Author: mposolda
Date: 2012-02-02 09:29:48 -0500 (Thu, 02 Feb 2012)
New Revision: 1365
Added:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/SystemPropertiesSubstitutionConverter.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SystemPropertiesSubstitutionAdapter.java
idm/trunk/picketlink-idm-core/src/test/resources/example-system-properties-config.xml
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/AttributeType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/CredentialsType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/ExternalConfigType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/GroupTypeMappingType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypeType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypesType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreMappingType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityTypeMappingsType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/OptionType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RealmType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RelationshipType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RepositoryType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/StoresType.java
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SupportedRelationshipTypesType.java
idm/trunk/picketlink-idm-core/src/test/java/org/picketlink/idm/impl/configuration/ConfigurationTestCase.java
Log:
JBEPP-1027 Support for system properties substitution in Picketlink IDM configuration
Added:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/SystemPropertiesSubstitutionConverter.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/SystemPropertiesSubstitutionConverter.java
(rev 0)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/SystemPropertiesSubstitutionConverter.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -0,0 +1,184 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2012, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.picketlink.idm.impl.configuration.jaxb2;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.logging.Logger;
+
+/**
+ * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
+ */
+public class SystemPropertiesSubstitutionConverter
+{
+ private static Logger log =
Logger.getLogger(SystemPropertiesSubstitutionConverter.class.getName());
+
+ /**
+ * Replaces variables of ${var:default} with System.getProperty(var, default). If no
variables are found, returns
+ * the same string, otherwise a copy of the string with variables substituted
+ *
+ * @param input
+ * @return A string with vars replaced, or the same string if no vars found
+ */
+ public static String substituteSystemProperty(String input)
+ {
+ String output = substituteVariable(input);
+
+ log.fine("Substituting value from configuration with System properties -
input=" + input + ", output=" + output);
+ return output;
+ }
+
+ /**
+ * Method is doing nothing but is needed by JAXB adapter.
+ *
+ * @param input
+ * @return input
+ */
+ public static String printValue(String input)
+ {
+ return input;
+ }
+
+
+
+ /****** PRIVATE METHODS **************/
+
+ // Methods for substitute system properties are forked from JGroups class
org.jgroups.utils.Util to avoid bugs
+ // and ensure same parsing behaviour, which is used by JGroups and by JBoss AS.
+
+
+ private static String substituteVariable(String val)
+ {
+ if(val == null)
+ return val;
+ String retval=val, prev;
+
+ while(retval.contains("${"))
+ { // handle multiple variables in val
+ prev=retval;
+ retval=_substituteVar(retval);
+ if(retval.equals(prev))
+ break;
+ }
+ return retval;
+ }
+
+ private static String _substituteVar(String val)
+ {
+ int start_index, end_index;
+ start_index=val.indexOf("${");
+ if(start_index == -1)
+ return val;
+ end_index=val.indexOf("}", start_index+2);
+ if(end_index == -1)
+ throw new IllegalArgumentException("missing \"}\" in " +
val);
+
+ String tmp=getProperty(val.substring(start_index +2, end_index));
+ if(tmp == null)
+ return val;
+ StringBuilder sb=new StringBuilder();
+ sb.append(val.substring(0, start_index));
+ sb.append(tmp);
+ sb.append(val.substring(end_index+1));
+ return sb.toString();
+ }
+
+ private static String getProperty(String s)
+ {
+ String var, default_val, retval=null;
+ int index=s.indexOf(":");
+ if(index >= 0)
+ {
+ var=s.substring(0, index);
+ default_val=s.substring(index+1);
+ if(default_val != null && default_val.length() > 0)
+ default_val=default_val.trim();
+ // retval=System.getProperty(var, default_val);
+ retval=_getProperty(var, default_val);
+ }
+ else
+ {
+ var=s;
+ // retval=System.getProperty(var);
+ retval=_getProperty(var, null);
+ }
+ return retval;
+ }
+
+ /**
+ * Parses a var which might be comma delimited, e.g. bla,foo:1000: if 'bla' is
set, return its value. Else,
+ * if 'foo' is set, return its value, else return "1000"
+ * @param var
+ * @param default_value
+ * @return
+ */
+ private static String _getProperty(String var, String default_value)
+ {
+ if(var == null)
+ return null;
+ List<String> list=parseCommaDelimitedStrings(var);
+ if(list == null || list.isEmpty())
+ {
+ list=new ArrayList<String>(1);
+ list.add(var);
+ }
+ String retval=null;
+ for(String prop: list)
+ {
+ try
+ {
+ retval=System.getProperty(prop);
+ if(retval != null)
+ return retval;
+ }
+ catch(Throwable e)
+ {
+ }
+ }
+ return default_value;
+ }
+
+ /** e.g. "bela,jeannette,michelle" --> List{"bela",
"jeannette", "michelle"} */
+ private static List<String> parseCommaDelimitedStrings(String l)
+ {
+ return parseStringList(l, ",");
+ }
+
+ private static List<String> parseStringList(String l, String separator)
+ {
+ List<String> tmp=new LinkedList<String>();
+ StringTokenizer tok=new StringTokenizer(l, separator);
+ String t;
+
+ while(tok.hasMoreTokens())
+ {
+ t=tok.nextToken();
+ tmp.add(t.trim());
+ }
+
+ return tmp;
+ }
+
+}
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/AttributeType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/AttributeType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/AttributeType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -67,14 +68,27 @@
public class AttributeType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String name;
+
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String mapping;
+
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String type;
+
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String isRequired;
+
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String isMultivalued;
+
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String isReadOnly;
+
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String isUnique;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/CredentialsType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/CredentialsType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/CredentialsType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,6 +43,7 @@
public class CredentialsType {
@XmlElement(name = "credential-type")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected List<String> credentialType;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/ExternalConfigType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/ExternalConfigType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/ExternalConfigType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -13,6 +13,7 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -39,8 +40,11 @@
public class ExternalConfigType {
@XmlValue
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String value;
+
@XmlAttribute
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String override;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/GroupTypeMappingType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/GroupTypeMappingType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/GroupTypeMappingType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,8 +43,12 @@
public class GroupTypeMappingType {
@XmlElement(name = "group-type-name", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String groupTypeName;
+
+
@XmlElement(name = "identity-object-type-name", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String identityObjectTypeName;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypeType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypeType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypeType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -90,7 +91,9 @@
public class IdentityObjectTypeType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String name;
+
@XmlElement(required = true)
protected IdentityObjectTypeType.Relationships relationships;
@XmlElement(required = true)
@@ -306,6 +309,7 @@
public static class Credentials {
@XmlElement(name = "credential-type")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected List<String> credentialType;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypesType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypesType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityObjectTypesType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,6 +43,7 @@
public class IdentityObjectTypesType {
@XmlElement(name = "identity-object-type")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected List<String> identityObjectType;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreMappingType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreMappingType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreMappingType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -44,7 +45,9 @@
public class IdentityStoreMappingType {
@XmlElement(name = "identity-store-id", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String identityStoreId;
+
@XmlElement(name = "identity-object-types", required = true)
protected IdentityObjectTypesType identityObjectTypes;
@XmlElement(required = true)
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityStoreType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -62,9 +63,13 @@
public class IdentityStoreType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String id;
+
@XmlElement(name = "class", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String clazz;
+
@XmlElement(name = "external-config", required = true)
protected ExternalConfigType externalConfig;
@XmlElement(name = "supported-relationship-types", required = true)
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityTypeMappingsType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityTypeMappingsType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/IdentityTypeMappingsType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -44,7 +45,9 @@
public class IdentityTypeMappingsType {
@XmlElement(name = "user-mapping", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String identityMapping;
+
@XmlElement(name = "group-type-mapping")
protected List<GroupTypeMappingType> groupTypeMapping;
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/OptionType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/OptionType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/OptionType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -44,7 +45,10 @@
public class OptionType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String name;
+
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected List<String> value;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RealmType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RealmType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RealmType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -46,9 +47,13 @@
public class RealmType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String id;
+
@XmlElement(name = "repository-id-ref", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String repositoryIdRef;
+
@XmlElement(name = "identity-type-mappings")
protected IdentityTypeMappingsType identityTypeMappings;
protected OptionsType options;
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RelationshipType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RelationshipType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RelationshipType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,8 +43,11 @@
public class RelationshipType {
@XmlElement(name = "relationship-type-ref", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String relationshipTypeRef;
+
@XmlElement(name = "identity-object-type-ref", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String identityObjectTypeRef;
/**
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RepositoryType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RepositoryType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/RepositoryType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -52,15 +53,24 @@
public class RepositoryType {
@XmlElement(required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String id;
+
@XmlElement(name = "class", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String clazz;
+
@XmlElement(name = "external-config")
protected ExternalConfigType externalConfig;
+
@XmlElement(name = "default-identity-store-id")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String defaultIdentityStoreId;
+
@XmlElement(name = "default-attribute-store-id")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String defaultAttributeStoreId;
+
@XmlElement(name = "identity-store-mappings")
protected IdentityStoreMappingsType identityStoreMappings;
protected OptionsType options;
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/StoresType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/StoresType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/StoresType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -12,6 +12,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,7 +43,9 @@
public class StoresType {
@XmlElement(name = "attribute-stores", required = true)
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected String attributeStores;
+
@XmlElement(name = "identity-stores", required = true)
protected IdentityStoresType identityStores;
Modified:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SupportedRelationshipTypesType.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SupportedRelationshipTypesType.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SupportedRelationshipTypesType.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -14,6 +14,7 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
@@ -42,6 +43,7 @@
public class SupportedRelationshipTypesType {
@XmlElement(name = "relationship-type")
+ @XmlJavaTypeAdapter(SystemPropertiesSubstitutionAdapter.class)
protected List<String> relationshipType;
/**
Added:
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SystemPropertiesSubstitutionAdapter.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SystemPropertiesSubstitutionAdapter.java
(rev 0)
+++
idm/trunk/picketlink-idm-core/src/main/java/org/picketlink/idm/impl/configuration/jaxb2/generated/SystemPropertiesSubstitutionAdapter.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -0,0 +1,26 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference
Implementation, vJAXB 2.1.10 in JDK 6
+// See <a
href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/...
+// Any modifications to this file will be lost upon recompilation of the source schema.
+// Generated on: 2012.02.01 at 07:21:12 odp. CET
+//
+
+
+package org.picketlink.idm.impl.configuration.jaxb2.generated;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+public class SystemPropertiesSubstitutionAdapter
+ extends XmlAdapter<String, String>
+{
+
+
+ public String unmarshal(String value) {
+ return
(org.picketlink.idm.impl.configuration.jaxb2.SystemPropertiesSubstitutionConverter.substituteSystemProperty(value));
+ }
+
+ public String marshal(String value) {
+ return
(org.picketlink.idm.impl.configuration.jaxb2.SystemPropertiesSubstitutionConverter.printValue(value));
+ }
+
+}
Modified:
idm/trunk/picketlink-idm-core/src/test/java/org/picketlink/idm/impl/configuration/ConfigurationTestCase.java
===================================================================
---
idm/trunk/picketlink-idm-core/src/test/java/org/picketlink/idm/impl/configuration/ConfigurationTestCase.java 2012-02-01
15:49:30 UTC (rev 1364)
+++
idm/trunk/picketlink-idm-core/src/test/java/org/picketlink/idm/impl/configuration/ConfigurationTestCase.java 2012-02-02
14:29:48 UTC (rev 1365)
@@ -25,8 +25,13 @@
import junit.framework.TestCase;
import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
import org.picketlink.idm.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
+import
org.picketlink.idm.impl.configuration.jaxb2.SystemPropertiesSubstitutionConverter;
import org.picketlink.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
/**
@@ -49,4 +54,48 @@
}
+
+ public void testSystemPropertiesSubstitution() throws Exception
+ {
+ // Init system properties for substitution
+ System.setProperty("identity.store.id", "HibernateStore");
+ System.setProperty("relationship.type1",
"JBOSS_IDENTITY_MEMBERSHIP");
+ System.setProperty("relationship.type2",
"JBOSS_IDENTITY_ROLLE");
+
+ System.setProperty("option2.value", "Value of option2");
+ System.setProperty("option3.value", "Value of option3");
+ System.setProperty("option5.value1", "Option5 value1");
+ System.setProperty("option5.value2", "Option5 value2");
+ System.setProperty("option6.value1", "Option6 value1");
+ System.setProperty("option7.value2", "Option7 value2");
+ System.setProperty("option8.value2", "Option8 value2");
+ System.setProperty("option8.value4", "Option8 value4");
+
+ // Parse config file
+ IdentityConfigurationMetaData config =
JAXB2IdentityConfiguration.createConfigurationMetaData(new
File("src/test/resources/example-system-properties-config.xml"));
+ assertNotNull(config);
+
+ // Assert that values from configuration were correctly substituted
+ assertEquals("HibernateStore",
config.getRepositories().get(0).getDefaultIdentityStoreId());
+ assertEquals("HibernateStore",
config.getRepositories().get(0).getDefaultAttributeStoreId());
+ assertEquals("true",
config.getRepositories().get(0).getOption("allowNotDefinedAttributes").get(0));
+ assertEquals("HibernateStore",
config.getIdentityStores().get(0).getId());
+
assertTrue(config.getIdentityStores().get(0).getSupportedRelationshipTypes().contains("JBOSS_IDENTITY_MEMBERSHIP"));
+
assertTrue(config.getIdentityStores().get(0).getSupportedRelationshipTypes().contains("JBOSS_IDENTITY_ROLLE"));
+
+ // Assert that all options were correctly substituted
+ Map<String, List<String>> options =
config.getIdentityStores().get(0).getOptions();
+ assertEquals("option1Value", options.get("option1").get(0));
+ assertEquals("Value of option2",
options.get("option2").get(0));
+ assertEquals("Value of option3",
options.get("option3").get(0));
+ assertEquals("defaultValue", options.get("option4").get(0));
+ assertEquals("Option5 value1", options.get("option5").get(0));
+ assertEquals("Option6 value1", options.get("option6").get(0));
+ assertEquals("Option7 value2", options.get("option7").get(0));
+ assertEquals("something1 Option8 value2 something2 defaultValue something3
Option8 value4 something4", options.get("option8").get(0));
+ assertEquals("something1 ${} something2",
options.get("option9").get(0));
+ assertEquals("${option10.value1}",
options.get("option10").get(0));
+ assertEquals("value2", options.get("option10").get(1));
+ assertEquals("defaultValue3", options.get("option10").get(2));
+ }
}
Added:
idm/trunk/picketlink-idm-core/src/test/resources/example-system-properties-config.xml
===================================================================
--- idm/trunk/picketlink-idm-core/src/test/resources/example-system-properties-config.xml
(rev 0)
+++
idm/trunk/picketlink-idm-core/src/test/resources/example-system-properties-config.xml 2012-02-02
14:29:48 UTC (rev 1365)
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jboss-identity xmlns="urn:picketlink:idm:config:v1_0_0_ga"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:picketlink:idm:config:v1_0_0_ga
identity-config.xsd">
+ <realms>
+ <realm>
+ <id>realm://Example/DB</id>
+ <repository-id-ref>Example Repository</repository-id-ref>
+ <identity-type-mappings>
+ <user-mapping>IDENTITY</user-mapping>
+ </identity-type-mappings>
+ </realm>
+ </realms>
+ <repositories>
+ <repository>
+ <id>Example Repository</id>
+
<class>org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository</class>
+ <external-config/>
+
<default-identity-store-id>${identity.store.id}</default-identity-store-id>
+
<default-attribute-store-id>${identity.store.id}</default-attribute-store-id>
+ <options>
+ <option>
+ <name>allowNotDefinedAttributes</name>
+ <value>${alow.not.defined.attributes:true}</value>
+ </option>
+ </options>
+ </repository>
+ </repositories>
+ <stores>
+ <attribute-stores/>
+ <identity-stores>
+ <identity-store>
+ <id>${identity.store.id}</id>
+
<class>org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl</class>
+ <external-config/>
+ <supported-relationship-types>
+ <relationship-type>${relationship.type1}</relationship-type>
+ <relationship-type>${relationship.type2}</relationship-type>
+ </supported-relationship-types>
+ <supported-identity-object-types>
+ <identity-object-type>
+ <name>USER</name>
+ <relationships/>
+ <credentials>
+ <credential-type>PASSWORD</credential-type>
+ </credentials>
+ <attributes/>
+ <options/>
+ </identity-object-type>
+ </supported-identity-object-types>
+ <options>
+ <option>
+ <name>option1</name>
+ <value>option1Value</value>
+ </option>
+ <option>
+ <name>option2</name>
+ <value>${option2.value}</value>
+ </option>
+ <option>
+ <name>option3</name>
+ <value>${option3.value:defaultValue}</value>
+ </option>
+ <option>
+ <name>option4</name>
+ <value>${option4.value:defaultValue}</value>
+ </option>
+ <option>
+ <name>option5</name>
+ <value>${option5.value1,option5.value2}</value>
+ </option>
+ <option>
+ <name>option6</name>
+ <value>${option6.value1,option6.value2}</value>
+ </option>
+ <option>
+ <name>option7</name>
+
<value>${option7.value1,option7.value2:defaultValue}</value>
+ </option>
+ <option>
+ <name>option8</name>
+ <value>something1 ${option8.value1,option8.value2} something2
${option8.value3:defaultValue} something3 ${option8.value4:defaultValue}
something4</value>
+ </option>
+ <option>
+ <name>option9</name>
+ <value>something1 ${} something2</value>
+ </option>
+ <option>
+ <name>option10</name>
+ <value>${option10.value1}</value>
+ <value>value2</value>
+ <value>${option10.value3:defaultValue3}</value>
+ </option>
+ </options>
+ </identity-store>
+ </identity-stores>
+ </stores>
+</jboss-identity>
\ No newline at end of file