Author: bdaw
Date: 2008-10-18 17:35:12 -0400 (Sat, 18 Oct 2008)
New Revision: 105
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
Log:
very dummy impl of mixed LDAP/DB scenario. Just to pass initial tests.
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/ProfileManagerImpl.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -45,7 +45,7 @@
super(session);
}
- //TODO: fix to have similar signatures in API/SPI for String[]
+ //TODO: fix to have similar signatures in API/SPI for String[] and avoid unnesesary
iterations
public Set<String> getSupportedAttributeNames(IdentityType identityType) throws
IdentityException
{
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/AbstractIdentityStoreRepository.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -25,7 +25,10 @@
import org.jboss.identity.spi.repository.IdentityStoreRepository;
import org.jboss.identity.spi.store.IdentityStore;
import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.exception.IdentityException;
import java.util.Set;
import java.util.Map;
@@ -94,4 +97,22 @@
{
return attributeStoreMappings.get(identityObjectType.getName());
}
+
+ public boolean hasIdentityObject(IdentityStoreInvocationContext ctx, IdentityStore is,
IdentityObject io) throws IdentityException
+ {
+ try
+ {
+ if (is.findIdentityObject(ctx, io.getName(), io.getIdentityType()) != null)
+ {
+ return true;
+ }
+ }
+ catch (IdentityException e)
+ {
+ //store may throw exception if there is no identity so do nothing
+ //TODO: this behaviour sucks...
+
+ }
+ return false;
+ }
}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -0,0 +1,332 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, 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.jboss.identity.impl.repository;
+
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.spi.model.IdentityObjectType;
+import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
+import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.exception.OperationNotSupportedException;
+import org.jboss.identity.exception.IdentityException;
+import org.jboss.identity.impl.NotYetImplementedException;
+
+import java.util.Map;
+import java.util.Collection;
+import java.util.Set;
+import java.io.IOException;
+
+/**
+ * LADP + DB
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class FallbackIdentityStoreRepository extends AbstractIdentityStoreRepository
+{
+
+ private final IdentityStore defaultIdentityStore;
+
+ private final AttributeStore defaultAttributeStore;
+
+ public FallbackIdentityStoreRepository(IdentityStore identityStore, AttributeStore
attributeStore,
+ Map<String, IdentityStore>
identityStoreMappings, Map<String, AttributeStore> attributeStoreMappings)
+ {
+ super(identityStoreMappings, attributeStoreMappings);
+
+ this.defaultIdentityStore = identityStore;
+ this.defaultAttributeStore = attributeStore;
+ }
+
+ public void bootstrap() throws IOException
+ {
+
+ }
+
+ public String getId()
+ {
+ return null;
+ }
+
+ public FeaturesDescription getSupportedFeatures()
+ {
+ return null;
+ }
+
+ IdentityStore resolveIdentityStore(IdentityObject io)
+ {
+ return resolveIdentityStore(io.getIdentityType());
+ }
+
+ IdentityStore resolveIdentityStore(IdentityObjectType iot)
+ {
+ IdentityStore ids = getIdentityStore(iot);
+ if (ids == null)
+ {
+ ids = defaultIdentityStore;
+ }
+ return ids;
+ }
+
+ AttributeStore resolveAttributeStore(IdentityObjectType iot)
+ {
+ AttributeStore ads = getAttributeStore(iot);
+ if (ads == null)
+ {
+ ads = defaultIdentityStore;
+ }
+ return ads;
+ }
+
+ public IdentityObject createIdentityObject(IdentityStoreInvocationContext
invocationCtx, String name, IdentityObjectType identityObjectType) throws
IdentityException
+ {
+ return resolveIdentityStore(identityObjectType).createIdentityObject(invocationCtx,
name, identityObjectType);
+ }
+
+ public void removeIdentityObject(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity) throws IdentityException
+ {
+ resolveIdentityStore(identity).removeIdentityObject(invocationCtx, identity);
+ }
+
+ public int getIdentityObjectsCount(IdentityStoreInvocationContext invocationCtx,
IdentityObjectType identityType) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).getIdentityObjectsCount(invocationCtx,
identityType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext
invocationContext, String name, IdentityObjectType identityObjectType) throws
IdentityException
+ {
+ return
resolveIdentityStore(identityObjectType).findIdentityObject(invocationContext, name,
identityObjectType);
+ }
+
+ public IdentityObject findIdentityObject(IdentityStoreInvocationContext
invocationContext, Object id) throws IdentityException
+ {
+
+ for (IdentityStore identityStore : getIdentityStoreMappings().values())
+ {
+ IdentityObject io = identityStore.findIdentityObject(invocationContext, id);
+ if (io != null)
+ {
+ return io;
+ }
+ }
+
+ return defaultIdentityStore.findIdentityObject(invocationContext, id);
+ }
+
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType
identityType, String nameFilter, int offset, int limit, boolean orderByName, boolean
ascending) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).findIdentityObject(invocationCtx,
identityType, nameFilter, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType
identityType, Map<String, String[]> attributes, int offset, int limit, boolean
orderByName, boolean ascending) throws IdentityException
+ {
+ return resolveIdentityStore(identityType).findIdentityObject(invocationCtx,
identityType, attributes, offset, limit, orderByName, ascending);
+ }
+
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
+ {
+ //TODO:!!!!!!
+ //return defaultIdentityStore.findIdentityObject(invocationCxt, identity,
relationshipType, parent, offset, limit, orderByName, ascending);
+ throw new NotYetImplementedException();
+ }
+
+ public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext
invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType, String relationshipName, boolean
createNames) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ return fromStore.createRelationship(invocationCxt, fromIdentity, toIdentity,
relationshipType, relationshipName, createNames);
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(),
fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(),
toIdentity.getIdentityType());
+ }
+
+ return defaultIdentityStore.createRelationship(invocationCxt, fromIdentity,
toIdentity, relationshipType, relationshipName, createNames);
+ }
+
+ public void removeRelationship(IdentityStoreInvocationContext invocationCxt,
IdentityObject fromIdentity, IdentityObject toIdentity, IdentityObjectRelationshipType
relationshipType, String relationshipName) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ fromStore.removeRelationship(invocationCxt, fromIdentity, toIdentity,
relationshipType, relationshipName);
+ return;
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(),
fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(),
toIdentity.getIdentityType());
+ }
+
+ defaultIdentityStore.removeRelationship(invocationCxt, fromIdentity, toIdentity,
relationshipType, relationshipName);
+ }
+
+ public void removeRelationships(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity1, IdentityObject identity2, boolean named) throws
IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(identity1);
+ IdentityStore toStore = resolveIdentityStore(identity2);
+
+ if (fromStore == toStore)
+ {
+ fromStore.removeRelationships(invocationCtx, identity1, identity2, named);
+ return;
+ }
+
+ if (!hasIdentityObject(invocationCtx, defaultIdentityStore, identity1))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCtx, identity1.getName(),
identity1.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCtx, defaultIdentityStore, identity2))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCtx, identity2.getName(),
identity2.getIdentityType());
+ }
+
+ defaultIdentityStore.removeRelationships(invocationCtx, identity1, identity2,
named);
+ }
+
+ public Set<IdentityObjectRelationship>
resolveRelationships(IdentityStoreInvocationContext invocationCxt, IdentityObject
fromIdentity, IdentityObject toIdentity) throws IdentityException
+ {
+ IdentityStore fromStore = resolveIdentityStore(fromIdentity);
+ IdentityStore toStore = resolveIdentityStore(toIdentity);
+
+ if (fromStore == toStore)
+ {
+ return fromStore.resolveRelationships(invocationCxt, fromIdentity, toIdentity);
+
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, fromIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, fromIdentity.getName(),
fromIdentity.getIdentityType());
+ }
+
+ if (!hasIdentityObject(invocationCxt, defaultIdentityStore, toIdentity))
+ {
+ defaultIdentityStore.createIdentityObject(invocationCxt, toIdentity.getName(),
toIdentity.getIdentityType());
+ }
+
+ return defaultIdentityStore.resolveRelationships(invocationCxt, fromIdentity,
toIdentity);
+ }
+
+ public String createRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.createRelationshipName(ctx, name);
+ }
+
+ public String removeRelationshipName(IdentityStoreInvocationContext ctx, String name)
throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.removeRelationshipName(ctx, name);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx, int
offset, int limit, boolean orderByName, boolean ascending) throws IdentityException,
OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.getRelationshipNames(ctx, offset, limit, orderByName,
ascending);
+ }
+
+ public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
IdentityObject identity, int offset, int limit, boolean orderByName, boolean ascending)
throws IdentityException, OperationNotSupportedException
+ {
+ //TODO: For now just assume that named relationships are in default one
+ return defaultIdentityStore.getRelationshipNames(ctx, identity, offset, limit,
orderByName, ascending);
+ }
+
+ public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx,
IdentityObjectType type) throws IdentityException
+ {
+ return resolveIdentityStore(type).hasPasswordAttribute(ctx, type);
+ }
+
+ public boolean validatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
+ {
+ return resolveIdentityStore(identityObject).validatePassword(ctx, identityObject,
password);
+ }
+
+ public void updatePassword(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, String password) throws IdentityException
+ {
+ resolveIdentityStore(identityObject).updatePassword(ctx, identityObject,
password);
+ }
+
+
+ public <T extends IdentityObjectType> Set<String>
getSupportedAttributeNames(IdentityStoreInvocationContext invocationContext, T
identityType) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from
defaultAttributeStore. For now just use the default one.
+
+ return defaultAttributeStore.getSupportedAttributeNames(invocationContext,
identityType);
+ //return
resolveIdentityStore(identityType).getSupportedAttributeNames(invocationContext,
identityType);
+ }
+
+ public Map<String, Set<String>>
getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity)
throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from
defaultAttributeStore. For now just use the default one.
+
+ return defaultAttributeStore.getAttributes(invocationContext, identity);
+ //return resolveIdentityStore(identity).getAttributes(invocationContext,
identity);
+ }
+
+ public void updateAttributes(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity, Map<String, Set<String>> attributes) throws
IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from
defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.updateAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).updateAttributes(invocationCtx, identity,
attributes);
+ }
+
+ public void addAttributes(IdentityStoreInvocationContext invocationCtx, IdentityObject
identity, Map<String, Set<String>> attributes) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from
defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.addAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).addAttributes(invocationCtx, identity,
attributes);
+ }
+
+ public void removeAttributes(IdentityStoreInvocationContext invocationCtx,
IdentityObject identity, Set<String> attributes) throws IdentityException
+ {
+ //TODO: for profile stored in two stores this need to be merged with results from
defaultAttributeStore. For now just use the default one.
+
+ defaultAttributeStore.removeAttributes(invocationCtx, identity, attributes);
+ //resolveIdentityStore(identity).removeAttributes(invocationCtx, identity,
attributes);
+ }
+
+
+}
\ No newline at end of file
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreInvocationContext.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -29,12 +29,9 @@
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class HibernateIdentityStoreInvocationContext implements
IdentityStoreInvocationContext
+public interface HibernateIdentityStoreInvocationContext extends
IdentityStoreInvocationContext
{
- public HibernateEntityManager getHibernateEntityManager()
- {
- return null;
- }
+ public HibernateEntityManager getHibernateEntityManager();
}
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/HibernateTestSupport.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -46,6 +46,16 @@
private Connection connection;
+ private final String databaseName;
+
+ private final String persistenceUnit;
+
+ public HibernateTestSupport(String databaseName, String persistenceUnit)
+ {
+ this.databaseName = databaseName;
+ this.persistenceUnit = persistenceUnit;
+ }
+
public HibernateEntityManager getHibernateEntityManager()
{
return em;
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -26,17 +26,38 @@
import org.jboss.identity.impl.HibernateTestSupport;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreImpl;
import org.jboss.identity.impl.store.hibernate.HibernateIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityObjectTypeConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityObjectTypeConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityStoreConfiguration;
+import org.jboss.identity.impl.store.ldap.SimpleLDAPIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStoreInvocationContext;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStoreConfiguration;
+import org.jboss.identity.impl.store.ldap.LDAPIdentityStore;
+import org.jboss.identity.impl.store.IdentityTypeEnum;
import org.jboss.identity.impl.repository.WrapperIdentityStoreRepository;
+import org.jboss.identity.impl.repository.FallbackIdentityStoreRepository;
import org.jboss.identity.api.IdentitySessionFactory;
import org.jboss.identity.api.IdentitySession;
import org.jboss.identity.spi.repository.IdentityStoreRepository;
import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.AttributeStore;
+import org.jboss.identity.opends.OpenDSService;
import org.hibernate.ejb.HibernateEntityManager;
+import org.opends.server.tools.LDAPModify;
+import javax.naming.directory.DirContext;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.Binding;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
+import java.util.Hashtable;
+import java.io.File;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -44,67 +65,231 @@
*/
public class APITestCase extends TestCase implements APITestContext
{
- HibernateTestSupport hibernateSupport = new HibernateTestSupport();
+ //TODO: Code below is hardly readable mess... just made it quickly for prototyping.
Testing bits will be cleanly initialized
+ //TODO: once I make XML configuration for all services
+
+ HibernateTestSupport hibernateSupport = new
HibernateTestSupport("unit-testing-jpa", "jboss-identity-model");
+
+ LDAPIdentityStoreInvocationContext ctx;
+
OrganizationTest orgTest;
IdentitySessionFactory identitySessionFactory;
+ public static final String LDAP_HOST = "localhost";
+
+ public static final String LDAP_PORT = "10389";
+
+ public static final String LDAP_PROVIDER_URL = "ldap://" + LDAP_HOST +
":" + LDAP_PORT;
+
+ public static final String LDAP_PRINCIPAL = "cn=Directory Manager";
+
+ public static final String LDAP_CREDENTIALS = "password";
+
+ static Hashtable<String,String> env = new Hashtable<String,String>();
+
+ static
+ {
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
+ env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
+ env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);
+ }
+
+ OpenDSService openDSService = new
OpenDSService("target/test-classes/opends");
+
protected void setUp() throws Exception
{
super.setUp();
hibernateSupport.start();
orgTest = new OrganizationTest(this);
+ openDSService.start();
}
protected void tearDown() throws Exception
{
hibernateSupport.stop();
+
+ cleanUp(new InitialLdapContext(env, null));
+
+ openDSService.stop();
}
- public void testOrganization() throws Exception
+ public void testDBOrganization() throws Exception
{
- prepareRealm(OrganizationTest.RED_HAT_REALM, new String[]{"IDENTITY",
"ORGANIZATION", "ORGANIZATION_UNIT", "DIVISION",
"DEPARTMENT", "PROJECT", "PEOPLE"});
+ IdentityStore store = new HibernateIdentityStoreImpl();
+ IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store,
store, null, null);
+ final IdentityStoreInvocationContext invocationContext = new
HibernateIdentityStoreInvocationContext()
+ {
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+ prepareRealm(repository, invocationContext, OrganizationTest.RED_HAT_REALM,
+ new String[]{"IDENTITY", "ORGANIZATION",
"ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT",
"PROJECT", "PEOPLE"});
orgTest.testRedHatOrganization();
}
- public void testSamplePortal() throws Exception
+ public void testDBSamplePortal() throws Exception
{
- prepareRealm(OrganizationTest.PORTAL_REALM, new String[]{"IDENTITY",
"SYSTEM", "ADMINISTRATION", "COMMUNITY",
"ORGANIZATION", "ORGANIZATION_UNIT", "OFFICE",
"DIVISION", "DEPARTMENT", "SECURITY", "PEOPLE"});
+ IdentityStore store = new HibernateIdentityStoreImpl();
+ IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store,
store, null, null);
+ final IdentityStoreInvocationContext invocationContext = new
HibernateIdentityStoreInvocationContext()
+ {
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+ prepareRealm(repository, invocationContext, OrganizationTest.PORTAL_REALM,
+ new String[]{"IDENTITY", "SYSTEM",
"ADMINISTRATION", "COMMUNITY", "ORGANIZATION",
"ORGANIZATION_UNIT",
+ "OFFICE", "DIVISION", "DEPARTMENT",
"SECURITY", "PEOPLE"});
orgTest.testSamplePortal();
}
- private void prepareRealm(String realmName, String[] objectTypes) throws Exception
+ public void testLDAPMixedOrganization() throws Exception
{
+ populateClean();
- Set<SessionWrapper> sessionWrappers = new HashSet<SessionWrapper>();
- sessionWrappers.add(new
EntityManagerWrapper(hibernateSupport.getHibernateEntityManager()));
+ IdentityStore hibernateStore = new HibernateIdentityStoreImpl();
- hibernateSupport.populateObjectTypes(objectTypes);
- hibernateSupport.populateRelationshipTypes(new
String[]{"JBOSS_IDENTITY_MEMBERSHIP", "JBOSS_IDENTITY_ROLE"});
+ final LDAPIdentityStoreConfiguration ldapConfig =
createLDAPConfig("IDENTITY", null, null);
- HibernateIdentityStoreImpl store = new HibernateIdentityStoreImpl();
+
- ;
+ IdentityStore ldapStore = new LDAPIdentityStore("LDAPStore");
- IdentityStoreRepository repository = new WrapperIdentityStoreRepository(store,
store, null, null);
+ Map<String, IdentityStore> isMap = new HashMap<String,
IdentityStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("PROJECT",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
- IdentityObjectTypeMapper iotMapper = new
DirectIdentityObjectTypeMapperImpl("IDENTITY");
+ Map<String, AttributeStore> asMap = new HashMap<String,
AttributeStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("PROJECT",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
- final HibernateIdentityStoreInvocationContext hibernateInvocationContext = new
HibernateIdentityStoreInvocationContext()
+ IdentityStoreRepository repository = new
FallbackIdentityStoreRepository(hibernateStore, hibernateStore, isMap, asMap);
+
+ final IdentityStoreInvocationContext invocationContext = new
TestInvocationContext()
{
+ public LdapContext getLdapContext() throws Exception
+ {
+
+
+ return new InitialLdapContext(env, null);
+ }
+
+ public LDAPIdentityStoreConfiguration getConfiguration()
+ {
+ return ldapConfig;
+ }
+
public HibernateEntityManager getHibernateEntityManager()
{
return hibernateSupport.getHibernateEntityManager();
}
};
+ prepareRealm(repository, invocationContext, OrganizationTest.RED_HAT_REALM,
+ new String[]{"IDENTITY", "ORGANIZATION",
"ORGANIZATION_UNIT", "DIVISION", "DEPARTMENT",
"PROJECT", "PEOPLE"});
+ orgTest.testRedHatOrganization();
+ }
+
+ public void testLDAPMixedSamplePortal() throws Exception
+ {
+ populateClean();
+
+ IdentityStore hibernateStore = new HibernateIdentityStoreImpl();
+
+ final LDAPIdentityStoreConfiguration ldapConfig =
createLDAPConfig("IDENTITY", null, null);
+
+ IdentityStore ldapStore = new LDAPIdentityStore("LDAPStore");
+
+ Map<String, IdentityStore> isMap = new HashMap<String,
IdentityStore>();
+ isMap.put("IDENTITY",ldapStore);
+ isMap.put("SYSTEM",hibernateStore);
+ isMap.put("ADMINISTRATION",hibernateStore);
+ isMap.put("COMMUNITY",hibernateStore);
+ isMap.put("ORGANIZATION",hibernateStore);
+ isMap.put("ORGANIZATION_UNIT",hibernateStore);
+ isMap.put("OFFICE",hibernateStore);
+ isMap.put("DIVISION",hibernateStore);
+ isMap.put("DEPARTMENT",hibernateStore);
+ isMap.put("SECURITY",hibernateStore);
+ isMap.put("PEOPLE",hibernateStore);
+
+ Map<String, AttributeStore> asMap = new HashMap<String,
AttributeStore>();
+ asMap.put("IDENTITY",ldapStore);
+ asMap.put("SYSTEM",hibernateStore);
+ asMap.put("ADMINISTRATION",hibernateStore);
+ asMap.put("COMMUNITY",hibernateStore);
+ asMap.put("ORGANIZATION",hibernateStore);
+ asMap.put("ORGANIZATION_UNIT",hibernateStore);
+ asMap.put("OFFICE",hibernateStore);
+ asMap.put("DIVISION",hibernateStore);
+ asMap.put("DEPARTMENT",hibernateStore);
+ asMap.put("SECURITY",hibernateStore);
+ asMap.put("PEOPLE",hibernateStore);
+
+ IdentityStoreRepository repository = new
FallbackIdentityStoreRepository(hibernateStore, hibernateStore, isMap, asMap);
+
+ final IdentityStoreInvocationContext invocationContext = new
TestInvocationContext()
+ {
+ public LdapContext getLdapContext() throws Exception
+ {
+ return new InitialLdapContext(env, null);
+ }
+
+ public LDAPIdentityStoreConfiguration getConfiguration()
+ {
+ return ldapConfig;
+ }
+
+ public HibernateEntityManager getHibernateEntityManager()
+ {
+ return hibernateSupport.getHibernateEntityManager();
+ }
+ };
+
+ prepareRealm(repository, invocationContext, OrganizationTest.PORTAL_REALM,
+ new String[]{"IDENTITY", "SYSTEM",
"ADMINISTRATION", "COMMUNITY", "ORGANIZATION",
"ORGANIZATION_UNIT",
+ "OFFICE", "DIVISION", "DEPARTMENT",
"SECURITY", "PEOPLE"});
+ orgTest.testSamplePortal();
+ }
+
+ // Helper
+
+ private void prepareRealm(IdentityStoreRepository repository, final
IdentityStoreInvocationContext invocationContext, String realmName, String[] objectTypes)
throws Exception
+ {
+
+ Set<SessionWrapper> sessionWrappers = new HashSet<SessionWrapper>();
+ sessionWrappers.add(new
EntityManagerWrapper(hibernateSupport.getHibernateEntityManager()));
+
+ hibernateSupport.populateObjectTypes(objectTypes);
+ hibernateSupport.populateRelationshipTypes(new
String[]{"JBOSS_IDENTITY_MEMBERSHIP", "JBOSS_IDENTITY_ROLE"});
+
+ IdentityObjectTypeMapper iotMapper = new
DirectIdentityObjectTypeMapperImpl("IDENTITY");
+
+
+
IdentityStoreInvocationContextResolver contextResolver = new
IdentityStoreInvocationContextResolver()
{
public IdentityStoreInvocationContext resolveInvocationContext()
{
- return hibernateInvocationContext;
+ return invocationContext;
}
};
@@ -127,6 +312,149 @@
return identitySessionFactory;
}
+ public void populate() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-opends.ldif");
+ }
+ public void populateClean() throws Exception
+ {
+ populateLDIF("target/test-classes/ldap/initial-empty-opends.ldif");
+ }
+
+ public void populateLDIF(String ldifRelativePath) throws Exception
+ {
+ File ldif = new File(ldifRelativePath);
+
+ System.out.println("LDIF: " + ldif.getAbsolutePath());
+
+ String[] cmd = new String[] {"-h", LDAP_HOST,
+ "-p", LDAP_PORT,
+ "-D", LDAP_PRINCIPAL,
+ "-w", LDAP_CREDENTIALS,
+ "-a", "-f", ldif.getPath()};
+
+ System.out.println("Populate success: " + (LDAPModify.mainModify(cmd,
false, System.out, System.err) == 0));
+
+ }
+
+ protected void cleanUp(DirContext ldapCtx) throws Exception
+ {
+ try
+ {
+ String dn = "dc=portal,dc=example,dc=com";
+
+ System.out.println("Removing: " + dn);
+
+ removeContext(ldapCtx, dn);
+ }
+ catch (Exception e)
+ {
+ //
+ }
+ }
+
+ //subsequent remove of javax.naming.Context
+ protected void removeContext(Context mainCtx, String name) throws Exception
+ {
+ Context deleteCtx = (Context)mainCtx.lookup(name);
+ NamingEnumeration subDirs = mainCtx.listBindings(name);
+
+ while (subDirs.hasMoreElements())
+ {
+ Binding binding = (Binding)subDirs.nextElement();
+ String subName = binding.getName();
+
+ removeContext(deleteCtx, subName);
+ }
+
+ mainCtx.unbind(name);
+ }
+
+ private SimpleLDAPIdentityStoreConfiguration createLDAPConfig(String peopleTypeName,
String rolesTypeName, String groupsTypeName)
+ {
+
+ Map<String, LDAPIdentityObjectTypeConfiguration> typesMap = new
HashMap<String, LDAPIdentityObjectTypeConfiguration>();
+
+ //People
+ SimpleLDAPIdentityObjectTypeConfiguration tc = new
SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {});
+ tc.setAllowEmptyMemberships(true);
+ Map<String, String> attrs = new HashMap<String, String>();
+ attrs.put("phone", "telephoneNumber");
+ attrs.put("description", "description");
+ attrs.put("carLicense", "carLicense");
+ tc.setAttributeNames(attrs);
+ Map<String, String[]> newAttrs = new HashMap<String, String[]>();
+ newAttrs.put("objectClass", new String[]{"top",
"inetOrgPerson"});
+ newAttrs.put("sn", new String[]{" "});
+ newAttrs.put("cn", new String[]{" "});
+
+ tc.setCreateEntryAttributeValues(newAttrs);
+ tc.setCtxDNs(new String[]
{"ou=People,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("uid");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName(null);
+ typesMap.put(peopleTypeName, tc);
+
+
+ if (rolesTypeName != null)
+ {
+ // ROLE
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName()});
+ tc.setAllowEmptyMemberships(true);
+ attrs = new HashMap<String, String>();
+ //attrs.put();
+ tc.setAttributeNames(attrs);
+ newAttrs = new HashMap<String, String[]>();
+ newAttrs.put("objectClass", new String[]{"top",
"groupOfNames"});
+ tc.setCreateEntryAttributeValues(newAttrs);
+ tc.setCtxDNs(new String[]
{"ou=Roles,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("cn");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName("member");
+ typesMap.put(rolesTypeName, tc);
+ }
+
+ if (groupsTypeName != null)
+ {
+ // GROUP
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc.setAllowCreateEntry(true);
+ tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName(),
IdentityTypeEnum.ROLE.getName(), IdentityTypeEnum.GROUP.getName()});
+ tc.setAllowEmptyMemberships(true);
+ attrs = new HashMap<String, String>();
+ //attrs.put();
+ tc.setAttributeNames(attrs);
+ newAttrs = new HashMap<String, String[]>();
+ newAttrs.put("objectClass", new String[]{"top",
"groupOfNames"});
+
+ tc.setCreateEntryAttributeValues(newAttrs);
+ tc.setCtxDNs(new String[]
{"ou=Groups,o=test,dc=portal,dc=example,dc=com"});
+ tc.setEntrySearchFilter(null);
+ tc.setIdAttributeName("cn");
+ tc.setMembershipAttributeDN(true);
+ tc.setMembershipAttributeName("member");
+ typesMap.put(groupsTypeName, tc);
+ }
+
+ return new SimpleLDAPIdentityStoreConfiguration(
+ LDAP_PROVIDER_URL,
+ LDAP_PRINCIPAL,
+ LDAP_CREDENTIALS,
+ 10000,
+ typesMap);
+ }
+
+ private interface TestInvocationContext extends
HibernateIdentityStoreInvocationContext, LDAPIdentityStoreInvocationContext
+ {
+
+ }
+
}
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/hibernate/HibernateTestBase.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -42,7 +42,7 @@
{
private static Logger logger =
Logger.getLogger(HibernateModelTestCase.class.getName());
- private HibernateTestSupport hibernateSupport = new HibernateTestSupport();
+ private HibernateTestSupport hibernateSupport = new
HibernateTestSupport("unit-testing-jpa", "jboss-identity-model");
protected HibernateEntityManager em;
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-10-17
20:52:50 UTC (rev 104)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-10-18
21:35:12 UTC (rev 105)
@@ -226,7 +226,7 @@
// ROLE
- tc = new SimpleLDAPIdentityObjectTypeConfiguration();
+ tc = new SimpleLDAPIdentityObjectTypeConfiguration();
tc.setAllowCreateEntry(true);
tc.setAllowedMembershipTypes(new String[] {IdentityTypeEnum.USER.getName()});
tc.setAllowEmptyMemberships(true);
@@ -296,197 +296,197 @@
// Tests
- // Just test if OpenDS is running and was populated...
-// public void testSimple() throws Exception
-// {
-// populate();
-//
-// Hashtable<String,String> env = new Hashtable<String,String>();
-// env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
-// env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
-// env.put(Context.SECURITY_AUTHENTICATION, "simple");
-// env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
-// env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);
-//
-// LdapContext ldapCtx = null;
-// try
-// {
-// ldapCtx = new InitialLdapContext(env, null);
-//
-//// Do something ...
-// System.out.println("Attributes: " +
ldapCtx.getAttributes("o=test,dc=portal,dc=example,dc=com"));
-//
-// }
-// catch (NamingException e)
-// {
-// e.printStackTrace();
-// }
-// finally
-// {
-// try
-// {
-// if (ldapCtx != null)
-// {
-// ldapCtx.close();
-// }
-// }
-// catch (NamingException e)
-// {
-// e.printStackTrace();
-// }
-// }
-// }
-//
-// public void testIdentityObjectCount() throws Exception
-// {
-// populate();
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-// assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
-// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-// }
-//
-// public void testFindCreateRemove() throws Exception
-// {
-// populate();
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
-// assertEquals("admin", io.getName());
-// assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getId().toString());
-//
-// //
-//
-// store.removeIdentityObject(ctx, io);
-//
-// assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
-//
-// assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
-//
-// //
-//
-// assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-//
-// store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
-//
-// assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
-//
-// //
-//
-// io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
-// assertEquals("newGroupA", io.getName());
-//
-// }
-//
-// public void testAttributes() throws Exception{
-//
-// populate();
-//
-// IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
-// IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
-//
-// //
-//
-// Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
-// HashSet<String> vals = new HashSet<String>();
-// vals.add("val1");
-// vals.add("val2");
-// vals.add("val3");
-//
-// attrs.put("phone", vals);
-//
-// vals = new HashSet<String>();
-// vals.add("val1");
-// vals.add("val2");
-// vals.add("val3");
-// vals.add("val4");
-// attrs.put("description", vals);
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// Map<String, Set<String>> persistedAttrs = store.getAttributes(ctx,
user1);
-//
-// assertEquals(2, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("phone"));
-// assertEquals(3, persistedAttrs.get("phone").size());
-//
-// assertTrue(persistedAttrs.containsKey("description"));
-// assertEquals(4, persistedAttrs.get("description").size());
-//
-// //
-//
-// attrs = new HashMap<String, Set<String>>();
-// vals = new HashSet<String>();
-// vals.add("val1");
-// attrs.put("carLicense", vals);
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("phone"));
-// assertEquals(3, persistedAttrs.get("phone").size());
-//
-// assertTrue(persistedAttrs.containsKey("description"));
-// assertEquals(4, persistedAttrs.get("description").size());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(1, persistedAttrs.get("carLicense").size());
-//
-// //
-//
-// vals = new HashSet<String>();
-// vals.add("val2");
-// attrs.put("carLicense", vals);
-//
-// store.addAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(2, persistedAttrs.get("carLicense").size());
-//
-// //
-//
-// store.updateAttributes(ctx, user1, attrs);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(3, persistedAttrs.keySet().size());
-//
-// assertTrue(persistedAttrs.containsKey("carLicense"));
-// assertEquals(1, persistedAttrs.get("carLicense").size());
-//
-// //
-//
-// Set<String> names = new HashSet<String>();
-// names.add("carLicense");
-// store.removeAttributes(ctx, user1, names);
-//
-// //
-//
-// persistedAttrs = store.getAttributes(ctx, user1);
-//
-// assertEquals(2, persistedAttrs.keySet().size());
-//
-// }
+// Just test if OpenDS is running and was populated...
+ public void testSimple() throws Exception
+ {
+ populate();
+ Hashtable<String,String> env = new Hashtable<String,String>();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
+ env.put(Context.PROVIDER_URL, LDAP_PROVIDER_URL);
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, LDAP_PRINCIPAL);
+ env.put(Context.SECURITY_CREDENTIALS, LDAP_CREDENTIALS);
+
+ LdapContext ldapCtx = null;
+ try
+ {
+ ldapCtx = new InitialLdapContext(env, null);
+
+// Do something ...
+ System.out.println("Attributes: " +
ldapCtx.getAttributes("o=test,dc=portal,dc=example,dc=com"));
+
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (ldapCtx != null)
+ {
+ ldapCtx.close();
+ }
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void testIdentityObjectCount() throws Exception
+ {
+ populate();
+
+ assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+ assertEquals(5, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.ROLE));
+ assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+ }
+
+ public void testFindCreateRemove() throws Exception
+ {
+ populate();
+
+ assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+
+ IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.USER);
+ assertEquals("admin", io.getName());
+ assertEquals("uid=admin,ou=People,o=test,dc=portal,dc=example,dc=com",
io.getId().toString());
+
+ //
+
+ store.removeIdentityObject(ctx, io);
+
+ assertEquals(6, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+
+ store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.USER);
+
+ assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.USER));
+
+ //
+
+ assertEquals(2, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+
+ store.createIdentityObject(ctx, "newGroupA", IdentityTypeEnum.GROUP);
+
+ assertEquals(3, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.GROUP));
+
+ //
+
+ io = store.findIdentityObject(ctx,
"cn=newGroupA,ou=Groups,o=test,dc=portal,dc=example,dc=com");
+ assertEquals("newGroupA", io.getName());
+
+ }
+
+ public void testAttributes() throws Exception{
+
+ populate();
+
+ IdentityObject user1 = store.createIdentityObject(ctx, "Adam",
IdentityTypeEnum.USER);
+ IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.USER);
+
+ //
+
+ Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
+ HashSet<String> vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+
+ attrs.put("phone", vals);
+
+ vals = new HashSet<String>();
+ vals.add("val1");
+ vals.add("val2");
+ vals.add("val3");
+ vals.add("val4");
+ attrs.put("description", vals);
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ Map<String, Set<String>> persistedAttrs = store.getAttributes(ctx,
user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("phone"));
+ assertEquals(3, persistedAttrs.get("phone").size());
+
+ assertTrue(persistedAttrs.containsKey("description"));
+ assertEquals(4, persistedAttrs.get("description").size());
+
+ //
+
+ attrs = new HashMap<String, Set<String>>();
+ vals = new HashSet<String>();
+ vals.add("val1");
+ attrs.put("carLicense", vals);
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("phone"));
+ assertEquals(3, persistedAttrs.get("phone").size());
+
+ assertTrue(persistedAttrs.containsKey("description"));
+ assertEquals(4, persistedAttrs.get("description").size());
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(1, persistedAttrs.get("carLicense").size());
+
+ //
+
+ vals = new HashSet<String>();
+ vals.add("val2");
+ attrs.put("carLicense", vals);
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(2, persistedAttrs.get("carLicense").size());
+
+ //
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(1, persistedAttrs.get("carLicense").size());
+
+ //
+
+ Set<String> names = new HashSet<String>();
+ names.add("carLicense");
+ store.removeAttributes(ctx, user1, names);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ }
+
public void testRelationships() throws Exception
{
populateClean();
@@ -495,20 +495,20 @@
}
-// public void testStorePersistence() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testStorePersistence();
-//
-// }
-//
-// public void testFindMethods() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testFindMethods();
-//
-// }
+ public void testStorePersistence() throws Exception
+ {
+ populateClean();
+ commonTest.testStorePersistence();
+
+ }
+
+ public void testFindMethods() throws Exception
+ {
+ populateClean();
+
+ commonTest.testFindMethods();
+
+ }
+
}