Author: bdaw
Date: 2008-12-04 04:52:41 -0500 (Thu, 04 Dec 2008)
New Revision: 125
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesMetaDataImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java
trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif
trunk/identity-impl/src/test/resources/ldap/initial-opends.ldif
trunk/identity-impl/src/test/resources/store-test-config.xml
Log:
reenable LDAP store test cases
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java 2008-12-02
18:51:34 UTC (rev 124)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java 2008-12-04
09:52:41 UTC (rev 125)
@@ -31,8 +31,10 @@
import
org.jboss.identity.impl.configuration.metadata.IdentityRepositoryConfigurationMetaDataImpl;
import
org.jboss.identity.impl.configuration.metadata.IdentityStoreConfigurationMetaDataImpl;
import org.jboss.identity.impl.configuration.metadata.IdentityStoreMappingMetaDataImpl;
+import org.jboss.identity.impl.configuration.metadata.RelationshipMetaDataImpl;
import org.jboss.identity.spi.configuration.metadata.IdentityStoreMappingMetaData;
import org.jboss.identity.spi.configuration.metadata.IdentityConfigurationMetaData;
+import org.jboss.identity.spi.configuration.metadata.RelationshipMetaData;
import org.jboss.identity.spi.exception.IdentityConfigurationException;
import org.jboss.identity.spi.attribute.AttributeMetaData;
import org.jboss.identity.spi.attribute.AttributeMetaDataImpl;
@@ -46,6 +48,7 @@
import org.jboss.identity.impl.configuration.jaxb2.generated.IdentityStoreMappingType;
import org.jboss.identity.impl.configuration.jaxb2.generated.IdentityObjectTypeType;
import org.jboss.identity.impl.configuration.jaxb2.generated.AttributeType;
+import org.jboss.identity.impl.configuration.jaxb2.generated.RelationshipType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -223,6 +226,9 @@
identityObjectTypeMD.setName(identityObjectTypeType.getName());
+
+ // Attributes
+
List<AttributeMetaData> attributes = new
LinkedList<AttributeMetaData>();
if (identityObjectTypeType.getAttributes() != null &&
@@ -260,6 +266,8 @@
identityObjectTypeMD.setAttributes(attributes);
+ // Credentials
+
List<String> credentials = new LinkedList<String>();
if (identityObjectTypeType.getCredentials() != null &&
@@ -273,6 +281,26 @@
identityObjectTypeMD.setCredentials(credentials);
+ // Relationships
+
+ List<RelationshipMetaData> relationships = new
LinkedList<RelationshipMetaData>();
+
+ if (identityObjectTypeType.getRelationships() != null &&
+ identityObjectTypeType.getRelationships().getRelationship() != null)
+ {
+ for (RelationshipType relationshipType :
identityObjectTypeType.getRelationships().getRelationship())
+ {
+ RelationshipMetaDataImpl relMD = new RelationshipMetaDataImpl();
+
relMD.setIdentityObjectTypeRef(relationshipType.getIdentityObjectTypeRef());
+
relMD.setRelationshipTypeRef(relationshipType.getRelationshipTypeRef());
+ relationships.add(relMD);
+ }
+ }
+
+ identityObjectTypeMD.setRelationships(relationships);
+
+ // Options
+
Map<String, List<String>> options = new HashMap<String,
List<String>>();
if (identityObjectTypeType.getOptions() != null &&
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesMetaDataImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesMetaDataImpl.java 2008-12-02
18:51:34 UTC (rev 124)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FeaturesMetaDataImpl.java 2008-12-04
09:52:41 UTC (rev 125)
@@ -52,7 +52,8 @@
private final Map<String, Set<String>> supportedCredentials;
- private Map<String, Map<String, Set<String>>>
supportedRelationshipMappings = new HashMap<String, Map<String,
Set<String>>>();
+ // <Relationship Type, <From IdentityType, To IdentityType>>
+ private final Map<String, Map<String, Set<String>>>
supportedRelationshipMappings = new HashMap<String, Map<String,
Set<String>>>();
public FeaturesMetaDataImpl(IdentityStoreConfigurationMetaData configurationMD,
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java 2008-12-02
18:51:34 UTC (rev 124)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreImpl.java 2008-12-04
09:52:41 UTC (rev 125)
@@ -106,6 +106,11 @@
public void bootstrap(IdentityStoreConfigurationMetaData configurationMD) throws
IdentityException
{
+ if (configurationMD == null)
+ {
+ throw new IllegalArgumentException("Configuration is null");
+ }
+
configuration = new SimpleLDAPIdentityStoreConfiguration(configurationMD);
supportedFeatures = new FeaturesMetaDataImpl(configurationMD,
supportedSearchControls);
@@ -305,7 +310,12 @@
}
//log.debug("Search filter: " + filter);
- List sr = searchIdentityObjects(ctx, identityType, filter, null, new
String[]{getTypeConfiguration(ctx, identityType).getIdAttributeName()});
+ List sr = searchIdentityObjects(ctx,
+ identityType,
+ filter,
+ null,
+ new String[]{getTypeConfiguration(ctx, identityType).getIdAttributeName()},
+ null);
return sr.size();
@@ -346,13 +356,23 @@
if (filter != null && filter.length() > 0)
{
Object[] filterArgs = {name};
- sr = searchIdentityObjects(invocationCtx, type, filter, filterArgs, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
+ sr = searchIdentityObjects(invocationCtx,
+ type,
+ filter,
+ filterArgs,
+ new String[]{getTypeConfiguration(invocationCtx,
type).getIdAttributeName()},
+ null);
}
else
{
//search all entries
filter = "(".concat(getTypeConfiguration(invocationCtx,
type).getIdAttributeName()).concat("=").concat(name).concat(")");
- sr = searchIdentityObjects(invocationCtx, type, filter, null, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
+ sr = searchIdentityObjects(invocationCtx,
+ type,
+ filter,
+ null,
+ new String[]{getTypeConfiguration(invocationCtx,
type).getIdAttributeName()},
+ null);
}
//log.debug("Search filter: " + filter);
@@ -539,19 +559,21 @@
checkIOType(type);
- List<IdentityObject> objects = new LinkedList<IdentityObject>();
+ LinkedList<IdentityObject> objects = new LinkedList<IdentityObject>();
LDAPIdentityObjectTypeConfiguration typeConfiguration =
getTypeConfiguration(invocationCtx, type);
try
{
+ Control[] requestControls = null;
+
// Sort control
if (sortSearchControl != null)
{
//TODO: make criticallity optional
- ctx.setRequestControls(new Control[]{
+ requestControls = new Control[]{
new SortControl(typeConfiguration.getIdAttributeName(),
Control.NONCRITICAL)
- });
+ };
}
StringBuilder af = new StringBuilder();
@@ -583,12 +605,22 @@
{
Object[] filterArgs = {nameFilter};
- sr = searchIdentityObjects(invocationCtx, type, "&(" + filter +
")" + af.toString(), filterArgs, new
String[]{typeConfiguration.getIdAttributeName()});
+ sr = searchIdentityObjects(invocationCtx,
+ type,
+ "(&(" + filter + ")" + af.toString() +
")",
+ filterArgs,
+ new String[]{typeConfiguration.getIdAttributeName()},
+ requestControls);
}
else
{
filter =
"(".concat(typeConfiguration.getIdAttributeName()).concat("=").concat(nameFilter).concat(")");
- sr = searchIdentityObjects(invocationCtx, type, "&(" + filter +
")" + af.toString(), null, new
String[]{typeConfiguration.getIdAttributeName()});
+ sr = searchIdentityObjects(invocationCtx,
+ type,
+ "(&(" + filter + ")" + af.toString() +
")",
+ null,
+ new String[]{typeConfiguration.getIdAttributeName()},
+ requestControls);
}
@@ -596,18 +628,26 @@
{
ctx = (LdapContext)res.getObject();
String dn = ctx.getNameInNamespace();
- objects.add(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ if (sortSearchControl != null)
+ {
+ //TODO: It seams that sort control returns entries in descending order by
default...
+ if (!sortSearchControl.isAscending())
+ {
+ objects.addFirst(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ }
+ else
+ {
+ objects.addLast(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ }
+ }
+ else
+ {
+ objects.add(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
+ }
}
ctx.close();
- // Post sort if the order was descending
- if (sortSearchControl != null && !sortSearchControl.isAscending());
- {
- //TODO: rather sucks for the performance but I don't see how to do this
with JNDI SortControl
- //TODO: check if result was sorted (if the control was NONCRITICAL) to save
some cycles
- Collections.reverse(objects);
- }
return objects;
}
@@ -642,101 +682,6 @@
return findIdentityObject(invocationCtx, type, null);
}
-// public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCtx, IdentityObjectType type,
Map<String, String[]> attributes, int offset, int limit, boolean orderByName,
boolean ascending) throws IdentityException
-// {
-// //TODO: handle paged results and sort
-//
-// if (log.isLoggable(Level.FINER))
-// {
-// log.finer(toString() + ".findIdentityObject with type: " + type
-// + "; attributes: " + attributes
-// + "; offset: " + offset
-// + "; limit: " + limit
-// + "; orderByName: " + orderByName
-// + "; ascending: " + ascending
-// );
-// }
-//
-// Context ctx = getLDAPContext(invocationCtx);
-// checkIOType(type);
-//
-// List<IdentityObject> objects = new LinkedList<IdentityObject>();
-//
-// try
-// {
-// String filter = getTypeConfiguration(invocationCtx,
type).getEntrySearchFilter();
-// List<SearchResult> sr = null;
-//
-// //TODO: if no search filter is present just use search method with
matchingAttributes from DirContext instead of
-// //TODO: concatenating filter
-//
-// StringBuilder af = new StringBuilder("(&");
-//
-// for (Map.Entry<String, String[]> stringEntry : attributes.entrySet())
-// {
-// for (String value : stringEntry.getValue())
-// {
-// af.append("(")
-// .append(stringEntry.getKey())
-// .append("=")
-// .append(value)
-// .append(")");
-// }
-// }
-//
-// af.append(")");
-//
-// if (filter != null && filter.length() > 0)
-// {
-// // chars are escaped in filterArgs so we must replace it manually
-// filter = filter.replaceAll("\\{0\\}", "*");
-//
-// Object[] filterArgs = {};
-// sr = searchIdentityObjects(invocationCtx, type, "&(" + filter
+ ")" + af.toString(), filterArgs, new
String[]{getTypeConfiguration(invocationCtx, type).getIdAttributeName()});
-// }
-// else
-// {
-// filter = "(".concat(getTypeConfiguration(invocationCtx,
type).getIdAttributeName()).concat("=").concat("*").concat(")");
-// sr = searchIdentityObjects(invocationCtx, type, "&(" + filter
+ ")" + af.toString(), null, new String[]{getTypeConfiguration(invocationCtx,
type).getIdAttributeName()});
-// }
-//
-//
-// for (SearchResult res : sr)
-// {
-// ctx = (Context)res.getObject();
-// String dn = ctx.getNameInNamespace();
-// objects.add(createIdentityObjectInstance(invocationCtx, type,
res.getAttributes(), dn));
-// }
-//
-// ctx.close();
-// return objects;
-//
-// }
-// catch (NoSuchElementException e)
-// {
-// //log.debug("No identity object found with name: " + name, e);
-// }
-// catch (NamingException e)
-// {
-// throw new IdentityException("IdentityObject search failed.", e);
-// }
-// finally
-// {
-// try
-// {
-// if (ctx != null)
-// {
-// ctx.close();
-// }
-// }
-// catch (NamingException e)
-// {
-// throw new IdentityException("Failed to close LDAP connection",
e);
-// }
-// }
-//
-// return objects;
-// }
public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext ctx, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent,
IdentityObjectSearchControl[] controls) throws IdentityException
{
@@ -956,9 +901,10 @@
LdapContext ldapContext = getLDAPContext(ctx);
// Check posibilities
- //TODO: Supported features should handle information from type configurations
- if
(!getSupportedFeatures().isRelationshipTypeSupported(fromIdentity.getIdentityType(),
toIdentity.getIdentityType(), relationshipType))
+ //TODO: null RelationshipType passed from removeRelationships
+ if (relationshipType != null &&
+
!getSupportedFeatures().isRelationshipTypeSupported(fromIdentity.getIdentityType(),
toIdentity.getIdentityType(), relationshipType))
{
throw new IdentityException("Relationship not supported");
}
@@ -1117,12 +1063,6 @@
throw new OperationNotSupportedException("Named relationships are not
supported by this implementation of LDAP IdentityStore");
}
- public boolean hasPasswordAttribute(IdentityStoreInvocationContext ctx,
IdentityObjectType type) throws IdentityException
- {
- //TODO: NYI
- throw new NotYetImplementedException();
- }
-
public boolean validateCredential(IdentityStoreInvocationContext ctx, IdentityObject
identityObject, IdentityObjectCredential credential) throws IdentityException
{
//TODO: NYI
@@ -1479,24 +1419,35 @@
return ldapio;
}
- public List<SearchResult> searchIdentityObjects(IdentityStoreInvocationContext
ctx, IdentityObjectType type, String filter, Object[] filterArgs, String[]
returningAttributes) throws NamingException, IdentityException
+ public List<SearchResult> searchIdentityObjects(IdentityStoreInvocationContext
ctx,
+ IdentityObjectType type,
+ String filter,
+ Object[] filterArgs,
+ String[] returningAttributes,
+ Control[] requestControls) throws
NamingException, IdentityException
{
LdapContext ldapContext = getLDAPContext(ctx);
+
+ if (ldapContext != null)
+ {
+ ldapContext.setRequestControls(requestControls);
+ }
+
NamingEnumeration results = null;
try
{
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
- controls.setTimeLimit(getConfiguration(ctx).getSearchTimeLimit());
+ SearchControls searchControls = new SearchControls();
+ searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ searchControls.setReturningObjFlag(true);
+ searchControls.setTimeLimit(getConfiguration(ctx).getSearchTimeLimit());
if (returningAttributes != null)
{
- controls.setReturningAttributes(returningAttributes);
+ searchControls.setReturningAttributes(returningAttributes);
}
@@ -1506,11 +1457,11 @@
{
if (filterArgs == null)
{
- results = ldapContext.search(entryCtxs[0], filter, controls);
+ results = ldapContext.search(entryCtxs[0], filter, searchControls);
}
else
{
- results = ldapContext.search(entryCtxs[0], filter, filterArgs, controls);
+ results = ldapContext.search(entryCtxs[0], filter, filterArgs,
searchControls);
}
return Tools.toList(results);
@@ -1524,11 +1475,11 @@
{
if (filterArgs == null)
{
- results = ldapContext.search(entryCtx, filter, controls);
+ results = ldapContext.search(entryCtx, filter, searchControls);
}
else
{
- results = ldapContext.search(entryCtx, filter, filterArgs, controls);
+ results = ldapContext.search(entryCtx, filter, filterArgs,
searchControls);
}
merged.addAll(Tools.toList(results));
results.close();
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-12-02
18:51:34 UTC (rev 124)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/store/ldap/LDAPIdentityStoreTestCase.java 2008-12-04
09:52:41 UTC (rev 125)
@@ -1,514 +1,510 @@
-///*
-//* 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.store.ldap;
-//
-//import junit.framework.TestCase;
-//import org.jboss.identity.opends.OpenDSService;
-//import org.jboss.identity.spi.store.IdentityStore;
-//import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
-//import org.jboss.identity.spi.model.IdentityObject;
-//import org.jboss.identity.impl.store.IdentityTypeEnum;
-//import org.jboss.identity.impl.store.CommonIdentityStoreTest;
-//import org.jboss.identity.impl.store.IdentityStoreTestContext;
-//import org.opends.server.tools.LDAPModify;
-//
-//import javax.naming.Context;
-//import javax.naming.NamingException;
-//import javax.naming.NamingEnumeration;
-//import javax.naming.Binding;
-//import javax.naming.directory.DirContext;
-//import javax.naming.ldap.LdapContext;
-//import javax.naming.ldap.InitialLdapContext;
-//import java.net.URL;
-//import java.util.Hashtable;
-//import java.util.Map;
-//import java.util.HashMap;
-//import java.util.Set;
-//import java.util.HashSet;
-//import java.util.logging.Logger;
-//import java.util.logging.Level;
-//import java.io.File;
-//
-///**
-// * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
-// * @version : 0.1 $
-// */
-//public class LDAPIdentityStoreTestCase extends TestCase implements
IdentityStoreTestContext
-//{
-//
-// 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";
-//
-// OpenDSService openDSService = new
OpenDSService("target/test-classes/opends");
-//
-// IdentityStore store;
-//
-// CommonIdentityStoreTest commonTest;
-//
-// LDAPIdentityStoreInvocationContext ctx;
-//
-// public LDAPIdentityStoreTestCase(String s)
-// {
-// super(s);
-// commonTest = new CommonIdentityStoreTest(this);
-// }
-//
-// protected void setUp() throws Exception
-// {
-// super.setUp();
-//
-// openDSService.start();
-//
-// // Initiate invocation context with simple configuration
-// initiateCtx();
-//
-//// populate();
-//
-// store = new LDAPIdentityStore("simpleTestLDAPStore");
-//
-//
-//
-// }
-//
-// protected void tearDown() throws Exception
-// {
-// super.tearDown();
-//
-// cleanUp();
-//
-// openDSService.stop();
-// }
-//
-// public void begin() throws Exception
-// {
-// //nothing
-// }
-//
-// public void commit() throws Exception
-// {
-// //nothing
-// }
-//
-// public void flush() throws Exception
-// {
-// //nothing
-// }
-//
-// public IdentityStore getStore()
-// {
-// return store;
-// }
-//
-// public IdentityStoreInvocationContext getCtx()
-// {
-// return ctx;
-// }
-//
-//
-//
-//
-//
-// 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() throws Exception
-// {
-// try
-// {
-//
-// DirContext ldapCtx = ctx.getLdapContext();
-// 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 void initiateCtx()
-// {
-//
-// Map<String, LDAPIdentityObjectTypeConfiguration> typesMap = new
HashMap<String, LDAPIdentityObjectTypeConfiguration>();
-//
-// //USER
-// 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(IdentityTypeEnum.USER.getName(), tc);
-//
-//
-// // 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(IdentityTypeEnum.ROLE.getName(), tc);
-//
-// // 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(IdentityTypeEnum.GROUP.getName(), tc);
-//
-// // ORGANIZATION
-// 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=Organizations,o=test,dc=portal,dc=example,dc=com"});
-// tc.setEntrySearchFilter(null);
-// tc.setIdAttributeName("cn");
-// tc.setMembershipAttributeDN(true);
-// tc.setMembershipAttributeName("member");
-// typesMap.put(IdentityTypeEnum.ORGANIZATION.getName(), tc);
-//
-//
-// SimpleLDAPIdentityStoreConfiguration configuration =
-// new SimpleLDAPIdentityStoreConfiguration(
-// LDAP_PROVIDER_URL,
-// LDAP_PRINCIPAL,
-// LDAP_CREDENTIALS,
-// 10000,
-// typesMap);
-//
-// ctx = new SimpleLDAPIdentityStoreInvocationContext(configuration);
-// }
-//
-//
-// // 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());
-//
-// }
-//
-// public void testRelationships() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testRelationships();
-//
-// }
-//
-// public void testStorePersistence() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testStorePersistence();
-//
-// }
-//
-// public void testFindMethods() throws Exception
-// {
-// populateClean();
-//
-// commonTest.testFindMethods();
-//
-// }
-//
-//}
+/*
+* 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.store.ldap;
+
+import junit.framework.TestCase;
+import org.jboss.identity.opends.OpenDSService;
+import org.jboss.identity.spi.store.IdentityStore;
+import org.jboss.identity.spi.store.IdentityStoreInvocationContext;
+import org.jboss.identity.spi.store.IdentityStoreSession;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.spi.configuration.metadata.IdentityConfigurationMetaData;
+import org.jboss.identity.spi.configuration.metadata.IdentityStoreConfigurationMetaData;
+import org.jboss.identity.impl.store.IdentityTypeEnum;
+import org.jboss.identity.impl.store.CommonIdentityStoreTest;
+import org.jboss.identity.impl.store.IdentityStoreTestContext;
+import org.jboss.identity.impl.configuration.jaxb2.JAXB2IdentityConfiguration;
+import org.jboss.identity.exception.IdentityException;
+import org.opends.server.tools.LDAPModify;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.Binding;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class LDAPIdentityStoreTestCase extends TestCase implements
IdentityStoreTestContext
+{
+
+ 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";
+
+ OpenDSService openDSService = new
OpenDSService("target/test-classes/opends");
+
+ IdentityStore store;
+
+ CommonIdentityStoreTest commonTest;
+
+ IdentityStoreInvocationContext ctx;
+
+ public LDAPIdentityStoreTestCase(String s)
+ {
+ super(s);
+ commonTest = new CommonIdentityStoreTest(this);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ openDSService.start();
+
+ IdentityConfigurationMetaData configurationMD = JAXB2IdentityConfiguration
+ .createConfigurationMetaData(new
File("src/test/resources/store-test-config.xml"));
+
+ IdentityStoreConfigurationMetaData storeMD = null;
+
+ for (IdentityStoreConfigurationMetaData metaData :
configurationMD.getIdentityStores())
+ {
+ if (metaData.getId().equals("LDAPTestStore"))
+ {
+ storeMD = metaData;
+ break;
+ }
+ }
+
+ ctx = new IdentityStoreInvocationContext()
+ {
+ public IdentityStoreSession getIdentityStoreSession()
+ {
+ return new IdentityStoreSession(){
+
+ public Object getSessionContext() throws IdentityException
+ {
+ try
+ {
+ return getLdapContext();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Failed to obtain LDAP connection:
", e);
+ }
+ }
+
+ public void close() throws IdentityException
+ {
+
+ }
+
+ public void save() throws IdentityException
+ {
+
+ }
+
+ public void clear() throws IdentityException
+ {
+
+ }
+
+ public boolean isOpen()
+ {
+ return false;
+ }
+
+ public boolean isTransactionSupported()
+ {
+ return false;
+ }
+
+ public void startTransaction()
+ {
+
+ }
+
+ public void commitTransaction()
+ {
+
+ }
+
+ public void rollbackTransaction()
+ {
+
+ }
+
+ public boolean isTransactionActive()
+ {
+ return false;
+ }
+ };
+ }
+
+ public String getRealmId()
+ {
+ return "testRealm";
+ }
+ };
+
+ //populate();
+
+ store = new LDAPIdentityStoreImpl("LDAPTestStore");
+
+ store.bootstrap(storeMD);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ cleanUp();
+
+ openDSService.stop();
+ }
+
+ public void begin() throws Exception
+ {
+ //nothing
+ }
+
+ public void commit() throws Exception
+ {
+ //nothing
+ }
+
+ public void flush() throws Exception
+ {
+ //nothing
+ }
+
+ public IdentityStore getStore()
+ {
+ return store;
+ }
+
+ public IdentityStoreInvocationContext getCtx()
+ {
+ return ctx;
+ }
+
+
+ public LdapContext getLdapContext() throws Exception
+ {
+ 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);
+
+ return new InitialLdapContext(env, null);
+ }
+
+
+
+ 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() throws Exception
+ {
+ DirContext ldapCtx = getLdapContext();
+
+ try
+ {
+
+
+ String dn = "dc=portal,dc=example,dc=com";
+
+ System.out.println("Removing: " + dn);
+
+ removeContext(ldapCtx, dn);
+ }
+ catch (Exception e)
+ {
+ //
+ }
+ finally
+ {
+ ldapCtx.close();
+ }
+ }
+
+ //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);
+ }
+
+ // 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.IDENTITY));
+ 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.IDENTITY));
+
+ IdentityObject io = store.findIdentityObject(ctx, "admin",
IdentityTypeEnum.IDENTITY);
+ 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.IDENTITY));
+
+ store.createIdentityObject(ctx, "newUserA", IdentityTypeEnum.IDENTITY);
+
+ assertEquals(7, store.getIdentityObjectsCount(ctx, IdentityTypeEnum.IDENTITY));
+
+ //
+
+ 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.IDENTITY);
+ IdentityObject user2 = store.createIdentityObject(ctx, "Eva",
IdentityTypeEnum.IDENTITY);
+
+ //
+
+ Map<String, String[]> attrs = new HashMap<String, String[]>();
+
+
+ attrs.put("phone", new String[]{"val1", "val2",
"val3"});
+ attrs.put("description", new String[]{"val1", "val2",
"val3", "val4"});
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ Map<String, String[]> persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("phone"));
+ assertEquals(3, persistedAttrs.get("phone").length);
+
+ assertTrue(persistedAttrs.containsKey("description"));
+ assertEquals(4, persistedAttrs.get("description").length);
+
+ //
+
+ attrs = new HashMap<String, String[]>();
+ attrs.put("carLicense", new String[]{"val1"});
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("phone"));
+ assertEquals(3, persistedAttrs.get("phone").length);
+
+ assertTrue(persistedAttrs.containsKey("description"));
+ assertEquals(4, persistedAttrs.get("description").length);
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(1, persistedAttrs.get("carLicense").length);
+
+ attrs.put("carLicense", new String[]{"val2"});
+
+ store.addAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(2, persistedAttrs.get("carLicense").length);
+
+ //
+
+ store.updateAttributes(ctx, user1, attrs);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(3, persistedAttrs.keySet().size());
+
+ assertTrue(persistedAttrs.containsKey("carLicense"));
+ assertEquals(1, persistedAttrs.get("carLicense").length);
+
+ //
+
+ String[] names = new String[]{"carLicense"};
+ store.removeAttributes(ctx, user1, names);
+
+ //
+
+ persistedAttrs = store.getAttributes(ctx, user1);
+
+ assertEquals(2, persistedAttrs.keySet().size());
+
+ }
+
+ public void testRelationships() throws Exception
+ {
+ populateClean();
+
+ commonTest.testRelationships();
+
+ }
+
+ public void testStorePersistence() throws Exception
+ {
+ populateClean();
+
+ commonTest.testStorePersistence();
+
+ }
+
+ public void testFindMethods() throws Exception
+ {
+ populateClean();
+
+ commonTest.testFindMethods();
+
+ }
+
+ public void testControls() throws Exception
+ {
+ populateClean();
+
+ commonTest.testControls();
+ }
+
+}
Modified: trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif
===================================================================
--- trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif 2008-12-02
18:51:34 UTC (rev 124)
+++ trunk/identity-impl/src/test/resources/ldap/initial-empty-opends.ldif 2008-12-04
09:52:41 UTC (rev 125)
@@ -28,5 +28,5 @@
dn: ou=Organizations,o=test,dc=portal,dc=example,dc=com
objectclass: top
objectclass: organizationalUnit
-ou: Groups
+ou: Organizations
Modified: trunk/identity-impl/src/test/resources/ldap/initial-opends.ldif
===================================================================
--- trunk/identity-impl/src/test/resources/ldap/initial-opends.ldif 2008-12-02 18:51:34
UTC (rev 124)
+++ trunk/identity-impl/src/test/resources/ldap/initial-opends.ldif 2008-12-04 09:52:41
UTC (rev 125)
@@ -163,3 +163,8 @@
description: Some organization
member: cn=User,ou=Roles,o=test,dc=portal,dc=example,dc=com
member: cn=Admin,ou=Roles,o=test,dc=portal,dc=example,dc=com
+
+dn: ou=Organizations,o=test,dc=portal,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: Organization
Modified: trunk/identity-impl/src/test/resources/store-test-config.xml
===================================================================
--- trunk/identity-impl/src/test/resources/store-test-config.xml 2008-12-02 18:51:34 UTC
(rev 124)
+++ trunk/identity-impl/src/test/resources/store-test-config.xml 2008-12-04 09:52:41 UTC
(rev 125)
@@ -161,7 +161,9 @@
<id>LDAPTestStore</id>
<class>org.jboss.identity.impl.store.ldap.LDAPIdentityStoreImpl</class>
<external-config/>
- <supported-relationship-types/>
+ <supported-relationship-types>
+
<relationship-type>JBOSS_IDENTITY_MEMBERSHIP</relationship-type>
+ </supported-relationship-types>
<supported-identity-object-types>
<identity-object-type>
<name>IDENTITY</name>
@@ -218,17 +220,21 @@
<name>GROUP</name>
<relationships>
<relationship>
- <relationship-type-ref/>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
<identity-object-type-ref>IDENTITY</identity-object-type-ref>
</relationship>
<relationship>
- <relationship-type-ref/>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
<identity-object-type-ref>ROLE</identity-object-type-ref>
</relationship>
<relationship>
- <relationship-type-ref/>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
<identity-object-type-ref>GROUP</identity-object-type-ref>
</relationship>
+ <relationship>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
+
<identity-object-type-ref>ORGANIZATION</identity-object-type-ref>
+ </relationship>
</relationships>
<credentials/>
<attributes/>
@@ -239,7 +245,7 @@
</option>
<option>
<name>ctxDNs</name>
-
<value>ou=Roles,o=test,dc=portal,dc=example,dc=com</value>
+
<value>ou=Groups,o=test,dc=portal,dc=example,dc=com</value>
</option>
<!--<option>-->
<!--<name>entrySearchFilter</name>-->
@@ -269,10 +275,68 @@
</options>
</identity-object-type>
<identity-object-type>
+ <name>ORGANIZATION</name>
+ <relationships>
+ <relationship>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
+
<identity-object-type-ref>IDENTITY</identity-object-type-ref>
+ </relationship>
+ <relationship>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
+
<identity-object-type-ref>ROLE</identity-object-type-ref>
+ </relationship>
+ <relationship>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
+
<identity-object-type-ref>GROUP</identity-object-type-ref>
+ </relationship>
+ <relationship>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
+
<identity-object-type-ref>ORGANIZATION</identity-object-type-ref>
+ </relationship>
+ </relationships>
+ <credentials/>
+ <attributes/>
+ <options>
+ <option>
+ <name>idAttributeName</name>
+ <value>cn</value>
+ </option>
+ <option>
+ <name>ctxDNs</name>
+
<value>ou=Organizations,o=test,dc=portal,dc=example,dc=com</value>
+ </option>
+ <!--<option>-->
+ <!--<name>entrySearchFilter</name>-->
+ <!--<value></value>-->
+ <!--</option>-->
+ <option>
+ <name>allowCreateEntry</name>
+ <value>true</value>
+ </option>
+ <option>
+ <name>membershipAttributeName</name>
+ <value>member</value>
+ </option>
+ <option>
+ <name>isMembershipAttributeDN</name>
+ <value>true</value>
+ </option>
+ <option>
+ <name>allowEmptyMemberships</name>
+ <value>true</value>
+ </option>
+ <option>
+ <name>createEntryAttributeValues</name>
+ <value>objectClass=top</value>
+ <value>objectClass=groupOfNames</value>
+ </option>
+ </options>
+ </identity-object-type>
+ <identity-object-type>
<name>ROLE</name>
<relationships>
<relationship>
- <relationship-type-ref/>
+
<relationship-type-ref>JBOSS_IDENTITY_MEMBERSHIP</relationship-type-ref>
<identity-object-type-ref>IDENTITY</identity-object-type-ref>
</relationship>
</relationships>