[jboss-svn-commits] JBoss Portal SVN: r5660 - in trunk: identity/src/main/org/jboss/portal/identity2 identity/src/main/org/jboss/portal/identity2/ldap identity/src/main/org/jboss/portal/test/identity/ldap test/src/etc/identityconfig test/src/etc/ldap/ldif
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 15 12:32:21 EST 2006
Author: bdaw
Date: 2006-11-15 12:32:02 -0500 (Wed, 15 Nov 2006)
New Revision: 5660
Added:
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java
trunk/test/src/etc/identityconfig/opends-config.xml
trunk/test/src/etc/identityconfig/rhds-config.xml
trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif
Log:
- identity modules refactoring
- minor features fixed and implemented
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -64,6 +64,8 @@
public static final String USER_PASSWORD_ATTRIBUTE_ID = "passwordAttributeID";
+ public static final String USER_EMAIL_ATTRIBUTE_ID = "emailAttributeID";
+
public static final String ROLE_CONTAINER_DN = "roleContainerDN";
public static final String ROLE_RID_ATTRIBUTE_ID = "ridAttributeID";
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -0,0 +1,226 @@
+/*
+* 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.portal.identity2.ldap;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity2.MembershipModule;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPMembershipModule extends AbstractJBossService implements MembershipModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPMembershipModule.class);
+
+ private LDAPConnectionContext connectionContext;
+
+ private LDAPUserModule userModule;
+
+ private LDAPRoleModule roleModule;
+
+ private IdentityContext identityContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+
+ //private LDAPMembershipStrategy membershipStrategy;
+
+ private String jndiName;
+
+ protected JNDI.Binding jndiBinding;
+
+
+ /** DN under which roles should be searched. Used only when obtaining roles having only User DN. */
+ /*private String roleCtxDN;*/
+
+
+
+ /** Name of attribute in role entry that point to belonging user */
+ //private String uidAttributeID;
+
+
+ /** If the uidAttributeID in Role entry keeps full DN of a user or just a name */
+ //private boolean uidAttributeIsDN;
+
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.MEMBERSHIP_MODULE);
+ }
+
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.MEMBERSHIP_MODULE);
+ }
+
+ }
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+
+ if (connectionContext == null)
+ {
+ try
+ {
+ this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context", e);
+ }
+ }
+ return connectionContext;
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ protected LDAPUserModule getUserModule() throws IdentityException
+ {
+
+ if (userModule == null)
+ {
+ try
+ {
+ this.userModule = (LDAPUserModule)identityContext.getObject(IdentityContext.USER_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context - must be LDAPUserModule", e);
+ }
+ }
+ return userModule;
+ }
+
+ protected LDAPRoleModule getRoleModule() throws IdentityException
+ {
+
+ if (roleModule == null)
+ {
+ try
+ {
+ this.roleModule = (LDAPRoleModule)identityContext.getObject(IdentityContext.ROLE_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context", e);
+ }
+ }
+ return roleModule;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ protected String getMemberAttributeID() throws IdentityException
+ {
+ String uid = getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
+ if (uid == null)
+ {
+ return "member";
+ }
+ return uid;
+ }
+
+ /*public void setUidAttributeID(String uidAttributeID)
+ {
+ this.uidAttributeID = uidAttributeID;
+ }*/
+
+ protected boolean isUidAttributeIsDN() throws IdentityException
+ {
+ if (getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) == null)
+ {
+ return true;
+ }
+
+ return getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
+ }
+
+ /*protected String getRoleContainerDN() throws IdentityException
+ {
+ return getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
+ }*/
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -51,19 +51,33 @@
}
- public LDAPRoleImpl(String dn, IdentityContext context)
+ public LDAPRoleImpl(String dn, IdentityContext context, String id, String display)
{
if (dn == null)
{
throw new IllegalArgumentException("LDAPRoleImpl need to be aware of its DN");
}
- this.dn = dn;
+
if (context == null)
{
throw new IllegalArgumentException("IdentityContext can't be null");
}
+
+ if (id == null)
+ {
+ throw new IllegalArgumentException("Id can't be null");
+ }
+
+ if (display == null)
+ {
+ throw new IllegalArgumentException("displayName can't be null");
+ }
+
this.identityContext = context;
+ this.id = id;
+ this.displayName = display;
+ this.dn = dn;
}
public String getName()
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -0,0 +1,253 @@
+/*
+* 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.portal.identity2.ldap;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.common.util.JNDI;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPRoleModule extends AbstractJBossService implements RoleModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPRoleModule.class);
+
+ private LDAPConnectionContext connectionContext;
+
+ private String jndiName;
+
+ private IdentityContext identityContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+ private JNDI.Binding jndiBinding;
+
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.ROLE_MODULE);
+ }
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.ROLE_MODULE);
+ }
+
+ }
+
+ protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws IdentityException
+ {
+ LDAPRoleImpl ldapr = null;
+ try
+ {
+
+ log.debug("Attributes: " + attrs);
+
+ //role name
+ Attribute uida = attrs.get(getRidAttributeID());
+ if (uida == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getRidAttributeID());
+ }
+ //ldapr = new LDAPRoleImpl(uida.getID().concat("=").concat((String)uida.get()) + "," + getContainerDN(), identityContext);
+ Attribute display = attrs.get(getDisplayNameAttributeID());
+ if (display == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getDisplayNameAttributeID());
+ }
+ ldapr = new LDAPRoleImpl(dn, identityContext, uida.get().toString(), display.get().toString());
+
+
+
+ log.debug("role uid: " + ldapr.getId());
+ log.debug("role dn: " + ldapr.getDn());
+
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPRoleImpl object from ldap entry (SearchResult)", e);
+ }
+
+ return ldapr;
+ }
+
+ /**
+ * method not belonging to UserModule interface - ldap specific.
+ *
+ */
+ public Role findRoleByDN(String dn) throws IdentityException, IllegalArgumentException
+ {
+ try
+ {
+ log.debug("findRoleByDN(): DN = " + dn);
+
+ if (dn == null)
+ {
+ throw new IdentityException("Role dn canot be null");
+ }
+
+ Attributes attrs = getConnectionContext().createInitialContext().getAttributes(dn);
+
+ if (attrs == null)
+ {
+ throw new IdentityException("Can't find user entry with DN: " + dn);
+ }
+
+ return createRoleInstance(attrs, dn);
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with dn: " + dn, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+ }
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow role module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper role search filter from the module
+ * @return
+ */
+ public abstract NamingEnumeration searchRoles(String filter) throws NamingException, IdentityException;
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ protected String getRidAttributeID() throws IdentityException
+ {
+ String rid = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_RID_ATTRIBUTE_ID);
+ if (rid == null)
+ {
+ return "cn";
+ }
+ return rid;
+ }
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ }
+ return connectionContext;
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ protected String getContainerDN() throws IdentityException
+ {
+ String cont = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
+ if (cont == null)
+ {
+ throw new IdentityException("Configuration option missing: " + IdentityConfiguration.ROLE_CONTAINER_DN);
+ }
+ return cont;
+ }
+
+ protected String getDisplayNameAttributeID() throws IdentityException
+ {
+ String display = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_DISPLAY_NAME_ATTRIBUTE_ID);
+ if (display == null)
+ {
+ return getRidAttributeID();
+ }
+ return display;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ protected String getJndiName()
+ {
+ return jndiName;
+ }
+
+ protected void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -55,67 +55,10 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPRoleModuleImpl extends AbstractJBossService implements RoleModule
+public class LDAPRoleModuleImpl extends LDAPRoleModule
{
- private LDAPConnectionContext connectionContext;
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPRoleModuleImpl.class);
- private String jndiName;
-
- private IdentityContext identityContext;
-
- private IdentityConfiguration identityConfiguration;
-
- //private String ridAttributeID;
-
- //private String containerDN;
-
- //private String displayNameAttributeID;
-
- protected JNDI.Binding jndiBinding;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.ROLE_MODULE);
- }
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.ROLE_MODULE);
- }
-
- }
-
public Role findRoleByName(String name) throws IdentityException, IllegalArgumentException
{
try
@@ -127,15 +70,12 @@
throw new IdentityException("Role name canot be null");
}
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
- String filter = getRidAttributeID().concat("=").concat(name);
+ String filter = "(".concat(getRidAttributeID()).concat("=").concat(name).concat(")");
log.debug("Search filter: " + filter);
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ NamingEnumeration results = searchRoles(filter);
List sr = Tools.toList(results);
if (sr.size() > 1)
{
@@ -160,9 +100,43 @@
public Set findRolesByNames(String[] names) throws IdentityException, IllegalArgumentException
{
+ if (names == null)
+ {
+ throw new IllegalArgumentException("null argument");
+ }
- //TODO:
- throw new UnsupportedOperationException("Not yet implemented");
+ Set roles = new HashSet();
+ try
+ {
+ //construct a filter with all role names
+ StringBuffer filter = new StringBuffer("(| ");
+ for (int i = 0; i < names.length; i++)
+ {
+ String name = names[i];
+ filter.append("(")
+ .append(getRidAttributeID())
+ .append("=")
+ .append(name)
+ .append(") ");
+ }
+ filter.append(")");
+
+ NamingEnumeration results = searchRoles(filter.toString());
+ List sr = Tools.toList(results);
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ roles.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Can't retreive roles", e);
+ }
+
+ return roles;
+
}
public Role findRoleById(Object id) throws IdentityException, IllegalArgumentException
@@ -183,11 +157,8 @@
return findRoleByName(id);
}
-
public Role createRole(String name, String displayName) throws IdentityException, IllegalArgumentException
{
-
- //TODO: handle displayName (what attribute in schema?)
if (name == null)
{
throw new IdentityException("Role name cannot be null");
@@ -203,11 +174,7 @@
Attributes attrs = new BasicAttributes(true);
//add attribute using provided configuration
- Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES);
- if (attributesToAdd == null)
- {
- throw new IdentityException(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES + " missing in configuration");
- }
+ Map attributesToAdd = getAttributesToAdd();
//attribute
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
@@ -279,15 +246,11 @@
{
try
{
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
//search all entries containing "cn" attribute
String filter = getRidAttributeID().concat("=").concat("*");
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ NamingEnumeration results = searchRoles(filter);
List sr = Tools.toList(results);
return sr.size();
@@ -309,22 +272,17 @@
Set rf = new HashSet();
try
{
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
//search all entries containing "cn" attribute
- String filter = getRidAttributeID().concat("=").concat("*");
+ String filter = "(".concat(getRidAttributeID()).concat("=").concat("*").concat(")");
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ NamingEnumeration results = searchRoles(filter);
while (results.hasMoreElements())
{
SearchResult res = (SearchResult)results.nextElement();
DirContext ctx = (DirContext)res.getObject();
rf.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
}
-
}
catch (NoSuchElementException e)
{
@@ -337,6 +295,25 @@
return rf;
}
+ /**
+ * This method should be used by over modules to perform searches. It will allow role module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper role search filter from the module
+ * @return
+ */
+ public NamingEnumeration searchRoles(String filter) throws NamingException, IdentityException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
+
+ //String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);
+
+ return getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ }
+
//TODO:remove this - it's only a fasade to make this implementation compatible with old RoleModule interface
public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
{
@@ -382,178 +359,16 @@
}
-
- protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws IdentityException
+ private Map getAttributesToAdd() throws IdentityException
{
- LDAPRoleImpl ldapr = null;
- try
+ Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
{
-
- log.debug("Attributes: " + attrs);
-
- //role name
- Attribute uida = attrs.get(getRidAttributeID());
- if (uida == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getRidAttributeID());
- }
- //ldapr = new LDAPRoleImpl(uida.getID().concat("=").concat((String)uida.get()) + "," + getContainerDN(), identityContext);
- ldapr = new LDAPRoleImpl(dn, identityContext);
- ldapr.setId((String)uida.get());
-
- Attribute display = attrs.get(getDisplayNameAttributeID());
- if (display != null)
- {
- ldapr.setDisplayName((String)display.get());
- }
-
- log.debug("role uid: " + ldapr.getId());
- log.debug("role dn: " + ldapr.getDn());
-
-
+ throw new IdentityException(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES + " missing in configuration");
}
- catch (NamingException e)
- {
- throw new IdentityException("Couldn't create LDAPRoleImpl object from ldap entry (SearchResult)", e);
- }
-
- return ldapr;
+ return attributesToAdd;
}
- /**
- * method not belonging to UserModule interface - ldap specific.
- *
- */
- public Role findRoleByDN(String dn) throws IdentityException, IllegalArgumentException
- {
- try
- {
- log.debug("findRoleByDN(): DN = " + dn);
- if (dn == null)
- {
- throw new IdentityException("Role dn canot be null");
- }
- /*SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- String filter = getUidAttributeID().concat("=").concat(userName);
- log.debug("Search filter: " + filter);*/
- //DirContext ctx = (DirContext)getConnectionContext().createInitialContext().lookup(dn);
- Attributes attrs = getConnectionContext().createInitialContext().getAttributes(dn);
-
- if (attrs == null)
- {
- throw new IdentityException("Can't find user entry with DN: " + dn);
- }
-
- return createRoleInstance(attrs, dn);
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No user found with dn: " + dn, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return null;
-
- }
-
- //**************************
- //*** Getter and Setters
- //**************************
-
- public String getRidAttributeID() throws IdentityException
- {
- String rid = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_RID_ATTRIBUTE_ID);
- if (rid == null)
- {
- return "cn";
- }
- return rid;
- }
-
- /*public void setRidAttributeID(String ridAttributeID)
- {
- this.ridAttributeID = ridAttributeID;
- }*/
-
-
- public LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
- }
- return connectionContext;
- }
-
- public IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
- /*public void setConnectionContext(LDAPConnectionContext connectionContext)
- {
- this.connectionContext = connectionContext;
- }*/
-
- public String getContainerDN() throws IdentityException
- {
- String cont = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
- if (cont == null)
- {
- throw new IdentityException("Configuration option missing: " + IdentityConfiguration.ROLE_CONTAINER_DN);
- }
- return cont;
- }
-
- /*public void setContainerDN(String containerDN)
- {
- this.containerDN = containerDN;
- }*/
-
- public String getDisplayNameAttributeID() throws IdentityException
- {
- String display = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_DISPLAY_NAME_ATTRIBUTE_ID);
- if (display == null)
- {
- return getRidAttributeID();
- }
- return display;
- }
-
- /*public void setDisplayNameAttributeID(String displayNameAttributeID)
- {
- this.displayNameAttributeID = displayNameAttributeID;
- }*/
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -53,83 +53,11 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPStaticGroupMembershipModuleImpl extends AbstractJBossService implements MembershipModule
+public class LDAPStaticGroupMembershipModuleImpl extends LDAPMembershipModule
{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticGroupMembershipModuleImpl.class);
+
- private LDAPConnectionContext connectionContext;
-
- private LDAPUserModuleImpl userModule;
-
- private LDAPRoleModuleImpl roleModule;
-
- private IdentityContext identityContext;
-
- private IdentityConfiguration identityConfiguration;
-
-
- //private LDAPMembershipStrategy membershipStrategy;
-
- private String jndiName;
-
- protected JNDI.Binding jndiBinding;
-
-
- /** DN under which roles should be searched. Used only when obtaining roles having only User DN. */
- /*private String roleCtxDN;*/
-
-
-
- /** Name of attribute in role entry that point to belonging user */
- //private String uidAttributeID;
-
-
- /** If the uidAttributeID in Role entry keeps full DN of a user or just a name */
- //private boolean uidAttributeIsDN;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.MEMBERSHIP_MODULE);
- }
-
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.MEMBERSHIP_MODULE);
- }
-
- }
-
public Set getRoles(User user) throws IdentityException
{
if (user == null)
@@ -166,17 +94,10 @@
}
- //TODO: move this search to RoleModule
- SearchControls controls = new SearchControls();
- //TODO: let to search roles with different scopes
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
String filter = getMemberAttributeID().concat("=").concat(memberName);
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getRoleContainerDN(), filter, controls);
+ NamingEnumeration results = getRoleModule().searchRoles(filter);
List sr = Tools.toList(results);
@@ -319,8 +240,14 @@
try
{
LDAPUserImpl user = (LDAPUserImpl)iterator.next();
- //TODO: check option and add value as name - not DN
- member.add(user.getDn());
+ if (isUidAttributeIsDN())
+ {
+ member.add(user.getDn());
+ }
+ else
+ {
+ member.add(user.getId().toString());
+ }
}
catch (ClassCastException e)
{
@@ -388,17 +315,10 @@
try
{
- //TODO: move this search to RoleModule
- SearchControls controls = new SearchControls();
- //TODO: let to search roles with different scopes
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
String filter = getMemberAttributeID().concat("=").concat(memberName);
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getRoleContainerDN(), filter, controls);
+ NamingEnumeration results = getRoleModule().searchRoles(filter);
List sr = Tools.toList(results);
//iterate over roles that contain a user
for (Iterator iterator = sr.iterator(); iterator.hasNext();)
@@ -471,122 +391,5 @@
}
- //************************************
- //******* Getters and Setters ********
- //************************************
-
- public LDAPConnectionContext getConnectionContext() throws IdentityException
- {
-
- if (connectionContext == null)
- {
- try
- {
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context", e);
- }
- }
- return connectionContext;
- }
-
- public IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
- public LDAPUserModuleImpl getUserModule() throws IdentityException
- {
-
- if (userModule == null)
- {
- try
- {
- this.userModule = (LDAPUserModuleImpl)identityContext.getObject(IdentityContext.USER_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context - must be LDAPUserModuleImpl", e);
- }
- }
- return userModule;
- }
-
- public LDAPRoleModuleImpl getRoleModule() throws IdentityException
- {
-
- if (roleModule == null)
- {
- try
- {
- this.roleModule = (LDAPRoleModuleImpl)identityContext.getObject(IdentityContext.ROLE_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context", e);
- }
- }
- return roleModule;
- }
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public String getMemberAttributeID() throws IdentityException
- {
- String uid = getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
- if (uid == null)
- {
- return "member";
- }
- return uid;
- }
-
- /*public void setUidAttributeID(String uidAttributeID)
- {
- this.uidAttributeID = uidAttributeID;
- }*/
-
- public boolean isUidAttributeIsDN() throws IdentityException
- {
- if (getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) == null)
- {
- return true;
- }
-
- return getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
- }
-
- /*public void setUidAttributeIsDN(boolean uidAttributeIsDN)
- {
- this.uidAttributeIsDN = uidAttributeIsDN;
- }*/
-
- public String getRoleContainerDN() throws IdentityException
- {
- return getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
- }
+
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -52,83 +52,11 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPStaticRoleMembershipModuleImpl extends AbstractJBossService implements MembershipModule
+public class LDAPStaticRoleMembershipModuleImpl extends LDAPMembershipModule//extends AbstractJBossService implements MembershipModule
{
- private LDAPConnectionContext connectionContext;
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticRoleMembershipModuleImpl.class);
- private LDAPUserModuleImpl userModule;
-
- private LDAPRoleModuleImpl roleModule;
-
- private IdentityContext identityContext;
-
- private IdentityConfiguration identityConfiguration;
-
-
- //private LDAPMembershipStrategy membershipStrategy;
-
- private String jndiName;
-
- protected JNDI.Binding jndiBinding;
-
-
- /** DN under which roles should be searched. Used only when obtaining roles having only User DN. */
- /*private String roleCtxDN;*/
-
-
-
- /** Name of attribute in role entry that point to belonging user */
- //private String uidAttributeID;
-
-
- /** If the uidAttributeID in Role entry keeps full DN of a user or just a name */
- //private boolean uidAttributeIsDN;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.MEMBERSHIP_MODULE);
- }
-
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.MEMBERSHIP_MODULE);
- }
-
- }
-
public Set getRoles(User user) throws IdentityException
{
if (user == null)
@@ -248,18 +176,12 @@
memberOfName = ldapRole.getId().toString();
}
-
- //TODO: move this search to UserModule
- SearchControls controls = new SearchControls();
-
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
String filter = getMemberAttributeID().concat("=").concat(memberOfName);
log.debug("Search filter: " + filter);
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getUserContainerDN(), filter, controls);
+ //NamingEnumeration results = getConnectionContext().createInitialContext().search(getUserContainerDN(), filter, controls);
+ NamingEnumeration results = getUserModule().searchUsers(filter);
List sr = Tools.toList(results);
@@ -332,17 +254,10 @@
try
{
- //TODO:move this search to user module
- SearchControls controls = new SearchControls();
-
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
String filter = getMemberAttributeID().concat("=").concat(memberOfName);
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getUserContainerDN(), filter, controls);
+ NamingEnumeration results = getUserModule().searchUsers(filter);
List sr = Tools.toList(results);
//iterate over users that contain a role
for (Iterator iterator = sr.iterator(); iterator.hasNext();)
@@ -415,9 +330,6 @@
throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
}
-
- //TODO: handle assignemnt of 0 roles (empty set) that must remove all the existing assignments
-
try
{
log.debug("findRoles(): user = " + ldapUser.getDn());
@@ -436,7 +348,14 @@
try
{
LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
- member.add(role.getDn());
+ if (isUidAttributeIsDN())
+ {
+ member.add(role.getDn());
+ }
+ else
+ {
+ member.add(role.getId().toString());
+ }
}
catch (ClassCastException e)
{
@@ -459,124 +378,4 @@
{
throw new UnsupportedOperationException("Not yet implemented");
}
-
-
- //************************************
- //******* Getters and Setters ********
- //************************************
-
- public LDAPConnectionContext getConnectionContext() throws IdentityException
- {
-
- if (connectionContext == null)
- {
- try
- {
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context", e);
- }
- }
- return connectionContext;
- }
-
- public IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
- public LDAPUserModuleImpl getUserModule() throws IdentityException
- {
-
- if (userModule == null)
- {
- try
- {
- this.userModule = (LDAPUserModuleImpl)identityContext.getObject(IdentityContext.USER_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context - must be LDAPUserModuleImpl", e);
- }
- }
- return userModule;
- }
-
- public LDAPRoleModuleImpl getRoleModule() throws IdentityException
- {
-
- if (roleModule == null)
- {
- try
- {
- this.roleModule = (LDAPRoleModuleImpl)identityContext.getObject(IdentityContext.ROLE_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context", e);
- }
- }
- return roleModule;
- }
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public String getMemberAttributeID() throws IdentityException
- {
- String uid = getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
- if (uid == null)
- {
- return "memberOf";
- }
- return uid;
- }
-
- /*public void setUidAttributeID(String uidAttributeID)
- {
- this.uidAttributeID = uidAttributeID;
- }*/
-
- public boolean isUidAttributeIsDN() throws IdentityException
- {
- if (getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) == null)
- {
- return true;
- }
-
- return getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
- }
-
- /*public void setUidAttributeIsDN(boolean uidAttributeIsDN)
- {
- this.uidAttributeIsDN = uidAttributeIsDN;
- }*/
-
- public String getUserContainerDN() throws IdentityException
- {
- return getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
- }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -56,7 +56,7 @@
private String password;
- //private String userName;
+ private String realEmail;
private LDAPUserImpl()
{
@@ -71,7 +71,7 @@
* @param password - should contain already encrypted password from ldap
* @throws IdentityException
*/
- public LDAPUserImpl(String dn, IdentityContext context, String password) throws IdentityException
+ public LDAPUserImpl(String dn, IdentityContext context, String id, String password, String email) throws IdentityException
{
if (dn == null)
{
@@ -89,8 +89,21 @@
throw new IllegalArgumentException("Password can't be null");
}
+ if (email == null)
+ {
+ throw new IllegalArgumentException("Email can't be null");
+ }
+
+ if (id == null)
+ {
+ throw new IllegalArgumentException("Id can't be null");
+ }
+
this.identityContext = context;
this.password = password;
+ this.realEmail = email;
+ this.id = id;
+
}
public boolean getEnabled()
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -0,0 +1,330 @@
+/*
+* 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.portal.identity2.ldap;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.UserProfileModule;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.NoSuchUserException;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import java.util.NoSuchElementException;
+import java.util.Map;
+
+/**
+ * Abstract LDAPUserModule that should be extended to provide compabitibility across identity modules
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPUserModule extends AbstractJBossService implements UserModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserModule.class);
+
+ private LDAPConnectionContext connectionContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+ private String jndiName;
+
+ private IdentityContext identityContext;
+
+ private UserProfileModule userProfileModule;
+
+ private JNDI.Binding jndiBinding;
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.USER_MODULE);
+ }
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.USER_MODULE);
+ }
+ }
+
+ public LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws IdentityException
+ {
+ LDAPUserImpl ldapu = null;
+ try
+ {
+ log.debug("Search result attributes: " + attrs);
+
+
+ Attribute uida = attrs.get(getUidAttributeID());
+ if (uida == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getUidAttributeID());
+ }
+
+ Attribute passwd = attrs.get(getPasswordAttributeId());
+ if (passwd == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getPasswordAttributeId());
+ }
+
+ Attribute email = attrs.get(getEmailAttributeId());
+ if (email == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getEmailAttributeId());
+ }
+
+ ldapu = new LDAPUserImpl(dn,identityContext, uida.get().toString(), passwd.get().toString(),email.get().toString());
+
+
+ log.debug("user uid: " + ldapu.getId());
+ log.debug("user dn: " + ldapu.getDn());
+
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPUserImpl object from ldap entry (SearchResult)", e);
+ }
+
+ return ldapu;
+ }
+
+ /**
+ * method not belonging to UserModule interface - ldap specific.
+ *
+ */
+ public User findUserByDN(String dn) throws IdentityException, IllegalArgumentException, NoSuchUserException
+ {
+ try
+ {
+ log.debug("findUserByDN(): DN = " + dn);
+
+ if (dn == null)
+ {
+ throw new IdentityException("User dn canot be null");
+ }
+
+ /*SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);*/
+ //DirContext ctx = (DirContext)getConnectionContext().createInitialContext().lookup(dn);
+ Attributes attrs = getConnectionContext().createInitialContext().getAttributes(dn);
+
+ if (attrs == null)
+ {
+ throw new IdentityException("Can't find user entry with DN: " + dn);
+ }
+
+ return createUserInstance(attrs, dn);
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with dn: " + dn, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+
+ }
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow user module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper user search filter from the module
+ * @return
+ */
+ public abstract NamingEnumeration searchUsers(String filter) throws NamingException, IdentityException;
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ protected UserProfileModule getUserProfileModule() throws IdentityException
+ {
+ if (userProfileModule == null)
+ {
+ this.userProfileModule = (UserProfileModule)identityContext.getObject(IdentityContext.USER_PROFILE_MODULE);
+ }
+ return userProfileModule;
+ }
+
+ protected String getUidAttributeID() throws IdentityException
+ {
+ String uid = getIdentityConfiguration().getValue(IdentityConfiguration.USER_UID_ATTRIBUTE_ID);
+ if (uid == null)
+ {
+ return "uid";
+ }
+ return uid;
+ }
+
+ protected String getHashAlgorightm()
+ {
+ try
+ {
+ return getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
+ }
+ catch(Exception e)
+ {
+ return null;
+ }
+ }
+
+ protected String getHashEncoding() throws IdentityException
+ {
+ String enc = getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
+ if (enc == null)
+ {
+ return "hex";
+ }
+ return enc;
+ }
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ }
+ return connectionContext;
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ protected String getContainerDN() throws IdentityException
+ {
+ String cont = getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
+ if (cont == null)
+ {
+ throw new IdentityException("Configuration option missing: " + IdentityConfiguration.USER_CONTAINER_DN);
+ }
+ return cont;
+ }
+
+ protected String getPasswordAttributeId() throws IdentityException
+ {
+ String passwd = getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ATTRIBUTE_ID);
+ if (passwd == null)
+ {
+ return "userPassword";
+ }
+ else
+ {
+ return passwd;
+ }
+ }
+
+ protected String getEmailAttributeId() throws IdentityException
+ {
+ String email = getIdentityConfiguration().getValue(IdentityConfiguration.USER_EMAIL_ATTRIBUTE_ID);
+ if (email == null)
+ {
+ return "mail";
+ }
+ else
+ {
+ return email;
+ }
+ }
+
+
+ protected Map getAttributesToAdd() throws IdentityException
+ {
+ Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES + " missing in configuration");
+ }
+ return attributesToAdd;
+ }
+
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -23,15 +23,10 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.util.JNDI;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -42,7 +37,6 @@
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import java.util.List;
import java.util.NoSuchElementException;
@@ -61,74 +55,10 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPUserModuleImpl extends AbstractJBossService implements UserModule
+public class LDAPUserModuleImpl extends LDAPUserModule
{
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserModuleImpl.class);
- private LDAPConnectionContext connectionContext;
-
- private IdentityConfiguration identityConfiguration;
-
- private String jndiName;
-
- private IdentityContext identityContext;
-
- private UserProfileModule userProfileModule;
-
- /** Attribute that stores user id */
- //private String uidAttributeID;
-
- /**
- * DN of entry containing users (like ou=People,dc=example,dc=com). It's where users will be added using createUser()
- * method. Under this DN users will be searched using ONELEVEL_SCOPE
- */
- //private String containerDN;
-
- protected JNDI.Binding jndiBinding;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.USER_MODULE);
- }
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.USER_MODULE);
- }
- }
-
-
public User findUserByUserName(String userName) throws IdentityException, IllegalArgumentException, NoSuchUserException
{
try
@@ -140,15 +70,11 @@
throw new IdentityException("User name canot be null");
}
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
- String filter = getUidAttributeID().concat("=").concat(userName);
+ String filter = "(".concat(getUidAttributeID()).concat("=").concat(userName).concat(")");
log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ NamingEnumeration results = searchUsers(filter);
List sr = Tools.toList(results);
if (sr.size() > 1)
{
@@ -192,57 +118,25 @@
return findUserByUserName(id);
}
- /**
- * method not belonging to UserModule interface - ldap specific.
- *
- */
- public User findUserByDN(String dn) throws IdentityException, IllegalArgumentException, NoSuchUserException
- {
- try
- {
- log.debug("findUserByDN(): DN = " + dn);
+
- if (dn == null)
- {
- throw new IdentityException("User dn canot be null");
- }
-
- /*SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- String filter = getUidAttributeID().concat("=").concat(userName);
- log.debug("Search filter: " + filter);*/
- //DirContext ctx = (DirContext)getConnectionContext().createInitialContext().lookup(dn);
- Attributes attrs = getConnectionContext().createInitialContext().getAttributes(dn);
-
- if (attrs == null)
- {
- throw new IdentityException("Can't find user entry with DN: " + dn);
- }
-
- return createUserInstance(attrs, dn);
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No user found with dn: " + dn, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return null;
-
- }
-
public User createUser(String userName, String password, String realEmail) throws IdentityException, IllegalArgumentException
{
- //TODO:handle email parameter
+
if (userName == null)
{
throw new IdentityException("User name cannot be null");
}
+ if (realEmail == null)
+ {
+ throw new IdentityException("User email cannot be null");
+ }
+ if (password == null)
+ {
+ throw new IdentityException("User password cannot be null");
+ }
+
log.debug("Creating user: " + userName);
@@ -255,13 +149,8 @@
//extending user object from ContextDir - configure what objectClass place there
Attributes attrs = new BasicAttributes(true);
-
//create attribute using provided configuration
- Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
- if (attributesToAdd == null)
- {
- throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES + " missing in configuration");
- }
+ Map attributesToAdd = getAttributesToAdd();
//attributes
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
@@ -281,6 +170,7 @@
attrs.put(attr);
}
+ //TODO:testcase password behaviour
String algorithm = getHashAlgorightm();
if (algorithm == null)
{
@@ -291,8 +181,9 @@
attrs.put(getPasswordAttributeId(), Tools.hashAndEncodeString(password,algorithm, getHashEncoding()));
}
- attrs.put(getPasswordAttributeId(), password);
//
+ //email
+ attrs.put(getEmailAttributeId(), realEmail);
String dn = getUidAttributeID().concat("=").concat(userName);
@@ -328,7 +219,7 @@
try
{
- LdapContext ctx = (LdapContext)getConnectionContext().createInitialContext();//.lookup(getContainerDN());
+ LdapContext ctx = getConnectionContext().createInitialContext();//.lookup(getContainerDN());
log.debug("removing entry: " + ldapu.getDn());
ctx.unbind(ldapu.getDn());
}
@@ -358,17 +249,12 @@
try
{
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
//search all entries containing "uid" attribute
- String ldap_filter = getUidAttributeID().concat("=").concat(filter);
+ String ldap_filter = "(".concat(getUidAttributeID()).concat("=").concat(filter).concat(")");
log.debug("Search filter: " + filter);
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), ldap_filter, controls);
- //List sr = Tools.toList(results);
+ NamingEnumeration results = searchUsers(ldap_filter);
while (results.hasMoreElements())
{
SearchResult res = (SearchResult)results.nextElement();
@@ -376,9 +262,6 @@
String dn = ctx.getNameInNamespace();
uf.add(createUserInstance(res.getAttributes(), dn));
}
-
- //return sr.size();
-
}
catch (NoSuchElementException e)
{
@@ -396,15 +279,12 @@
{
try
{
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-
//search all entries containing "uid" attribute
- String filter = getUidAttributeID().concat("=").concat("*");
+ String filter = "(".concat(getUidAttributeID()).concat("=").concat("*").concat(")");
log.debug("Search filter: " + filter);
- NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ NamingEnumeration results = searchUsers(filter);
List sr = Tools.toList(results);
return sr.size();
@@ -422,186 +302,25 @@
}
-
-
- protected LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws IdentityException
+ /**
+ * This method should be used by over modules to perform searches. It will allow user module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper user search filter from the module
+ * @return
+ */
+ public NamingEnumeration searchUsers(String filter) throws NamingException, IdentityException
{
- LDAPUserImpl ldapu = null;
- try
- {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
+ //String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);
- /*log.debug("SearchResult: " + sr);
- Attributes attrs = sr.getAttributes();*/
- log.debug("Search result attributes: " + attrs);
-
-
- Attribute uida = attrs.get(getUidAttributeID());
- if (uida == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getUidAttributeID());
- }
-
- Attribute passwd = attrs.get(getPasswordAttributeId());
- if (passwd == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getPasswordAttributeId());
- }
-
- ldapu = new LDAPUserImpl(dn,identityContext, passwd.get().toString());
- ldapu.setId(uida.get().toString());
-
- log.debug("user uid: " + ldapu.getId());
- log.debug("user dn: " + ldapu.getDn());
-
-
- }
- catch (NamingException e)
- {
- throw new IdentityException("Couldn't create LDAPUserImpl object from ldap entry (SearchResult)", e);
- }
-
- return ldapu;
+ return getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
}
+}
- //**************************
- //*** Getter and Setters
- //**************************
- public UserProfileModule getUserProfileModule()
- {
- return userProfileModule;
- }
-
- public void setUserProfileModule(UserProfileModule userProfileModule)
- {
- this.userProfileModule = userProfileModule;
- }
-
- public String getUidAttributeID() throws IdentityException
- {
- String uid = getIdentityConfiguration().getValue(IdentityConfiguration.USER_UID_ATTRIBUTE_ID);
- if (uid == null)
- {
- return "uid";
- }
- return uid;
- }
-
- private String getHashAlgorightm()
- {
- try
- {
- return getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
- }
- catch(Exception e)
- {
- return null;
- }
- }
-
- public String getHashEncoding() throws IdentityException
- {
- String enc = getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
- if (enc == null)
- {
- return "hex";
- }
- return enc;
- }
-
- /*public void setUidAttributeID(String uidAttributeID)
- {
- this.uidAttributeID = uidAttributeID;
- }*/
-
- public LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
- }
- return connectionContext;
- }
-
- public IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
-
- /*public void setConnectionContext(LDAPConnectionContext connectionContext)
- {
- this.connectionContext = connectionContext;
- }*/
-
- public String getContainerDN() throws IdentityException
- {
- String cont = getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
- if (cont == null)
- {
- throw new IdentityException("Configuration option missing: " + IdentityConfiguration.USER_CONTAINER_DN);
- }
- return cont;
- }
-
- public String getPasswordAttributeId() throws IdentityException
- {
- String passwd = getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ATTRIBUTE_ID);
- if (passwd == null)
- {
- return "userPassword";
- }
- else
- {
- return passwd;
- }
-
- }
-
-
-
- /*public void setContainerDN(String containerDN)
- {
- this.containerDN = containerDN;
- }*/
-
- /*public String getNameAttributeID()
- {
- if (this.nameAttributeID == null)
- {
- return "cn";
- }
- return nameAttributeID;
- }
-
- public void setNameAttributeID(String nameAttributeID)
- {
- this.nameAttributeID = nameAttributeID;
- }*/
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-15 17:32:02 UTC (rev 5660)
@@ -32,6 +32,11 @@
import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.identity.ldap.LDAPTestCase;
+import java.util.Set;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.List;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
@@ -127,4 +132,52 @@
int count = roleModule.getRolesCount();
assertEquals(3, count);
}
+
+ public void testFindRolesByNames() throws Exception
+ {
+ Set roles = roleModule.findRolesByNames(new String[] {"Echo"});
+
+ assertEquals(1, roles.size());
+
+ List roleNames = new LinkedList();
+
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ roleNames.add(role.getDn());
+ }
+ assertTrue(roleNames.contains("cn=Echo,ou=Roles," + suffix));
+
+
+ //
+ roles = roleModule.findRolesByNames(new String[] {"Echo", "Echo1"});
+
+ assertEquals(2, roles.size());
+
+ roleNames = new LinkedList();
+
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ roleNames.add(role.getDn());
+ }
+ assertTrue(roleNames.contains("cn=Echo,ou=Roles," + suffix));
+ assertTrue(roleNames.contains("cn=Echo1,ou=Roles," + suffix));
+
+ //
+ roles = roleModule.findRolesByNames(new String[] {"Echo", "Echo1", "TheDuke"});
+
+ assertEquals(3, roles.size());
+
+ roleNames = new LinkedList();
+
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ roleNames.add(role.getDn());
+ }
+ assertTrue(roleNames.contains("cn=Echo,ou=Roles," + suffix));
+ assertTrue(roleNames.contains("cn=Echo1,ou=Roles," + suffix));
+ assertTrue(roleNames.contains("cn=TheDuke,ou=Roles," + suffix));
+ }
}
Modified: trunk/test/src/etc/identityconfig/opends-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-15 17:32:02 UTC (rev 5660)
@@ -68,6 +68,10 @@
<value>hex</value>
</option>
<option>
+ <name>emailAttributeID</name>
+ <value>mail</value>
+ </option>
+ <option>
<name>roleContainerDN</name>
<value>ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</value>
</option>
Modified: trunk/test/src/etc/identityconfig/rhds-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/rhds-config.xml 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/test/src/etc/identityconfig/rhds-config.xml 2006-11-15 17:32:02 UTC (rev 5660)
@@ -68,6 +68,10 @@
<value>hex</value>
</option>
<option>
+ <name>emailAttributeID</name>
+ <value>mail</value>
+ </option>
+ <option>
<name>roleContainerDN</name>
<value>ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</value>
</option>
Modified: trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif
===================================================================
--- trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif 2006-11-15 15:09:33 UTC (rev 5659)
+++ trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif 2006-11-15 17:32:02 UTC (rev 5660)
@@ -18,6 +18,7 @@
cn: Java Duke
sn: Duke
userPassword: theduke
+mail: email at email.com
dn: uid=jduke1,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
@@ -27,6 +28,7 @@
cn: Java Duke1
sn: Duke1
userPassword: theduke
+mail: email at email.com
dn: uid=jduke2,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
@@ -37,6 +39,7 @@
cn: Java Duke2
sn: Duke2
userPassword: theduke
+mail: email at email.com
dn: uid=jduke3,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
@@ -46,6 +49,7 @@
cn: Java Duke3
sn: Duke3
userPassword: theduke
+mail: email at email.com
dn: uid=jduke4,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
@@ -55,6 +59,7 @@
cn: Java Duke4
sn: Duke4
userPassword: theduke
+mail: email at email.com
dn: ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
@@ -106,6 +111,7 @@
cn: Java Duke
sn: Duke
userPassword: theduke
+mail: email at email.com
memberOf: cn=Echo,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
dn: uid=jduke1,ou=People,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
@@ -116,6 +122,7 @@
cn: Java Duke1
sn: Duke1
userPassword: theduke
+mail: email at email.com
memberOf: cn=Echo,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
memberOf: cn=Echo1,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
@@ -128,6 +135,7 @@
cn: Java Duke2
sn: Duke2
userPassword: theduke
+mail: email at email.com
memberOf: cn=Echo,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
memberOf: cn=Echo1,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
memberOf: cn=TheDuke,ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
@@ -141,6 +149,7 @@
cn: Java Duke3
sn: Duke3
userPassword: theduke
+mail: email at email.com
dn: uid=jduke4,ou=People,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
@@ -150,6 +159,7 @@
cn: Java Duke4
sn: Duke4
userPassword: theduke
+mail: email at email.com
dn: ou=Roles,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectclass: top
More information about the jboss-svn-commits
mailing list