[jboss-svn-commits] JBoss Portal SVN: r5335 - in trunk: build/ide/intellij/idea50/modules/migration build/ide/intellij/idea50/modules/thirdparty 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/resources/portal-identity-test-jar/org/jboss/portal/test/identity test/src/main/org/jboss/portal/test/framework/embedded
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 5 18:34:52 EDT 2006
Author: bdaw
Date: 2006-10-05 18:34:30 -0400 (Thu, 05 Oct 2006)
New Revision: 5335
Added:
trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticGroupLDAPMembershipStrategyImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticRoleLDAPMembershipStrategyImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipStrategyTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupStrategyTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticRoleStrategyTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
Modified:
trunk/build/ide/intellij/idea50/modules/migration/migration.iml
trunk/build/ide/intellij/idea50/modules/thirdparty/thirdparty.iml
trunk/identity/build.xml
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModuleImpl.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/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
Log:
- additionall stuff for LDAP support implementation
- some identity test improvements
Modified: trunk/build/ide/intellij/idea50/modules/migration/migration.iml
===================================================================
--- trunk/build/ide/intellij/idea50/modules/migration/migration.iml 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/build/ide/intellij/idea50/modules/migration/migration.iml 2006-10-05 22:34:30 UTC (rev 5335)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
- <component name="NewModuleRootManager">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../../../../../migration/output/idea50/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../../../../../migration">
Modified: trunk/build/ide/intellij/idea50/modules/thirdparty/thirdparty.iml
===================================================================
--- trunk/build/ide/intellij/idea50/modules/thirdparty/thirdparty.iml 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/build/ide/intellij/idea50/modules/thirdparty/thirdparty.iml 2006-10-05 22:34:30 UTC (rev 5335)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
- <component name="NewModuleRootManager">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../../../../../thirdparty/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$" />
Modified: trunk/identity/build.xml
===================================================================
--- trunk/identity/build.xml 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/build.xml 2006-10-05 22:34:30 UTC (rev 5335)
@@ -200,7 +200,8 @@
<execute-tests>
<x-test>
<test todir="${test.reports}" name="org.jboss.portal.test.identity.DBUserTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPUserTestCase"/>
+ <!--<test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticRoleStrategyTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupStrategyTestCase"/>-->
</x-test>
<x-classpath>
<pathelement location="${build.lib}/portal-identity-lib.jar"/>
Added: trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/LDAPMembershipStrategy.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,45 @@
+/*
+* 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.LDAPUserImpl;
+import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
+
+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;
+
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,186 @@
+/*
+* 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 javax.naming.InitialContext;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.directory.InitialDirContext;
+import java.util.Hashtable;
+
+/**
+ * Keeps configuration of connection to LDAP server
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPConnectionContext extends AbstractJBossService
+{
+
+
+ private String name;
+
+ private String providerUrl;
+
+ private String contextFactory;
+
+ private String adminDN;
+
+ private String adminPassword;
+
+ private String protocol;
+
+ private String authentication = "simple";
+
+ public LDAPConnectionContext(String name,
+ String url,
+ String context,
+ String admin,
+ String password,
+ String protocol,
+ String authentication)
+ {
+ this.name = name;
+ this.providerUrl = url;
+ this.contextFactory = context;
+ this.adminDN = admin;
+ this.adminPassword = password;
+ this.protocol = protocol;
+ this.authentication = authentication;
+ }
+
+
+ public InitialLdapContext createInitialContext()
+ {
+ try
+ {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, this.getContextFactory());
+ env.put(Context.PROVIDER_URL, this.getProviderUrl());
+ env.put(Context.SECURITY_AUTHENTICATION, this.getAuthentication());
+ env.put(Context.SECURITY_PRINCIPAL, this.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, this.getAdminPassword());
+ return new InitialLdapContext(env, null);
+ }
+ catch (NamingException e)
+ {
+ log.info("Unable to create InitialLdapContext using: " + this, e);
+ return null;
+ }
+ }
+
+
+
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer();
+ str.append("Name: " + this.name)
+ .append(", Provider URL: " + this.providerUrl)
+ .append(", Context factory: " + this.contextFactory)
+ .append(", Admin user: " + this.adminDN)
+ .append(", Admin password: " + this.adminPassword)
+ .append(", Authentication: " + this.authentication);
+ return str.toString();
+ }
+
+
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getProviderUrl()
+ {
+ return providerUrl;
+ }
+
+ public void setProviderUrl(String providerUrl)
+ {
+ this.providerUrl = providerUrl;
+ }
+
+ public String getContextFactory()
+ {
+ return contextFactory;
+ }
+
+ public void setContextFactory(String contextFactory)
+ {
+ this.contextFactory = contextFactory;
+ }
+
+ public String getAdminDN()
+ {
+ return adminDN;
+ }
+
+ public void setAdminDN(String adminDN)
+ {
+ this.adminDN = adminDN;
+ }
+
+ public String getAdminPassword()
+ {
+ return adminPassword;
+ }
+
+ public void setAdminPassword(String adminPassword)
+ {
+ this.adminPassword = adminPassword;
+ }
+
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ public void setProtocol(String protocol)
+ {
+ this.protocol = protocol;
+ }
+
+ public String getAuthentication()
+ {
+ return authentication;
+ }
+
+ public void setAuthentication(String authentication)
+ {
+ this.authentication = authentication;
+ }
+
+
+
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -24,6 +24,7 @@
import org.jboss.portal.identity2.RoleModule;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
@@ -31,8 +32,9 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPExtRoleModuleImpl implements RoleModule
+public class LDAPExtRoleModuleImpl extends LDAPRoleModuleImpl
{
+
public Role findRoleByName(String name) throws IdentityException, IllegalArgumentException
{
throw new UnsupportedOperationException("Not yet implemented");
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -25,6 +25,7 @@
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
@@ -32,8 +33,9 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPExtUserModuleImpl implements UserModule
+public class LDAPExtUserModuleImpl extends LDAPUserModuleImpl
{
+
public User findUserByUserName(String userName) throws IdentityException, IllegalArgumentException, NoSuchUserException
{
throw new UnsupportedOperationException("Not yet implemented");
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -23,8 +23,10 @@
import org.jboss.portal.identity2.MembershipModule;
import org.jboss.portal.identity2.Role;
+import org.jboss.portal.identity2.LDAPMembershipStrategy;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
@@ -32,31 +34,125 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPMembershipModuleImpl implements MembershipModule
+public class LDAPMembershipModuleImpl extends AbstractJBossService implements MembershipModule
{
+ private LDAPConnectionContext connectionContext;
+
+ private LDAPMembershipStrategy membershipStrategy;
+
public Set getRoles(User user) throws IdentityException
{
- throw new UnsupportedOperationException("Not yet implemented");
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
+ }
+
+ return membershipStrategy.getRoles(ldapUser);
+
}
public Set getUsers(Role role) throws IdentityException
{
- throw new UnsupportedOperationException("Not yet implemented");
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPRoleImpl objects");
+ }
+
+ return membershipStrategy.getUsers(ldapRole);
}
public void assignUsers(Role role, Set users) throws IdentityException
{
- throw new UnsupportedOperationException("Not yet implemented");
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPRoleImpl objects");
+ }
+
+ membershipStrategy.assignUsers(ldapRole, users);
}
public void assignRoles(User user, Set roles) throws IdentityException
{
- throw new UnsupportedOperationException("Not yet implemented");
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only LDAPUserImpl objects");
+ }
+
+ membershipStrategy.assignRoles(ldapUser, roles);
}
+ //TODO:don't forget to add this....
public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
{
throw new UnsupportedOperationException("Not yet implemented");
}
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+ public LDAPMembershipStrategy getMembershipStrategy()
+ {
+ return membershipStrategy;
+ }
+
+ public void setMembershipStrategy(LDAPMembershipStrategy membershipStrategy)
+ {
+ this.membershipStrategy = membershipStrategy;
+ }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -31,11 +31,23 @@
*/
public class LDAPRoleImpl implements Role
{
- public Object getId()
+
+ private String dn;
+
+ private String id;
+
+ private LDAPRoleImpl()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+
}
+ public LDAPRoleImpl(String dn)
+ {
+ this.dn = dn;
+ }
+
+
+
public String getName()
{
return null; //To change body of implemented methods use File | Settings | File Templates.
@@ -55,4 +67,23 @@
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+ public String getDn()
+ {
+ return dn;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -24,16 +24,23 @@
import org.jboss.portal.identity2.RoleModule;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.Attributes;
+import javax.naming.NamingException;
import java.util.Set;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPRoleModuleImpl implements RoleModule
+public class LDAPRoleModuleImpl extends AbstractJBossService implements RoleModule
{
+ private LDAPConnectionContext connectionContext;
+ private String idAttributeName;
+
public Role findRoleByName(String name) throws IdentityException, IllegalArgumentException
{
throw new UnsupportedOperationException("Not yet implemented");
@@ -73,4 +80,53 @@
{
throw new UnsupportedOperationException("Not yet implemented");
}
+
+
+ protected LDAPRoleImpl createUserInstance(SearchResult sr) throws IdentityException
+ {
+ LDAPRoleImpl ldapr = null;
+ try {
+
+
+ Attributes attrs = sr.getAttributes();
+ String dn = (String)attrs.get("dn").get();
+ ldapr = new LDAPRoleImpl(dn);
+ if (idAttributeName != null)
+ {
+ String uid = (String)attrs.get(idAttributeName).get();
+ ldapr.setId(uid);
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPRoleImpl object from ldap entry", e);
+ }
+
+ return ldapr;
+ }
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ public String getIdAttributeName()
+ {
+ return idAttributeName;
+ }
+
+ public void setIdAttributeName(String idAttributeName)
+ {
+ this.idAttributeName = idAttributeName;
+ }
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -22,7 +22,9 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.UserProfileModule;
import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.identity.IdentityException;
import java.util.Date;
import java.util.Locale;
@@ -33,11 +35,27 @@
*/
public class LDAPUserImpl implements User
{
- public Object getId()
+
+ private UserProfileModule userProfileModule;
+
+ private String dn;
+
+ private String id;
+
+ private LDAPUserImpl()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+
}
+ public LDAPUserImpl(String dn) throws IdentityException
+ {
+ if (dn == null)
+ {
+ throw new IdentityException("Cannot create LDAPUserImpl without DN");
+ }
+ this.dn = dn;
+ }
+
public boolean getEnabled()
{
return false; //To change body of implemented methods use File | Settings | File Templates.
@@ -162,4 +180,26 @@
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ public String getDn()
+ {
+ return dn;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+
+ public Object getId()
+ {
+ return id;
+ }
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -22,10 +22,15 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.identity2.UserModule;
+import org.jboss.portal.identity2.UserProfileModule;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
import java.util.Set;
/**
@@ -34,6 +39,15 @@
*/
public class LDAPUserModuleImpl implements UserModule
{
+
+ private LDAPConnectionContext connectionContext;
+
+ private UserProfileModule userProfileModule;
+
+ private String idAttributeName;
+
+
+
public User findUserByUserName(String userName) throws IdentityException, IllegalArgumentException, NoSuchUserException
{
throw new UnsupportedOperationException("Not yet implemented");
@@ -73,4 +87,65 @@
{
throw new UnsupportedOperationException("Not yet implemented");
}
+
+
+ protected LDAPUserImpl createUserInstance(SearchResult sr) throws IdentityException
+ {
+ LDAPUserImpl ldapu = null;
+ try {
+
+
+ Attributes attrs = sr.getAttributes();
+ String dn = (String)attrs.get("dn").get();
+ ldapu = new LDAPUserImpl(dn);
+ if (idAttributeName != null)
+ {
+ String uid = (String)attrs.get(idAttributeName).get();
+ ldapu.setId(uid);
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPUserImpl object from ldap entry", e);
+ }
+
+ return ldapu;
+ }
+
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ public UserProfileModule getUserProfileModule()
+ {
+ return userProfileModule;
+ }
+
+ public void setUserProfileModule(UserProfileModule userProfileModule)
+ {
+ this.userProfileModule = userProfileModule;
+ }
+
+ public String getIdAttributeName()
+ {
+ return idAttributeName;
+ }
+
+ public void setIdAttributeName(String idAttributeName)
+ {
+ this.idAttributeName = idAttributeName;
+ }
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -23,6 +23,7 @@
import org.jboss.portal.identity2.UserProfileModule;
import org.jboss.portal.identity2.User;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
@@ -30,9 +31,21 @@
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class LDAPUserProfileModuleImpl implements UserProfileModule
+public class LDAPUserProfileModuleImpl extends AbstractJBossService implements UserProfileModule
{
+ private LDAPConnectionContext connectionContext;
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+
public String getProperty(User user, String propertyName)
{
if (user == null)
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticGroupLDAPMembershipStrategyImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticGroupLDAPMembershipStrategyImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticGroupLDAPMembershipStrategyImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,100 @@
+/*
+* 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.LDAPMembershipStrategy;
+import org.jboss.portal.identity.IdentityException;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class StaticGroupLDAPMembershipStrategyImpl extends AbstractJBossService implements LDAPMembershipStrategy
+{
+ private LDAPConnectionContext connectionContext;
+
+
+ /**
+ * 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;
+
+
+ public Set getRoles(LDAPUserImpl user) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Set getUsers(LDAPRoleImpl role) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public void assignUsers(LDAPRoleImpl role, Set users) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public void assignRoles(LDAPUserImpl user, Set roles) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+ public String getRoleCtxDN()
+ {
+ return roleCtxDN;
+ }
+
+ public void setRoleCtxDN(String roleCtxDN)
+ {
+ this.roleCtxDN = roleCtxDN;
+ }
+
+ public String getUidAttributeID()
+ {
+ return uidAttributeID;
+ }
+
+ public void setUidAttributeID(String uidAttributeID)
+ {
+ this.uidAttributeID = uidAttributeID;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticRoleLDAPMembershipStrategyImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticRoleLDAPMembershipStrategyImpl.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/StaticRoleLDAPMembershipStrategyImpl.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,99 @@
+/*
+* 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.LDAPMembershipStrategy;
+import org.jboss.portal.identity.IdentityException;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class StaticRoleLDAPMembershipStrategyImpl extends AbstractJBossService implements LDAPMembershipStrategy
+{
+ private LDAPConnectionContext connectionContext;
+
+ /**
+ * DN under which users should be searched. Used only when obtaining users having only Role DN.
+ */
+ private String userCtxDN;
+
+ /**
+ * Name of attribute in role entry that point to belonging user
+ */
+ private String roleAttributeID;
+
+
+ public Set getRoles(LDAPUserImpl user) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Set getUsers(LDAPRoleImpl role) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public void assignUsers(LDAPRoleImpl role, Set users) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public void assignRoles(LDAPUserImpl user, Set roles) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+ public String getUserCtxDN()
+ {
+ return userCtxDN;
+ }
+
+ public void setUserCtxDN(String userCtxDN)
+ {
+ this.userCtxDN = userCtxDN;
+ }
+
+ public String getRoleAttributeID()
+ {
+ return roleAttributeID;
+ }
+
+ public void setRoleAttributeID(String roleAttributeID)
+ {
+ this.roleAttributeID = roleAttributeID;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipStrategyTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipStrategyTestCase.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipStrategyTestCase.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,61 @@
+/*
+* 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.test.identity;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPMembershipStrategyTestCase extends LDAPTestCase
+{
+ public LDAPMembershipStrategyTestCase(Map parametrization)
+ {
+ super(parametrization);
+ }
+
+ /** . */
+ protected MembershipStrategyTest mstc;
+
+
+ protected void setUp() throws Exception
+ {
+ //mstc = new MembershipStrategyTest();
+ super.setUp();
+ }
+
+ public void testFirstSimple() throws Exception
+ {
+ mstc.testFirstSimple();
+ }
+
+ public void testSecondSimple() throws Exception
+ {
+ mstc.testSecondSimple();
+ }
+
+ public void testThirdSimple() throws Exception
+ {
+ mstc.testThirdSimple();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupStrategyTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupStrategyTestCase.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupStrategyTestCase.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,74 @@
+/*
+* 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.test.identity;
+
+import junit.framework.TestSuite;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.jboss.portal.common.junit.metadata.TestCaseMetaData;
+import org.jboss.portal.common.junit.metadata.TestCaseParameterMetaData;
+import org.jboss.portal.common.junit.TestCaseFactory;
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity2.ldap.StaticGroupLDAPMembershipStrategyImpl;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPStaticGroupStrategyTestCase extends LDAPMembershipStrategyTestCase
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticGroupStrategyTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
+ TestCaseMetaData testCaseMD = new TestCaseMetaData();
+ testCaseMD.bindParameter(new TestCaseParameterMetaData("DirectoryServerConfig"), DSConfig.fromXML2(configsURL));
+ TestSuite suite = TestCaseFactory.create(testCaseMD, LDAPStaticGroupStrategyTestCase.class);
+ return suite;
+ }
+
+ public LDAPStaticGroupStrategyTestCase(Map parametrization)
+ {
+ super(parametrization);
+ }
+
+ protected void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+
+ StaticGroupLDAPMembershipStrategyImpl strategy = new StaticGroupLDAPMembershipStrategyImpl();
+ strategy.setConnectionContext(createConnectionContext());
+
+ mstc = new MembershipStrategyTest();
+ mstc.setContext(this);
+ mstc.setLDAPMembershipStrategy(strategy);
+
+
+ super.setUp();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticRoleStrategyTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticRoleStrategyTestCase.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticRoleStrategyTestCase.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,75 @@
+/*
+* 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.test.identity;
+
+import org.jboss.portal.common.junit.metadata.TestCaseMetaData;
+import org.jboss.portal.common.junit.metadata.TestCaseParameterMetaData;
+import org.jboss.portal.common.junit.TestCaseFactory;
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity2.ldap.StaticGroupLDAPMembershipStrategyImpl;
+import org.jboss.portal.identity2.ldap.StaticRoleLDAPMembershipStrategyImpl;
+
+import junit.framework.TestSuite;
+
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPStaticRoleStrategyTestCase extends LDAPMembershipStrategyTestCase
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticRoleStrategyTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
+ TestCaseMetaData testCaseMD = new TestCaseMetaData();
+ testCaseMD.bindParameter(new TestCaseParameterMetaData("DirectoryServerConfig"), DSConfig.fromXML2(configsURL));
+ TestSuite suite = TestCaseFactory.create(testCaseMD, LDAPStaticRoleStrategyTestCase.class);
+ return suite;
+ }
+
+ public LDAPStaticRoleStrategyTestCase(Map parametrization)
+ {
+ super(parametrization);
+ }
+
+ protected void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+
+ StaticRoleLDAPMembershipStrategyImpl strategy = new StaticRoleLDAPMembershipStrategyImpl();
+ strategy.setConnectionContext(createConnectionContext());
+
+ mstc = new MembershipStrategyTest();
+ mstc.setContext(this);
+ mstc.setLDAPMembershipStrategy(strategy);
+
+
+ super.setUp();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,193 @@
+/*
+* 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.test.identity;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.Binding;
+import javax.naming.Context;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss dot com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 5247 $
+ */
+public abstract class LDAPTestCase extends junit.framework.TestCase implements MembershipStrategyTest.Context
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPTestCase.class);
+
+ static
+ {
+ Appender appender = new ConsoleAppender(new SimpleLayout());
+ Logger.getRoot().addAppender(appender);
+ Logger.getRoot().setLevel(Level.INFO);
+ }
+
+ public LDAPTestCase()
+ {
+
+ }
+
+ public LDAPTestCase(Map parametrization)
+ {
+ dsConfig = (DSConfig)parametrization.get("DirectoryServerConfig");
+ }
+
+ public LDAPTestCase(DSConfig dsConfig)
+ {
+ this.dsConfig = dsConfig;
+ }
+
+ protected TestRuntimeContext runtimeContext;
+
+ private DSConfig dsConfig;
+
+
+
+ public String getName()
+ {
+ return super.getName() + "," + dsConfig.getName() + "," + dsConfig.getDescription();
+ }
+
+ protected void setUp() throws Exception
+ {
+ runtimeContext.start();
+
+
+ populate();
+ }
+
+ protected void tearDown() throws Exception
+ {
+
+ //on exit remove dc=jboss,dc=org
+ cleanUp();
+
+ runtimeContext.stop();
+ }
+
+
+ public void begin()
+ {
+
+ }
+
+
+ public void commit()
+ {
+
+
+ }
+
+ protected void populate()
+ {
+ try
+ {
+ //on start load the content into ldap
+
+ DirContext ctx = getDirContext();
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+
+ URL ldif = tcl.getResource("ldap/ldif/example1.ldif");
+ log.info("ldif to load by loader: " + ldif.getPath());
+
+ LdifFileLoader loader = new LdifFileLoader(ctx, ldif.getPath());
+ loader.execute();
+ }
+ catch (Exception e)
+ {
+ log.info("fail to import initial ldif for tests", e);
+ }
+ }
+
+ protected void cleanUp()
+ {
+ try
+ {
+ DirContext ctx = getDirContext();
+ DirContext org = (DirContext)ctx.lookup("dc=org");
+ removeContext(org, "dc=jboss");
+ }
+ catch (Exception e)
+ {
+ log.info("fail to unbind content from tests", e);
+ }
+ }
+
+
+ protected DirContext getDirContext() throws Exception
+ {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, dsConfig.getContextFactory());
+ env.put(Context.PROVIDER_URL, dsConfig.getProviderUrl());
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, dsConfig.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, dsConfig.getAdminPassword());
+ return new InitialDirContext(env);
+ }
+
+ //subsequent remove of javax.naming.Context
+ protected void removeContext(Context mainCtx, String name) throws Exception
+ {
+ Context deleteCtx = (Context)mainCtx.lookup(name);
+ NamingEnumeration subDirs = mainCtx.listBindings(name);
+
+ while (subDirs.hasMoreElements())
+ {
+ Binding binding = (Binding)subDirs.nextElement();
+ String subName = binding.getName();
+
+ removeContext(deleteCtx, subName);
+ }
+
+ mainCtx.unbind(name);
+ }
+
+ public LDAPConnectionContext createConnectionContext()
+ {
+ return new LDAPConnectionContext(dsConfig.getName(),
+ dsConfig.getProviderUrl(),
+ dsConfig.getContextFactory(),
+ dsConfig.getAdminDN(),
+ dsConfig.getAdminPassword(),
+ null,
+ "simple");
+ }
+
+
+}
Added: trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -0,0 +1,83 @@
+/*
+* 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.test.identity;
+
+import junit.framework.Assert;
+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.identity.IdentityException;
+import org.jboss.portal.common.util.CollectionBuilder;
+import org.jboss.portal.identity2.LDAPMembershipStrategy;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss dot com">Boleslaw Dawidowicz</a>
+ * @version $Revision: 2001 $
+ */
+public class MembershipStrategyTest extends Assert
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(MembershipStrategyTest.class);
+
+ /** . */
+ private MembershipStrategyTest.Context ctx;
+
+ private LDAPMembershipStrategy strategy;
+
+
+ public void setContext(MembershipStrategyTest.Context ctx)
+ {
+ this.ctx = ctx;
+ }
+
+ public void setLDAPMembershipStrategy(LDAPMembershipStrategy strategy)
+ {
+ this.strategy = strategy;
+ }
+
+ public void testFirstSimple() throws Exception
+ {
+ log.info("first test");
+ }
+
+ public void testSecondSimple() throws Exception
+ {
+ log.info("second test");
+ }
+
+ public void testThirdSimple() throws Exception
+ {
+ log.info("third test");
+ }
+
+ public interface Context
+ {
+ void begin();
+ void commit();
+ }
+}
Modified: trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml
===================================================================
--- trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml 2006-10-05 22:34:30 UTC (rev 5335)
@@ -4,9 +4,6 @@
xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
xmlns="urn:jboss:bean-deployer">
- <!--<bean name="OpenDSService" class="org.jboss.portal.test.framework.embedded.opends.OpenDSService">
- </bean>-->
-
<bean name="ApacheDSService" class="org.jboss.portal.test.framework.embedded.apacheds.ApacheDSService">
<property name="removeWorkingDir">true</property>
</bean>
@@ -24,5 +21,4 @@
<depends>ApacheDSService</depends>
</bean>
-
</deployment>
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2006-10-05 12:19:26 UTC (rev 5334)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2006-10-05 22:34:30 UTC (rev 5335)
@@ -35,13 +35,14 @@
import java.io.InputStream;
/**
+ * Configuration of LDAP Directory Server used for tests. Corresponds with directories.xml file
+ *
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
public class DSConfig
{
-
private String name;
private String description;
More information about the jboss-svn-commits
mailing list