[jboss-cvs] Picketlink SVN: r383 - in idm/trunk: picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 24 13:34:26 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-08-24 13:34:25 -0400 (Tue, 24 Aug 2010)
New Revision: 383

Added:
   idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStoreFactory.java
   idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/SecurityActions.java
Modified:
   idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java
   idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
Log:
PLIDM-23: single factory to instantiate identity stores

Modified: idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java
===================================================================
--- idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java	2010-08-23 21:20:08 UTC (rev 382)
+++ idm/trunk/picketlink-idm-ldap/src/main/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreImpl.java	2010-08-24 17:34:25 UTC (rev 383)
@@ -22,37 +22,8 @@
 
 package org.picketlink.idm.impl.store.ldap;
 
-import org.picketlink.idm.api.cfg.IdentityConfigurationRegistry;
-import org.picketlink.idm.common.exception.IdentityException;
-import org.picketlink.idm.impl.NotYetImplementedException;
-import org.picketlink.idm.impl.api.SimpleAttribute;
-import org.picketlink.idm.impl.helper.Tools;
-import org.picketlink.idm.impl.model.ldap.LDAPIdentityObjectImpl;
-import org.picketlink.idm.impl.model.ldap.LDAPIdentityObjectRelationshipImpl;
-import org.picketlink.idm.impl.store.FeaturesMetaDataImpl;
-import org.picketlink.idm.impl.types.SimpleIdentityObject;
-import org.picketlink.idm.spi.cache.IdentityStoreCacheProvider;
-import org.picketlink.idm.spi.configuration.IdentityStoreConfigurationContext;
-import org.picketlink.idm.spi.configuration.metadata.IdentityObjectAttributeMetaData;
-import org.picketlink.idm.spi.configuration.metadata.IdentityObjectTypeMetaData;
-import org.picketlink.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
-import org.picketlink.idm.spi.exception.OperationNotSupportedException;
-import org.picketlink.idm.spi.model.IdentityObject;
-import org.picketlink.idm.spi.model.IdentityObjectAttribute;
-import org.picketlink.idm.spi.model.IdentityObjectCredential;
-import org.picketlink.idm.spi.model.IdentityObjectRelationship;
-import org.picketlink.idm.spi.model.IdentityObjectRelationshipType;
-import org.picketlink.idm.spi.model.IdentityObjectType;
-import org.picketlink.idm.spi.search.IdentityObjectSearchCriteria;
-import org.picketlink.idm.spi.store.FeaturesMetaData;
-import org.picketlink.idm.spi.store.IdentityObjectSearchCriteriaType;
-import org.picketlink.idm.spi.store.IdentityStore;
-import org.picketlink.idm.spi.store.IdentityStoreInvocationContext;
-import org.picketlink.idm.spi.store.IdentityStoreSession;
-
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -89,15 +60,43 @@
 import javax.naming.ldap.LdapName;
 import javax.naming.ldap.SortControl;
 
+import org.picketlink.idm.common.exception.IdentityException;
+import org.picketlink.idm.impl.NotYetImplementedException;
+import org.picketlink.idm.impl.api.SimpleAttribute;
+import org.picketlink.idm.impl.helper.Tools;
+import org.picketlink.idm.impl.model.ldap.LDAPIdentityObjectImpl;
+import org.picketlink.idm.impl.model.ldap.LDAPIdentityObjectRelationshipImpl;
+import org.picketlink.idm.impl.store.FeaturesMetaDataImpl;
+import org.picketlink.idm.impl.types.SimpleIdentityObject;
+import org.picketlink.idm.spi.cache.IdentityStoreCacheProvider;
+import org.picketlink.idm.spi.configuration.IdentityStoreConfigurationContext;
+import org.picketlink.idm.spi.configuration.metadata.IdentityObjectAttributeMetaData;
+import org.picketlink.idm.spi.configuration.metadata.IdentityObjectTypeMetaData;
+import org.picketlink.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
+import org.picketlink.idm.spi.exception.OperationNotSupportedException;
+import org.picketlink.idm.spi.model.IdentityObject;
+import org.picketlink.idm.spi.model.IdentityObjectAttribute;
+import org.picketlink.idm.spi.model.IdentityObjectCredential;
+import org.picketlink.idm.spi.model.IdentityObjectRelationship;
+import org.picketlink.idm.spi.model.IdentityObjectRelationshipType;
+import org.picketlink.idm.spi.model.IdentityObjectType;
+import org.picketlink.idm.spi.search.IdentityObjectSearchCriteria;
+import org.picketlink.idm.spi.store.FeaturesMetaData;
+import org.picketlink.idm.spi.store.IdentityObjectSearchCriteriaType;
+import org.picketlink.idm.spi.store.IdentityStore;
+import org.picketlink.idm.spi.store.IdentityStoreInvocationContext;
+import org.picketlink.idm.spi.store.IdentityStoreSession;
+
 /**
  * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
  * @version : 0.1 $
  */
 public class LDAPIdentityStoreImpl implements IdentityStore
 {
+	private static final long serialVersionUID = -3823363689431954490L;
 
    //TODO: JNDI connection credentials encoding (pluggable?)
-
+	
    private static Logger log = Logger.getLogger(LDAPIdentityStoreImpl.class.getName());
 
    private final String id;
@@ -124,6 +123,7 @@
       this.id = id;
    }
 
+   @SuppressWarnings("rawtypes")
    public void bootstrap(IdentityStoreConfigurationContext configurationContext) throws IdentityException
    {
       if (configurationContext == null)

Added: idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStoreFactory.java
===================================================================
--- idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStoreFactory.java	                        (rev 0)
+++ idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/IdentityStoreFactory.java	2010-08-24 17:34:25 UTC (rev 383)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.store;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * PLIDM-23: Factory that returns the Identity Store implementations related to ldap, db etc
+ * @author Anil.Saldhana at redhat.com
+ * @since Aug 24, 2010
+ */
+public class IdentityStoreFactory
+{   
+   public enum IdentityStoreType
+   {
+      LDAP, DB, HIBERNATE;
+   } 
+   
+   /**
+    * A map of FQN of store implementations that are keyed in by the Identity Store Type
+    */
+   private static Map<IdentityStoreType, String> classMap = new HashMap<IdentityStoreType, String>();
+   
+   /**
+    * A map of concrete store implementations that are keyed in by the Identity Store Type
+    */
+   private static Map<IdentityStoreType, IdentityStore> instanceMap = new HashMap<IdentityStoreType, IdentityStore>();
+   
+   static
+   {
+      classMap.put( IdentityStoreType.LDAP, "org.picketlink.idm.impl.store.ldap.LDAPIdentityStoreImpl" );
+      classMap.put( IdentityStoreType.HIBERNATE, "org.picketlink.idm.impl.store.hibernate.HibernateIdentityStoreImpl" ); 
+   };
+   
+   /**
+    * Given a {@code IdentityStoreType}, return a concrete implementation of store
+    * @param type
+    * @param id
+    * @return
+    */
+   @SuppressWarnings({"rawtypes", "unchecked"})
+   public static IdentityStore getIdentityStore( IdentityStoreType type, String id )
+   {
+      IdentityStore store = instanceMap.get(type);
+      if( store == null )
+      {
+         ClassLoader tcl = SecurityActions.getContextClassLoader();
+         try
+         {
+            Class clazz = tcl.loadClass( classMap.get(type) );
+            Constructor ctr = clazz.getDeclaredConstructor( new Class[] { String.class } );
+            store = (IdentityStore) ctr.newInstance( new Object[] { id } );
+            instanceMap.put(type, store);
+         }
+         catch ( Exception e )
+         {
+            throw new RuntimeException( "Unable to get Identity Store:", e );
+         }
+      }
+      return store; 
+   }
+   
+   /**
+    * Static Method that replaces the fqn of store implementation for a particular identity type
+    * @param type
+    * @param fqn
+    */
+   public void setIdentityStoreClass( IdentityStoreType type, String fqn )
+   {
+      if( fqn == null )
+         throw new IllegalArgumentException( "fqn is null" );
+      classMap.put(type, fqn); 
+      instanceMap.remove( type ); //Remove the old type
+   }
+}
\ No newline at end of file

Added: idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/SecurityActions.java
===================================================================
--- idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/SecurityActions.java	                        (rev 0)
+++ idm/trunk/picketlink-idm-spi/src/main/java/org/picketlink/idm/spi/store/SecurityActions.java	2010-08-24 17:34:25 UTC (rev 383)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.store;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author Anil.Saldhana at redhat.com
+ * @since Aug 24, 2010
+ */
+public class SecurityActions
+{ 
+   /**
+    * Get the Thread Context ClassLoader
+    * @return
+    */
+   public static ClassLoader getContextClassLoader()
+   {
+      return AccessController.doPrivileged( new PrivilegedAction<ClassLoader>()
+      {
+
+         public ClassLoader run()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   } 
+}
\ No newline at end of file

Modified: idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java
===================================================================
--- idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java	2010-08-23 21:20:08 UTC (rev 382)
+++ idm/trunk/picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/ldap/LDAPIdentityStoreTestCase.java	2010-08-24 17:34:25 UTC (rev 383)
@@ -33,6 +33,8 @@
 import org.picketlink.idm.spi.configuration.metadata.IdentityConfigurationMetaData;
 import org.picketlink.idm.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
 import org.picketlink.idm.spi.store.IdentityStore;
+import org.picketlink.idm.spi.store.IdentityStoreFactory;
+import org.picketlink.idm.spi.store.IdentityStoreFactory.IdentityStoreType;
 import org.picketlink.idm.spi.store.IdentityStoreInvocationContext;
 import org.picketlink.idm.spi.store.IdentityStoreSession;
 
@@ -93,7 +95,7 @@
 
       //populate();
 
-      store = new LDAPIdentityStoreImpl("LDAP Identity Store");
+      store =  IdentityStoreFactory.getIdentityStore( IdentityStoreType.LDAP,  "LDAP Identity Store");
 
       store.bootstrap(context);
 



More information about the jboss-cvs-commits mailing list