[jboss-svn-commits] JBoss Portal SVN: r5623 - in trunk: identity/src/main/org/jboss/portal/identity identity/src/main/org/jboss/portal/identity2 identity/src/main/org/jboss/portal/identity2/ldap identity/src/main/org/jboss/portal/test/identity identity/src/main/org/jboss/portal/test/identity/ldap test/src/etc test/src/etc/ldap/ldif
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 10 19:18:36 EST 2006
Author: bdaw
Date: 2006-11-10 19:18:20 -0500 (Fri, 10 Nov 2006)
New Revision: 5623
Removed:
trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java
Modified:
trunk/identity/src/main/org/jboss/portal/identity/User.java
trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.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/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java
trunk/test/src/etc/directories.xml
trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif
Log:
- compleated base implementation of MembershipModule using ldap groups + test cases
- minor improvements to ldap RoleModule and UserModule implementations
Modified: trunk/identity/src/main/org/jboss/portal/identity/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/User.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity/User.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -57,7 +57,7 @@
String INFO_USER_VIEW_EMAIL_VIEW_REAL = "portal.user.email.view-real";
String INFO_USER_LAST_LOGIN_DATE = "portal.user.last-login-date";
- /** The user identifier. */
+ /** The user identifier. To safetly cast to String use .toString() method */
Object getId();
// User management **************************************************************************************************
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -1,46 +0,0 @@
-/******************************************************************************
- * 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;
-
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
-import org.jboss.portal.identity2.ldap.LDAPUserImpl;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface LDAPMembershipStrategy
-{
-
- public Set getRoles(LDAPUserImpl user) throws IdentityException;
-
- public Set getUsers(LDAPRoleImpl role) throws IdentityException;
-
- public void assignUsers(LDAPRoleImpl role, Set users) throws IdentityException;
-
- public void assignRoles(LDAPUserImpl user, Set roles) throws IdentityException;
-
-}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -46,16 +46,35 @@
Set getUsers(Role role) throws IdentityException;
+
+ /**
+ * Creates a relationship beetween a role and set of users. Other roles that have assotiontions with
+ * those users remain unaffected.
+ *
+ * @param role
+ * @param users
+ * @throws IdentityException
+ */
void assignUsers(Role role, Set users) throws IdentityException;
+ /**
+ * Creates a relationship beetween a user and set of roles. This operation will erase any other assotientions
+ * beetween the user and roles not specified in the provided set.
+ *
+ * @param user
+ * @param roles
+ * @throws IdentityException
+ */
void assignRoles(User user, Set roles) throws IdentityException;
/**
- * Returns role members based on rolename
+ * Returns role members based on rolename - depreciated method ethod here only for compatibility with
+ * old RoleModule interface
*
* @param roleName
* @param offset
* @param limit
+ * @deprecated
*/
Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException;
}
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-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -41,6 +41,7 @@
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;
@@ -127,6 +128,7 @@
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
String filter = getRidAttributeID().concat("=").concat(name);
log.debug("Search filter: " + filter);
@@ -139,7 +141,9 @@
throw new IdentityException("Found more than one role with id: " + name + "" +
"Posible data inconsistency");
}
- return createRoleInstance((SearchResult)sr.iterator().next());
+ SearchResult res = (SearchResult)sr.iterator().next();
+ DirContext ctx = (DirContext)res.getObject();
+ return createRoleInstance(res.getAttributes(),ctx.getNameInNamespace());
}
catch (NoSuchElementException e)
@@ -197,21 +201,14 @@
//extending user object from ContextDir - configure what objectClass place there
Attributes attrs = new BasicAttributes(true);
- /*//TODO: let admin decide what objectClass put in here (maybe as a map in mbean params)
- Attribute oc = new BasicAttribute("objectClass");
- oc.add("top");
- oc.add("groupOfNames");
- attrs.put(oc);
- //set the value for cn in case rid attribute is different
- attrs.put("cn", "");
- attrs.put("member", "");*/
-
+ //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");
}
+ //attribute
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
{
String attributeName = (String)it1.next();
@@ -219,6 +216,7 @@
Attribute attr = new BasicAttribute(attributeName);
List attributeValues = (List)attributesToAdd.get(attributeName);
+ //values
for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
{
String attrValue = (String)it2.next();
@@ -322,7 +320,8 @@
while (results.hasMoreElements())
{
SearchResult res = (SearchResult)results.nextElement();
- rf.add(createRoleInstance(res));
+ DirContext ctx = (DirContext)res.getObject();
+ rf.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
}
}
@@ -383,25 +382,22 @@
}
- protected LDAPRoleImpl createRoleInstance(SearchResult sr) throws IdentityException
+ protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws IdentityException
{
LDAPRoleImpl ldapr = null;
try
{
+ log.debug("Attributes: " + attrs);
- log.debug("SearchResult: " + sr);
-
- Attributes attrs = sr.getAttributes();
- log.debug("Search result 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(uida.getID().concat("=").concat((String)uida.get()) + "," + getContainerDN(), identityContext);
+ ldapr = new LDAPRoleImpl(dn, identityContext);
ldapr.setId((String)uida.get());
Attribute display = attrs.get(getDisplayNameAttributeID());
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-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -26,19 +26,28 @@
import org.jboss.portal.identity.User;
import org.jboss.portal.identity2.MembershipModule;
import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
import org.jboss.portal.identity2.ldap.helper.LDAPTools;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.common.util.Tools;
import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.ModificationItem;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import java.util.Set;
import java.util.HashSet;
+import java.util.List;
+import java.util.Iterator;
+import java.util.LinkedList;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
@@ -51,7 +60,7 @@
private LDAPUserModuleImpl userModule;
- private RoleModule roleModule;
+ private LDAPRoleModuleImpl roleModule;
private IdentityContext identityContext;
@@ -139,8 +148,55 @@
throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
}
- throw new UnsupportedOperationException("Not yet implemented");
+ Set roles = new HashSet();
+ try
+ {
+ log.debug("getRoles(): user DN = " + ldapUser.getDn());
+
+ String memberName = "";
+
+ if (isUidAttributeIsDN())
+ {
+ memberName = ldapUser.getDn();
+ }
+ else
+ {
+ memberName = ldapUser.getId().toString();
+ }
+
+
+
+ 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);
+ List sr = Tools.toList(results);
+
+
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ roles.add(getRoleModule().createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+
+
+
+ }
+ catch (Exception e)
+ {
+ log.debug("Failed to resolve userRoles: " + ldapUser.getId().toString(), e);
+ }
+
+ return roles;
+
}
public Set getUsers(Role role) throws IdentityException
@@ -237,7 +293,48 @@
throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPRoleImpl objects");
}
- throw new UnsupportedOperationException("Not yet implemented");
+
+
+ if (users.size() == 0)
+ {
+ throw new IdentityException("Cannot assigne 0 users to a role using this membership strategy (because some LDAPs " +
+ "require the member field to be set). ");
+ }
+
+ try
+ {
+ log.debug("findUsers(): role = " + ldapRole.getDn());
+
+ if (ldapRole.getName() == null)
+ {
+ throw new IdentityException("Role name canot be null");
+ }
+
+ //construct new member attribute values
+ Attributes attrs = new BasicAttributes(true);
+
+ Attribute member = new BasicAttribute(getMemberAttributeID());
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ member.add(user.getDn());
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPUserImpl objects", e);
+ }
+ }
+ attrs.put(member);
+
+ getConnectionContext().createInitialContext().modifyAttributes(ldapRole.getDn(), DirContext.REPLACE_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to change Role members", e);
+ }
+
}
public void assignRoles(User user, Set roles) throws IdentityException
@@ -258,7 +355,109 @@
throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
}
+ //First build a list of roles DNs to add
+ List roleDNsToAdd = new LinkedList();
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ roleDNsToAdd.add(role.getDn());
+ }
+ catch(ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPRoleImpl objects", e);
+ }
+ }
+
+ String memberName=null;
+
+ //Find all the roles that currently contain user as member (need to remove user from some of them)
+ if (isUidAttributeIsDN())
+ {
+ memberName = ldapUser.getDn();
+ }
+ else
+ {
+ memberName = ldapUser.getId().toString();
+ }
+
+
+ try
+ {
+ 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);
+ List sr = Tools.toList(results);
+ //iterate over roles that contain a user
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ String roleDN = ctx.getNameInNamespace();
+ //if role is one which we want to add
+ if (roleDNsToAdd.contains(roleDN))
+ {
+ //we do nothing but mark this role as added
+ roleDNsToAdd.remove(roleDN);
+ continue;
+ }
+ //if it's not on the list we need to remove user from it
+ else
+ {
+ Attribute attr = res.getAttributes().get(getMemberAttributeID());
+
+ //can't remove the last member (if the attribute is required by schema)
+ //TODO: workaround this somehow.... (adding goofy user or admin instead?)
+ if (attr.size() != 1)
+ {
+ //remove user name from the member list
+ attr.remove(memberName);
+
+ //and replace attributes
+ Attributes newAttrs = new BasicAttributes(true);
+ newAttrs.put(getMemberAttributeID(), attr);
+ getConnectionContext().createInitialContext().modifyAttributes(roleDN, DirContext.REPLACE_ATTRIBUTE, newAttrs);
+ }
+ else
+ {
+ log.error("Couldn't remove user from role as it was the last member - possibly required field in ldap");
+ }
+
+ //and mark this role as done
+ roleDNsToAdd.remove(roleDN);
+ }
+ }
+
+ //now iterate over roles that left to process
+ for (Iterator iterator = roleDNsToAdd.iterator(); iterator.hasNext();)
+ {
+ String roleDN = (String)iterator.next();
+
+ //changes to make
+ ModificationItem[] mods = new ModificationItem[1];
+ mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+ new BasicAttribute(getMemberAttributeID(), memberName));
+ // Perform the requested modifications on the named object
+ getConnectionContext().createInitialContext().modifyAttributes(roleDN, mods);
+ }
+
+ //and that should be all...
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+
throw new UnsupportedOperationException("Not yet implemented");
}
@@ -316,14 +515,14 @@
return userModule;
}
- public RoleModule getRoleModule() throws IdentityException
+ public LDAPRoleModuleImpl getRoleModule() throws IdentityException
{
if (roleModule == null)
{
try
{
- this.roleModule = (RoleModule)identityContext.getObject(IdentityContext.ROLE_MODULE);
+ this.roleModule = (LDAPRoleModuleImpl)identityContext.getObject(IdentityContext.ROLE_MODULE);
}
catch (ClassCastException e)
{
@@ -374,11 +573,17 @@
{
return true;
}
- return Boolean.getBoolean(getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_UID_ATTRIBUTE_IS_DN));
+
+ return getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_UID_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/LDAPUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -35,6 +35,7 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.Context;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
@@ -140,6 +141,7 @@
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
String filter = getUidAttributeID().concat("=").concat(userName);
log.debug("Search filter: " + filter);
@@ -152,7 +154,10 @@
throw new IdentityException("Found more than one user with id: " + userName + "" +
"Posible data inconsistency");
}
- return createUserInstance(((SearchResult)sr.iterator().next()).getAttributes());
+ SearchResult res = (SearchResult)sr.iterator().next();
+ Context ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ return createUserInstance(res.getAttributes(), dn);
}
catch (NoSuchElementException e)
@@ -206,6 +211,7 @@
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)
@@ -213,7 +219,7 @@
throw new IdentityException("Can't find user entry with DN: " + dn);
}
- return createUserInstance(attrs);
+ return createUserInstance(attrs, dn);
}
catch (NoSuchElementException e)
@@ -248,22 +254,15 @@
//extending user object from ContextDir - configure what objectClass place there
Attributes attrs = new BasicAttributes(true);
- /*//TODO: let admin decide what objectClass put in here (maybe as a map in mbean params)
- Attribute oc = new BasicAttribute("objectClass");
- oc.add("top");
- oc.add("uidObject");
- oc.add("person");
- attrs.put(oc);
- attrs.put(getUidAttributeID(), userName);
- attrs.put("sn", " ");
- attrs.put("cn", " ");*/
+ //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");
}
+ //attributes
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
{
String attributeName = (String)it1.next();
@@ -271,6 +270,7 @@
Attribute attr = new BasicAttribute(attributeName);
List attributeValues = (List)attributesToAdd.get(attributeName);
+ //values
for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
{
String attrValue = (String)it2.next();
@@ -336,6 +336,7 @@
}
//TODO:implement something to use offset and limit - sort asc and
+ //TODO: and testcase this...
public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws IdentityException, IllegalArgumentException
{
log.info("Current implementation of findUsersFilteredByUserName returns all users and is not \"offset\" and \"limit\" sensitive ");
@@ -346,6 +347,7 @@
{
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);
@@ -357,7 +359,9 @@
while (results.hasMoreElements())
{
SearchResult res = (SearchResult)results.nextElement();
- uf.add(createUserInstance(res.getAttributes()));
+ Context ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ uf.add(createUserInstance(res.getAttributes(), dn));
}
//return sr.size();
@@ -407,7 +411,7 @@
- protected LDAPUserImpl createUserInstance(Attributes attrs) throws IdentityException
+ protected LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws IdentityException
{
LDAPUserImpl ldapu = null;
try
@@ -425,7 +429,8 @@
{
throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getUidAttributeID());
}
- ldapu = new LDAPUserImpl(uida.getID().concat("=").concat((String)uida.get()) + "," + getContainerDN(),identityContext);
+ //ldapu = new LDAPUserImpl(uida.getID().concat("=").concat((String)uida.get()) + "," + getContainerDN(),identityContext);
+ ldapu = new LDAPUserImpl(dn,identityContext);
ldapu.setId((String)uida.get());
//TODO:handle password
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -23,7 +23,6 @@
package org.jboss.portal.test.identity;
import junit.framework.Assert;
-import org.jboss.portal.identity2.LDAPMembershipStrategy;
import org.jboss.portal.identity2.MembershipModule;
import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.identity.UserModule;
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-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -47,6 +47,8 @@
RoleModule roleModule;
+ private String suffix;
+
public void setUp() throws Exception
{
runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
@@ -72,6 +74,8 @@
roleModule.start();
this.roleModule = roleModule;
+ suffix = getDirectoryServerConfigParameter().getCleanUpDN();
+
super.setUp();
}
@@ -84,14 +88,14 @@
public void testFindRoleByName() throws Exception
{
LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + suffix);
assertEquals(ldapr.getName(), "Echo");
}
public void testRemoveRole() throws Exception
{
LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + suffix);
assertEquals(ldapr.getName(), "Echo");
roleModule.removeRole("Echo");
ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
@@ -117,10 +121,10 @@
public void testgetRoleCount() throws Exception
{
LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + suffix);
assertEquals(ldapr.getName(), "Echo");
int count = roleModule.getRolesCount();
- assertEquals(2, count);
+ assertEquals(3, count);
}
}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -48,6 +48,8 @@
UserModule userModule;
+ private String suffix;
+
public void setUp() throws Exception
{
System.out.println("#########################");
@@ -76,6 +78,8 @@
userModule.start();
this.userModule = userModule;
+ suffix = getDirectoryServerConfigParameter().getCleanUpDN();
+
super.setUp();
}
@@ -88,7 +92,7 @@
public void testFindUserByName() throws Exception
{
LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + suffix);
assertEquals(ldapu.getUserName(), "jduke");
}
@@ -96,7 +100,7 @@
{
LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
assertNotNull(ldapu);
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + suffix);
userModule.removeUser("jduke");
ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
assertNull(ldapu);
@@ -120,7 +124,7 @@
public void testgetUserCount() throws Exception
{
LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + suffix);
assertEquals(ldapu.getUserName(), "jduke");
int count = userModule.getUserCount();
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-11 00:18:20 UTC (rev 5623)
@@ -34,13 +34,19 @@
import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
import org.jboss.portal.identity2.ldap.LDAPStaticGroupMembershipModuleImpl;
import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
+import org.jboss.portal.identity2.ldap.LDAPUserImpl;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.common.util.Tools;
import java.util.Set;
import java.util.Iterator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.LinkedList;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
@@ -62,6 +68,8 @@
private MembershipModule membershipModule;
+ private String suffix;
+
public void setUp() throws Exception
{
runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
@@ -109,23 +117,115 @@
mstc.setUserModule(userModule);
mstc.setRoleModule(roleModule);
+ suffix = getDirectoryServerConfigParameter().getCleanUpDN();
+
super.setUp();
}
-
+ //TODO:extend this
public void testGetUsers() throws Exception
{
LDAPRoleImpl role = (LDAPRoleImpl)roleModule.findRoleByName("Echo");
Set users = membershipModule.getUsers(role);
assertEquals(3, users.size());
+ List names = new LinkedList();
+
for (Iterator iterator = users.iterator(); iterator.hasNext();)
{
- User user = (User)iterator.next();
- log.info("####################3User: " + user.getUserName());
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ names.add(user.getDn());
+ }
+ assertTrue(names.contains("uid=jduke1,ou=People," + suffix));
+ assertTrue(names.contains("uid=jduke3,ou=People," + suffix));
+ assertTrue(names.contains("uid=jduke4,ou=People," + suffix));
+ }
+ //TODO:extend this
+ public void testGetRoles() throws Exception
+ {
+ LDAPUserImpl user = (LDAPUserImpl)userModule.findUserByUserName("jduke1");
+ Set roles = membershipModule.getRoles(user);
+ 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));
+ user = (LDAPUserImpl)userModule.findUserByUserName("jduke3");
+ roles = membershipModule.getRoles(user);
+ 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));
+
}
+
+
+ //TODO:extend this
+ public void testAssignRoles() throws Exception
+ {
+ Set users = new HashSet();
+ users.add((LDAPUserImpl)userModule.findUserByUserName("jduke1"));
+ users.add((LDAPUserImpl)userModule.findUserByUserName("jduke4"));
+ LDAPRoleImpl role = (LDAPRoleImpl)roleModule.findRoleByName("Echo1");
+ membershipModule.assignUsers(role,users);
+
+ users = membershipModule.getUsers(role);
+
+ assertEquals(2, users.size());
+
+ List names = new LinkedList();
+
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ names.add(user.getDn());
+ }
+
+ assertTrue(names.contains("uid=jduke1,ou=People," + suffix));
+ assertTrue(names.contains("uid=jduke4,ou=People," + suffix));
+ }
+
+
+ //TODO:extend this
+ public void testAssignUsers() throws Exception
+ {
+ Set users = new HashSet();
+ users.add((LDAPUserImpl)userModule.findUserByUserName("jduke1"));
+ users.add((LDAPUserImpl)userModule.findUserByUserName("jduke4"));
+ LDAPRoleImpl role = (LDAPRoleImpl)roleModule.findRoleByName("Echo1");
+ membershipModule.assignUsers(role,users);
+
+ users = membershipModule.getUsers(role);
+
+ assertEquals(2, users.size());
+
+ List names = new LinkedList();
+
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ names.add(user.getDn());
+ }
+
+ assertTrue(names.contains("uid=jduke1,ou=People," + suffix));
+ assertTrue(names.contains("uid=jduke4,ou=People," + suffix));
+ }
+
+
+
}
Modified: trunk/test/src/etc/directories.xml
===================================================================
--- trunk/test/src/etc/directories.xml 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/test/src/etc/directories.xml 2006-11-11 00:18:20 UTC (rev 5623)
@@ -40,16 +40,16 @@
<directory>
<name>RedHatDS</name>
<description>RedHat Directory in QA Labs (need vpn access)</description>
- <!--identity configuration file-->
+
<config-file>identityconfig/rhds-config.xml</config-file>
<host>dev39.qa.atl.jboss.com</host>
<port>10389</port>
<context-factory>com.sun.jndi.ldap.LdapCtxFactory</context-factory>
<admin-dn>cn=Directory Manager</admin-dn>
<admin-password>qpq123qpq</admin-password>
- <!--ldif from which LDAP will be populated before each test-->
+
<populate-ldif>ldap/ldif/initial-tests-qa.ldif</populate-ldif>
- <!--DN that will be removed to perform cleanup after each test-->
+
<cleanup-dn>dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</cleanup-dn>
</directory>
</directories>
Modified: trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif
===================================================================
--- trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif 2006-11-10 15:54:54 UTC (rev 5622)
+++ trunk/test/src/etc/ldap/ldif/initial-tests-qa.ldif 2006-11-11 00:18:20 UTC (rev 5623)
@@ -70,6 +70,15 @@
member: uid=jduke3,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
member: uid=jduke4,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
+dn: cn=Echo1,ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
+objectClass: top
+objectClass: groupOfNames
+cn: Echo1
+description: the JBossAdmin group 2
+member: uid=jduke2,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
+member: uid=jduke3,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
+member: uid=jduke5,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
+
dn: cn=TheDuke,ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com
objectClass: groupOfNames
objectClass: top
More information about the jboss-svn-commits
mailing list