[jboss-svn-commits] JBoss Portal SVN: r5604 - in trunk: build/ide/intellij/idea50/modules/identity cms/src/resources/portal-cms-jar/org/jboss/portal/cms identity identity/src/main/org/jboss/portal/identity2 identity/src/main/org/jboss/portal/identity2/config identity/src/main/org/jboss/portal/identity2/ldap identity/src/main/org/jboss/portal/test/identity identity/src/main/org/jboss/portal/test/identity/db identity/src/main/org/jboss/portal/test/identity/ldap identity/src/resources identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity identity/src/resources/test-identity-sar identity/src/resources/test-identity-sar/META-INF test test/src/etc test/src/etc/identityconfig test/src/main/org/jboss/portal/test/framework/embedded test/src/main/org/jboss/portal/test/framework/embedded/opends testsuite
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 8 12:47:47 EST 2006
Author: bdaw
Date: 2006-11-08 12:46:41 -0500 (Wed, 08 Nov 2006)
New Revision: 5604
Added:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
trunk/identity/src/main/org/jboss/portal/identity2/config/
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java
trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/db/
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPMembershipModuleTestCase.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/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java
trunk/identity/src/resources/test-identity-sar/
trunk/identity/src/resources/test-identity-sar/META-INF/
trunk/identity/src/resources/test-identity-sar/META-INF/jboss-service.xml
trunk/test/src/etc/identityconfig/
trunk/test/src/etc/identityconfig/opends-config.xml
trunk/test/src/etc/identityconfig/test-config.xml
trunk/test/src/etc/identityconfig/test2-config.xml
Removed:
trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java
Modified:
trunk/build/ide/intellij/idea50/modules/identity/identity.iml
trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml
trunk/identity/build.xml
trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.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/resources/portal-identity-test-jar/org/jboss/portal/test/identity/db-beans.xml
trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml
trunk/test/build.xml
trunk/test/src/etc/directories.xml
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/opends/OpenDSService.java
trunk/testsuite/build.xml
Log:
- central identity configurations option (draft)
- testsuite updates (OpenDS goes to server)
- reenable identity tests in testsuite
- improved configurable ldap user/role creation
Modified: trunk/build/ide/intellij/idea50/modules/identity/identity.iml
===================================================================
--- trunk/build/ide/intellij/idea50/modules/identity/identity.iml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/build/ide/intellij/idea50/modules/identity/identity.iml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -94,6 +94,15 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss/jbossxb/lib/jboss-xml-binding.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
Modified: trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml
===================================================================
--- trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -64,7 +64,7 @@
</bean>
<!--
- <bean name="TestBean" class="org.jboss.portal.test.identity.DBUserTestCase">
+ <bean name="TestBean" class="org.jboss.portal.test.identity.db.DBUserTestCase">
<constructor factoryMethod="getBean">
<factory bean="BeanFactory"/>
<parameter>TestBean</parameter>
Modified: trunk/identity/build.xml
===================================================================
--- trunk/identity/build.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/build.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -179,7 +179,7 @@
<include name="${javac.includes}"/>
<exclude name="${javac.excludes}"/>
- <exclude name="org/jboss/portal/test/identity/**"/>
+ <exclude name="org/jboss/portal/test/identity/ldap/**"/>
</javac>
</target>
@@ -255,22 +255,24 @@
<!-- generates artifacts used for tests, requires output to be previously run
-->
<target name="package-tests" depends="init,
- output">
+ output, package-tests15">
<jar jarfile="${build.lib}/portal-identity-test-lib.jar">
<fileset dir="${build.classes}" includes="org/jboss/portal/test/**"/>
<fileset dir="${build.resources}/portal-identity-test-jar"/>
</jar>
+ </target>
+
+ <target name="package-tests15" if="HAVE_JDK_1.5">
<!--test-identity.sar -->
- <!--<jar jarfile="${build.lib}/test-identity.sar">
+ <jar jarfile="${build.lib}/test-identity.sar">
<fileset dir="${build.resources}/test-identity-sar"/>
<fileset dir="../test/output/lib" includes="portal-test-agent-lib.jar"/>
<fileset dir="${sun.opends.lib}" includes="OpenDS.jar"/>
<fileset dir="${sleepycat.sleepycat.lib}" includes="je.jar"/>
- </jar>-->
+ </jar>
</target>
-
<!-- ================================================================== -->
<!-- Cleaning -->
<!-- ================================================================== -->
@@ -306,6 +308,7 @@
<fileset dir="../test/output/etc/opends"/>
</copy>
<copy file="${build.lib}/test-identity.sar" todir="${jboss.home}/server/${portal.deploy.dir}"/>
+ <sleep seconds="15"/>
</target>
<!-- Undeployment of agent -->
@@ -314,8 +317,11 @@
<delete dir="${jboss.home}/server/default/conf/opends"/>
</target>
- <target name="tests" depends="init" if="HAVE_JDK_1.5">
+ <target name="tests" depends="init, tests15">
<property name="proto-libs" value="${project.root}/proto-libs"/>
+
+
+
<execute-tests>
<!--
@@ -325,16 +331,9 @@
</x-sysproperty>
-->
+
<x-test>
- <!--<test todir="${test.reports}" name="org.jboss.portal.test.identity.DBUserTestCase"/>-->
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPSimpleUserModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPSimpleRoleModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>
- <!--<test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.identity.LDAPStaticGroupMembershipModuleTestCase"/>-->
+ <test todir="${test.reports}" name="org.jboss.portal.test.identity.db.DBUserTestCase"/>
</x-test>
<x-classpath>
<pathelement location="${build.lib}/portal-identity-lib.jar"/>
@@ -344,6 +343,62 @@
<path refid="apache.commons.classpath"/>
+ <path refid="dom4j.dom4j.classpath"/>
+ <path refid="jboss.microcontainer.classpath"/>
+ <path refid="jboss.jbossxb.classpath"/>
+ <path refid="apache.xerces.classpath"/>
+ <path refid="oswego.concurrent.classpath"/>
+ <path refid="apache.logging.classpath"/>
+ <path refid="apache.log4j.classpath"/>
+ <path refid="hibernate.hibernate.classpath"/>
+ <path refid="antlr.antlr.classpath"/>
+ <path refid="asm.asm.classpath"/>
+ <path refid="apache.collections.classpath"/>
+ <path refid="jbossas/core.libs.classpath"/>
+ <path refid="junit.junit.classpath"/>
+ <path refid="apache.logging.classpath"/>
+ <path refid="cglib.cglib.classpath"/>
+ <path refid="jboss.portal-test.classpath"/>
+ <path refid="jboss.portal-common.classpath"/>
+ <path refid="jboss.portal-jems.classpath"/>
+ <path refid="sun.jaf.classpath"/>
+ </x-classpath>
+ </execute-tests>
+
+
+
+ </target>
+
+
+ <target name="tests15" depends="init" if="HAVE_JDK_1.5">
+ <property name="proto-libs" value="${project.root}/proto-libs"/>
+ <antcall target="deploy-ldap"/>
+ <execute-tests>
+<!--
+
+ <x-sysproperty>
+ <jvmarg value="-Xdebug"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>
+ </x-sysproperty>
+-->
+
+
+ <x-test>
+ <!--<test todir="${test.reports}" name="org.jboss.portal.test.identity.ConfigurationTestCase"/>-->
+ <test todir="${test.reports}" name="org.jboss.portal.test.identity.ldap.LDAPSimpleUserModuleTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.identity.ldap.LDAPSimpleRoleModuleTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.identity.ldap.LDAPStaticGroupMembershipModuleTestCase"/>
+
+
+ </x-test>
+ <x-classpath>
+ <pathelement location="${build.lib}/portal-identity-lib.jar"/>
+ <pathelement location="${build.lib}/portal-identity-test-lib.jar"/>
+ <pathelement location="${jboss.portal-test.root}/etc"/>
+ <pathelement location="${build.resources}/hibernate"/>
+
+
+ <path refid="apache.commons.classpath"/>
<path refid="sun.opends.classpath"/>
<path refid="dom4j.dom4j.classpath"/>
<path refid="jboss.microcontainer.classpath"/>
@@ -367,7 +422,7 @@
<path refid="sun.jaf.classpath"/>
</x-classpath>
</execute-tests>
+ <antcall target="undeploy-ldap"/>
</target>
-
</project>
Added: trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,90 @@
+/*
+* 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 java.util.Map;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IdentityConfiguration
+{
+ public static final String GROUP_COMMON = "common";
+
+ public static final String GROUP_CONNECTION = "connection";
+
+ public static final String GROUP_USER_CREATE_ATTRIBUTES = "userCreateAttibutes";
+
+ public static final String GROUP_ROLE_CREATE_ATTRIBUTES = "roleCreateAttibutes";
+
+ public static final String CONNECTION_NAME = "connection-name";
+
+ public static final String CONNECTION_CONTEXT_FACTORY = "context-factory";
+
+ public static final String CONNECTION_HOST = "host";
+
+ public static final String CONNECTION_PORT = "port";
+
+ public static final String CONNECTION_ADMIN_DN = "admin-dn";
+
+ public static final String CONNECTION_ADMIN_PASSWORD = "admin-password";
+
+ public static final String CONNECTION_AUTHENTICATION = "authentication";
+
+ public static final String USER_CONTAINER_DN = "userContainerDN";
+
+ public static final String USER_UID_ATTRIBUTE_ID = "uidAttributeID";
+
+ public static final String ROLE_CONTAINER_DN = "roleContainerDN";
+
+ public static final String ROLE_RID_ATTRIBUTE_ID = "ridAttributeID";
+
+ public static final String ROLE_DISPLAY_NAME_ATTRIBUTE_ID = "roleDisplayNameAttributeID";
+
+ public static final String ROLE_MEMBER_ATTRIBUTE_ID = "roleMemberAttributeID";
+
+ public static final String MEMBERSHIP_UID_ATTRIBUTE_IS_DN = "memberAttributeIsDN";
+
+
+
+ public List getValues(String optionGroup, String option);
+
+ public String getValue(String optionGroup, String option);
+
+ public String getValue(String option);
+
+ public void setValues(String optionGroup, String option, List values);
+
+ public void addValue(String optionGroup, String option, String value);
+
+ public Map getOptions(String optionGroup);
+
+ public void setOptions(String optionGroup, Map options);
+
+ public void remoeOption(String optionGroup, String option);
+
+ public Map getOptionGroups();
+
+
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -39,6 +39,7 @@
public static final String CONNECTION_CONTEXT = "connection_context";
+ public static final String IDENTITY_CONFIGURATION = "configuration";
public void register(Object object, String name) throws IdentityException;
Added: trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,318 @@
+/*
+* 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.config;
+
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallerFactory;
+
+import java.util.Map;
+import java.util.List;
+import java.net.URL;
+import java.io.InputStream;
+
+/**
+ * Immutable object storing options in simple manner
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleConfigurationImpl extends AbstractJBossService implements IdentityConfiguration
+{
+
+ private Map data;
+
+ private String jndiName;
+
+ private String configFile;
+
+ protected JNDI.Binding jndiBinding;
+
+ private IdentityContext identityContext;
+
+ protected void startService() throws Exception
+ {
+
+
+ try
+ {
+ log.info("Processing portal identity configuration");
+ log.debug("config file: " + configFile);
+ URL config = Thread.currentThread().getContextClassLoader().getResource(configFile);
+ InputStream in = config.openStream();
+ // create unmarshaller
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+
+ // create an instance of ObjectModelFactory
+ ObjectModelFactory factory = new SimpleIdentityConfigurationFactory();
+
+ // let the object model factory to create an instance of Map and populate it with data from XML
+ data = (Map)unmarshaller.unmarshal(in, factory, null);
+
+ // close the XML stream
+ in.close();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot parse configuration file", e);
+ }
+
+ //
+ 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.IDENTITY_CONFIGURATION);
+ }
+
+
+ }
+
+
+ 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.IDENTITY_CONFIGURATION);
+ }
+
+ }
+
+
+
+ public List getValues(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ return (List)group.get(option);
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ List values = (List)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.get(0);
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String option)
+ {
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(GROUP_COMMON))
+ {
+ Map group = (Map)data.get(GROUP_COMMON);
+ if (group.containsKey(option))
+ {
+ List values = (List)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.get(0);
+ }
+ }
+ }
+ return null;
+ }
+
+ public void setValues(String optionGroup, String option, List values)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (values == null)
+ {
+ throw new IllegalArgumentException("null values list");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, values);
+ }
+ }
+
+ public void addValue(String optionGroup, String option, String value)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("null value name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ ((List)group.get(option)).add(value);
+ }
+ }
+ }
+
+ public Map getOptions(String optionGroup)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ return (Map)data.get(optionGroup);
+ }
+ return null;
+ }
+
+ public void setOptions(String optionGroup, Map options)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (options == null)
+ {
+ throw new IllegalArgumentException("null options map");
+ }
+ data.put(optionGroup,options);
+ }
+
+ public void remoeOption(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, null);
+ }
+ }
+
+
+ public void setData(Map data)
+ {
+ this.data = data;
+ }
+
+ public Map getOptionGroups()
+ {
+ return data;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public String getConfigFile()
+ {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile)
+ {
+ this.configFile = configFile;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,117 @@
+/*
+* 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.config;
+
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.jboss.xb.binding.GenericObjectModelFactory;
+import org.xml.sax.Attributes;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleIdentityConfigurationFactory implements GenericObjectModelFactory
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(SimpleIdentityConfigurationFactory.class);
+
+ String currentGroupName;
+
+ String currentOptionName;
+
+ public Object newRoot(Object object, UnmarshallingContext unmarshallingContext, String string, String string1, Attributes attributes)
+ {
+ return new HashMap();
+ }
+
+ public Object completeRoot(Object root, UnmarshallingContext unmarshallingContext, String string, String string1)
+ {
+ return root;
+ }
+
+ public Object newChild(Object root, UnmarshallingContext nav, String nsURI, String localName, Attributes attrs)
+ {
+ //return a new map for group options
+ if ("option-group".equals(localName))
+ {
+ return new HashMap();
+ }
+ //return list for option values
+ if ("option".equals(localName))
+ {
+ return new LinkedList();
+ }
+ if (root instanceof List)
+ {
+ if ("value".equals(localName))
+ {
+ return root;
+ }
+ }
+ return null;
+ }
+
+ public void addChild(Object parent, Object child, UnmarshallingContext nav, String nsURI, String localName)
+ {
+ if (child instanceof List && parent instanceof Map)
+ {
+ if ("option".equals(localName))
+ {
+ ((Map)parent).put(this.currentOptionName, child);
+ }
+ }
+ if (child instanceof Map && parent instanceof Map)
+ {
+ if ("option-group".equals(localName))
+ {
+ ((Map)parent).put(this.currentGroupName, child);
+ }
+ }
+ }
+
+ public void setValue(Object object, UnmarshallingContext unmarshallingContext, String nsUri, String localName, String value)
+ {
+ if(object instanceof Map)
+ {
+ if ("group-name".equals(localName))
+ {
+ this.currentGroupName = value;
+ }
+ }
+ if(object instanceof List)
+ {
+ if ("name".equals(localName))
+ {
+ this.currentOptionName = value;
+ }
+ if ("value".equals(localName))
+ {
+ List option = (List)object;
+ option.add(value);
+ }
+ }
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -24,6 +24,7 @@
import org.jboss.portal.jems.as.system.AbstractJBossService;
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;
@@ -43,6 +44,8 @@
private IdentityContext identityContext;
+ private IdentityConfiguration identityConfiguration;
+
protected void startService() throws Exception
{
if (identityContext == null)
@@ -68,7 +71,7 @@
}
- private String name;
+ /*private String name;
private String providerUrl;
@@ -80,9 +83,9 @@
private String protocol;
- private String authentication = "simple";
+ private String authentication = "simple";*/
- public LDAPConnectionContext(String name,
+ /*public LDAPConnectionContext(String name,
String url,
String context,
String admin,
@@ -97,6 +100,11 @@
this.adminPassword = password;
this.protocol = protocol;
this.authentication = authentication;
+ }*/
+
+ public LDAPConnectionContext()
+ {
+
}
@@ -106,7 +114,7 @@
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, this.getContextFactory());
- env.put(Context.PROVIDER_URL, this.getProviderUrl());
+ env.put(Context.PROVIDER_URL, "ldap://" + getHost() + ":" + getPort());
env.put(Context.SECURITY_AUTHENTICATION, this.getAuthentication());
env.put(Context.SECURITY_PRINCIPAL, this.getAdminDN());
env.put(Context.SECURITY_CREDENTIALS, this.getAdminPassword());
@@ -123,12 +131,13 @@
public String toString()
{
StringBuffer str = new StringBuffer();
- str.append("Name: ").append(this.name)
- .append(", Provider URL: ").append(this.providerUrl)
- .append(", Context factory: ").append(this.contextFactory)
- .append(", Admin user: ").append(this.adminDN)
- .append(", Admin password: ").append(this.adminPassword)
- .append(", Authentication: ").append(this.authentication);
+ str.append("Name: ").append(getName())
+ .append(", Host: ").append(getHost())
+ .append(", Port: ").append(getPort())
+ .append(", Context factory: ").append(getContextFactory())
+ .append(", Admin user: ").append(getAdminDN())
+ .append(", Admin password: ").append(getAdminPassword())
+ .append(", Authentication: ").append(getAuthentication());
return str.toString();
}
@@ -138,55 +147,60 @@
public String getName()
{
- return name;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_NAME);
}
- public void setName(String name)
+ /*public void setName(String name)
{
this.name = name;
- }
+ }*/
- public String getProviderUrl()
+ public String getHost()
{
- return providerUrl;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_HOST);
}
- public void setProviderUrl(String providerUrl)
+ /*public void setProviderUrl(String providerUrl)
{
this.providerUrl = providerUrl;
+ }*/
+
+ public String getPort()
+ {
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_PORT);
}
public String getContextFactory()
{
- return contextFactory;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_CONTEXT_FACTORY);
}
- public void setContextFactory(String contextFactory)
+ /*public void setContextFactory(String contextFactory)
{
this.contextFactory = contextFactory;
- }
+ }*/
public String getAdminDN()
{
- return adminDN;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_ADMIN_DN);
}
- public void setAdminDN(String adminDN)
+ /*public void setAdminDN(String adminDN)
{
this.adminDN = adminDN;
- }
+ }*/
public String getAdminPassword()
{
- return adminPassword;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_ADMIN_PASSWORD);
}
- public void setAdminPassword(String adminPassword)
+ /*public void setAdminPassword(String adminPassword)
{
this.adminPassword = adminPassword;
- }
+ }*/
- public String getProtocol()
+ /*public String getProtocol()
{
return protocol;
}
@@ -194,17 +208,22 @@
public void setProtocol(String protocol)
{
this.protocol = protocol;
- }
+ }*/
public String getAuthentication()
{
- return authentication;
+ String auth = getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_CONNECTION, IdentityConfiguration.CONNECTION_AUTHENTICATION);
+ if (auth == null)
+ {
+ return "simple";
+ }
+ return auth;
}
- public void setAuthentication(String authentication)
+ /*public void setAuthentication(String authentication)
{
this.authentication = authentication;
- }
+ }*/
public IdentityContext getIdentityContext()
{
@@ -216,5 +235,21 @@
this.identityContext = identityContext;
}
+ public IdentityConfiguration getIdentityConfiguration()
+ {
+ try
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+ catch (IdentityException e)
+ {
+ throw new RuntimeException("Can't obtain IdentityConfiguration", e);
+ }
+ }
+
}
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-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -30,6 +30,7 @@
import org.jboss.portal.identity.User;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.MembershipModule;
+import org.jboss.portal.identity2.IdentityConfiguration;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.NamingEnumeration;
@@ -45,6 +46,8 @@
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.HashSet;
+import java.util.Map;
+import java.util.Iterator;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
@@ -58,15 +61,17 @@
private IdentityContext identityContext;
- private String ridAttributeID;
+ private IdentityConfiguration identityConfiguration;
- private String containerDN;
+ //private String ridAttributeID;
- private String displayNameAttributeID;
+ //private String containerDN;
- protected JNDI.Binding jndiBinding;
+ //private String displayNameAttributeID;
+ protected JNDI.Binding jndiBinding;
+
protected void startService() throws Exception
{
@@ -192,20 +197,45 @@
//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)
+ /*//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", "");
+ attrs.put("member", "");*/
+ Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new IdentityException(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES + " missing in configuration");
+ }
+
+ for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
+ {
+ String attributeName = (String)it1.next();
+ log.debug("adding attribute: " + attributeName);
+ Attribute attr = new BasicAttribute(attributeName);
+ List attributeValues = (List)attributesToAdd.get(attributeName);
+
+ for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
+ {
+ String attrValue = (String)it2.next();
+ log.debug("adding attribute value: " + attrValue);
+ attr.add(attrValue);
+ }
+ attrs.put(attr);
+ }
+
//role name
attrs.put(getRidAttributeID(), name);
//display name
- attrs.put(getDisplayNameAttributeID(), displayName);
+ if (!getDisplayNameAttributeID().equals(getRidAttributeID()))
+ {
+ attrs.put(getDisplayNameAttributeID(), displayName);
+ }
String dn = getRidAttributeID().concat("=").concat(name);
@@ -214,7 +244,7 @@
}
catch (NamingException e)
{
- throw new IdentityException("Failed to create user", e);
+ throw new IdentityException("Failed to create role", e);
}
return findRoleByName(name);
@@ -380,8 +410,6 @@
ldapr.setDisplayName((String)display.get());
}
- //TODO:handle password
-
log.debug("role uid: " + ldapr.getId());
log.debug("role dn: " + ldapr.getDn());
@@ -399,19 +427,20 @@
//*** Getter and Setters
//**************************
- public String getRidAttributeID()
+ public String getRidAttributeID() throws IdentityException
{
- if (this.ridAttributeID == null)
+ String rid = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_RID_ATTRIBUTE_ID);
+ if (rid == null)
{
return "cn";
}
- return ridAttributeID;
+ return rid;
}
- public void setRidAttributeID(String ridAttributeID)
+ /*public void setRidAttributeID(String ridAttributeID)
{
this.ridAttributeID = ridAttributeID;
- }
+ }*/
public LDAPConnectionContext getConnectionContext() throws IdentityException
@@ -423,34 +452,44 @@
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()
+ public String getContainerDN() throws IdentityException
{
- return containerDN;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
}
- public void setContainerDN(String containerDN)
+ /*public void setContainerDN(String containerDN)
{
this.containerDN = containerDN;
- }
+ }*/
- public String getDisplayNameAttributeID()
+ public String getDisplayNameAttributeID() throws IdentityException
{
- if (this.displayNameAttributeID == null)
+ String display = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_DISPLAY_NAME_ATTRIBUTE_ID);
+ if (display == null)
{
return getRidAttributeID();
}
- return displayNameAttributeID;
+ return display;
}
- public void setDisplayNameAttributeID(String displayNameAttributeID)
+ /*public void setDisplayNameAttributeID(String displayNameAttributeID)
{
this.displayNameAttributeID = displayNameAttributeID;
- }
+ }*/
public IdentityContext getIdentityContext()
{
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-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -24,30 +24,21 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.User;
-import org.jboss.portal.identity2.LDAPMembershipStrategy;
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.SearchControls;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
import java.util.Set;
-import java.util.List;
-import java.util.NoSuchElementException;
import java.util.HashSet;
-import java.util.MissingResourceException;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
@@ -58,13 +49,15 @@
private LDAPConnectionContext connectionContext;
- private UserModule userModule;
+ private LDAPUserModuleImpl userModule;
private RoleModule roleModule;
private IdentityContext identityContext;
+ private IdentityConfiguration identityConfiguration;
+
//private LDAPMembershipStrategy membershipStrategy;
private String jndiName;
@@ -78,11 +71,11 @@
/** Name of attribute in role entry that point to belonging user */
- private String uidAttributeID;
+ //private String uidAttributeID;
/** If the uidAttributeID in Role entry keeps full DN of a user or just a name */
- private boolean uidAttributeIsDN;
+ //private boolean uidAttributeIsDN;
protected void startService() throws Exception
@@ -184,13 +177,14 @@
//obtain Role entry attributes from directory
Attributes attrs = getConnectionContext().createInitialContext().getAttributes(ldapRole.getDn());
+ log.debug("Role attributes: " + attrs);
if (attrs == null )
{
throw new IdentityException("Cannot find Role with DN: " + ldapRole.getDn());
}
//iterate over user names belonging to this role
- NamingEnumeration values = attrs.get(getUidAttributeID()).getAll();
+ NamingEnumeration values = attrs.get(getMemberAttributeID()).getAll();
while (values.hasMoreElements())
{
String value = values.nextElement().toString();
@@ -204,7 +198,7 @@
try
{
- users.add(getUserModule().findUserByUserName(name));
+ users.add(getUserModule().findUserByUserName(name));
}
catch(IdentityException ie)
{
@@ -293,18 +287,27 @@
return connectionContext;
}
- public UserModule getUserModule() throws IdentityException
+ 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 = (UserModule)identityContext.getObject(IdentityContext.USER_MODULE);
+ this.userModule = (LDAPUserModuleImpl)identityContext.getObject(IdentityContext.USER_MODULE);
}
catch (ClassCastException e)
{
- throw new IdentityException("Not supported object as part of the context", e);
+ throw new IdentityException("Not supported object as part of the context - must be LDAPUserModuleImpl", e);
}
}
return userModule;
@@ -347,23 +350,32 @@
this.jndiName = jndiName;
}
- public String getUidAttributeID()
+ public String getMemberAttributeID() throws IdentityException
{
- return uidAttributeID;
+ String uid = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_MEMBER_ATTRIBUTE_ID);
+ if (uid == null)
+ {
+ return "member";
+ }
+ return uid;
}
- public void setUidAttributeID(String uidAttributeID)
+ /*public void setUidAttributeID(String uidAttributeID)
{
this.uidAttributeID = uidAttributeID;
- }
+ }*/
- public boolean isUidAttributeIsDN()
+ public boolean isUidAttributeIsDN() throws IdentityException
{
- return uidAttributeIsDN;
+ if (getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_UID_ATTRIBUTE_IS_DN) == null)
+ {
+ return true;
+ }
+ return Boolean.getBoolean(getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_UID_ATTRIBUTE_IS_DN));
}
- public void setUidAttributeIsDN(boolean uidAttributeIsDN)
+ /*public void setUidAttributeIsDN(boolean uidAttributeIsDN)
{
this.uidAttributeIsDN = uidAttributeIsDN;
- }
+ }*/
}
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-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -30,6 +30,7 @@
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;
@@ -45,6 +46,8 @@
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.HashSet;
+import java.util.Map;
+import java.util.Iterator;
/**
* Simple implementation of UserModule for LDAP support. Search of users is limited to one place * containerField - DN
@@ -61,6 +64,8 @@
private LDAPConnectionContext connectionContext;
+ private IdentityConfiguration identityConfiguration;
+
private String jndiName;
private IdentityContext identityContext;
@@ -68,15 +73,15 @@
private UserProfileModule userProfileModule;
/** Attribute that stores user id */
- private String uidAttributeID;
+ //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;
+ //private String containerDN;
- protected JNDI.Binding jndiBinding;
+ protected JNDI.Binding jndiBinding;
protected void startService() throws Exception
@@ -180,6 +185,50 @@
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.ONELEVEL_SCOPE);
+
+ String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);*//*
+
+
+ NamingEnumeration results = getConnectionContext().createInitialContext().search(getContainerDN(), filter, controls);
+ List sr = Tools.toList(results);
+ if (sr.size() > 1)
+ {
+ throw new IdentityException("Found more than one user with id: " + userName + "" +
+ "Posible data inconsistency");
+ }
+ return createUserInstance((SearchResult)sr.iterator().next());
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with name: " + userName, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+
+ }*/
+
//TODO:how to properly store password? encoding and let specify the method?
public User createUser(String userName, String password, String realEmail) throws IdentityException, IllegalArgumentException
{
@@ -188,6 +237,7 @@
{
throw new IdentityException("User name cannot be null");
}
+ log.debug("Creating user: " + userName);
try
@@ -199,18 +249,41 @@
//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)
+ /*//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", "");
+ attrs.put("sn", " ");
+ attrs.put("cn", " ");*/
+ Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES + " missing in configuration");
+ }
+
+ for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
+ {
+ String attributeName = (String)it1.next();
+ log.debug("adding attribute: " + attributeName);
+ Attribute attr = new BasicAttribute(attributeName);
+ List attributeValues = (List)attributesToAdd.get(attributeName);
+
+ for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
+ {
+ String attrValue = (String)it2.next();
+ log.debug("adding attribute value: " + attrValue);
+ attr.add(attrValue);
+ }
+ attrs.put(attr);
+ }
+
//TODO: correctly store password... encode it and choose the method?
- attrs.put("userPassword", password);
+ //TODO: make password attribute name configurable?
+ attrs.put("userpassword", password);
//
String dn = getUidAttributeID().concat("=").concat(userName);
@@ -333,6 +406,8 @@
}
+
+
protected LDAPUserImpl createUserInstance(SearchResult sr) throws IdentityException
{
LDAPUserImpl ldapu = null;
@@ -383,19 +458,20 @@
this.userProfileModule = userProfileModule;
}
- public String getUidAttributeID()
+ public String getUidAttributeID() throws IdentityException
{
- if (this.uidAttributeID == null)
+ String uid = getIdentityConfiguration().getValue(IdentityConfiguration.USER_UID_ATTRIBUTE_ID);
+ if (uid == null)
{
return "uid";
}
- return uidAttributeID;
+ return uid;
}
- public void setUidAttributeID(String uidAttributeID)
+ /*public void setUidAttributeID(String uidAttributeID)
{
this.uidAttributeID = uidAttributeID;
- }
+ }*/
public LDAPConnectionContext getConnectionContext() throws IdentityException
{
@@ -406,20 +482,30 @@
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()
+ public String getContainerDN() throws IdentityException
{
- return containerDN;
+ return getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
}
- public void setContainerDN(String containerDN)
+ /*public void setContainerDN(String containerDN)
{
this.containerDN = containerDN;
- }
+ }*/
/*public String getNameAttributeID()
{
Added: trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,135 @@
+/*
+* 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.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.jboss.portal.identity2.IdentityContextImpl;
+import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
+
+
+import java.util.Set;
+import java.util.Iterator;
+
+
+/**
+ * @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 class ConfigurationTestCase extends junit.framework.TestCase
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(ConfigurationTestCase.class);
+
+ static
+ {
+ Appender appender = new ConsoleAppender(new SimpleLayout());
+ Logger.getRoot().addAppender(appender);
+ Logger.getRoot().setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.portal.identity2").setLevel(Level.DEBUG);
+ }
+
+ /*public static TestSuite createTestSuite(Class clazz) throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
+ Map parameterMap = new HashMap();
+ parameterMap.put("DirectoryServerConfig", DSConfig.fromXML2(configsURL));
+ POJOJUnitTest abc = new POJOJUnitTest(clazz);
+ JUnitAdapter adapter = new JUnitAdapter(abc);
+ TestSuite suite = new TestSuite();
+ suite.addTest(adapter);
+ return suite;
+ }*/
+
+ public ConfigurationTestCase()
+ {
+
+ }
+
+ /*public ConfigurationTestCase(DSConfig dsConfig)
+ {
+ this.directoryServerConfigParameter = dsConfig;
+ }
+
+ private DSConfig directoryServerConfigParameter;
+
+ public String getName()
+ {
+ return super.getName();// + "," + directoryServerConfigParameter.getName() + "," + directoryServerConfigParameter.getDescription();
+ }
+
+ public DSConfig getDirectoryServerConfigParameter()
+ {
+ return directoryServerConfigParameter;
+ }
+
+ public void setDirectoryServerConfigParameter(DSConfig directoryServerConfigParameter)
+ {
+ this.directoryServerConfigParameter = directoryServerConfigParameter;
+ }*/
+
+ IdentityContextImpl context;
+
+
+ public void setUp() throws Exception
+ {
+ this.context = new IdentityContextImpl();
+ context.start();
+
+
+ }
+
+ public void testFactory() throws Exception
+ {
+ SimpleConfigurationImpl configuration = new SimpleConfigurationImpl();
+ configuration.setIdentityContext(context);
+ configuration.setConfigFile("identityconfig/test-config.xml");
+ configuration.start();
+ Set keys = configuration.getOptionGroups().keySet();
+ log.info("Option Groups:");
+ for (Iterator iterator = keys.iterator(); iterator.hasNext();)
+ {
+ String group = (String)iterator.next();
+ log.info("option-group: " + group);
+
+ log.info("Options:");
+ Set names = configuration.getOptions(group).keySet();
+ for (Iterator iterator1 = names.iterator(); iterator1.hasNext();)
+ {
+ String optionName = (String)iterator1.next();
+ log.info("Name: " + optionName);
+
+ }
+
+ }
+
+
+ assertEquals("uid",configuration.getValue("user.uidAttributeId"));
+ }
+
+
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,324 +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.test.identity;
-
-import junit.framework.TestSuite;
-import org.apache.log4j.Appender;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.jboss.portal.common.test.junit.POJOJUnitTest;
-import org.jboss.portal.common.test.junit.JUnitAdapter;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.identity.ProfileMap;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.db.DBRoleModuleImpl;
-import org.jboss.portal.identity.db.DBUserModuleImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-import org.jboss.portal.test.framework.embedded.DataSourceSupport;
-import org.jboss.portal.test.framework.embedded.HibernateSupport;
-
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class DBUserTestCase extends junit.framework.TestCase implements UserTest.Context
-{
-
- static
- {
- Appender appender = new ConsoleAppender(new SimpleLayout());
- Logger.getRoot().addAppender(appender);
- Logger.getRoot().setLevel(Level.DEBUG);
- Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
- }
-
- public static TestSuite suite() throws Exception
- {
- URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
- Map parameterMap = new HashMap();
- parameterMap.put("DataSourceConfig", DataSourceSupport.Config.fromXML2(configsURL));
- POJOJUnitTest abc = new POJOJUnitTest(DBUserTestCase.class);
- JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
- TestSuite suite = new TestSuite();
- suite.addTest(adapter);
- return suite;
- }
-
- /** . */
- private DataSourceSupport.Config dataSourceConfigParameter;
-
- /** . */
- private TestRuntimeContext runtimeContext;
-
- /** . */
- private HibernateSupport hibernate;
-
- /** . */
- private UserTest utc;
-
- /** . */
- private DBUserModuleImpl userModule;
-
- /** . */
- private DBRoleModuleImpl roleModule;
-
- public DataSourceSupport.Config getDataSourceConfigParameter()
- {
- return dataSourceConfigParameter;
- }
-
- public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfig)
- {
- this.dataSourceConfigParameter = dataSourceConfig;
- }
-
- public HibernateSupport getHibernate()
- {
- return hibernate;
- }
-
- public void setHibernate(HibernateSupport hibernate)
- {
- this.hibernate = hibernate;
- }
-
- public String getName()
- {
- return super.getName() + "," + dataSourceConfigParameter.getDisplayName();
- }
-
- public void setUp() throws Exception
- {
- runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/db-beans.xml");
- runtimeContext.addBean("DBTestBean", this);
- runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
- runtimeContext.start();
-
- //
- utc = new UserTest();
- userModule = new DBUserModuleImpl();
- userModule.setSessionFactoryJNDIName("java:/SessionFactory");
- userModule.start();
-
- //
- roleModule = new DBRoleModuleImpl();
- roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
- roleModule.start();
-
- //
- utc.setUserModule(userModule);
- utc.setRoleModule(roleModule);
- utc.setContext(this);
- utc.populate();
- }
-
- public void tearDown() throws Exception
- {
- utc.setUserModule(null);
- utc.setRoleModule(null);
- utc.setContext(null);
- utc = null;
-
- //
- roleModule.destroy();
- userModule.destroy();
- roleModule = null;
- userModule = null;
-
- //
- runtimeContext.stop();
- }
-
-
- public void begin()
- {
- hibernate.openSession();
- }
-
- public void commit()
- {
- assertTrue(hibernate.commitTransaction());
- }
-
- //
-
- public void testFindUsersUsingFilter() throws Exception
- {
- utc.testFindUsersUsingFilter();
- }
-
- public void testFindUser1() throws Exception
- {
- utc.testFindUser1();
- }
-
- public void testFindUser2() throws Exception
- {
- utc.testFindUser2();
- }
-
- public void testFindUsers() throws Exception
- {
- utc.testFindUsers();
- }
-
- public void testCreateUser() throws Exception
- {
- utc.testCreateUser();
- }
-
- public void testCreateRole() throws Exception
- {
- utc.testCreateRole();
- }
-
- public void testCountUser() throws Exception
- {
- utc.testCountUser();
- }
-
- public void testRemoveNonExistingRole() throws Exception
- {
- utc.testRemoveNonExistingRole();
- }
-
- public void testRemoveRole() throws Exception
- {
- utc.testRemoveRole();
- }
-
- public void testRemoveUser() throws Exception
- {
- utc.testRemoveUser();
- }
-
- public void testFindRoles() throws Exception
- {
- utc.testFindRoles();
- }
-
- public void testFindRoleMembers() throws Exception
- {
- utc.testFindRoleMembers();
- }
-
- public void testDynamicProperty() throws Exception
- {
- begin();
- User user = userModule.createUser("testname", "testpassword", "testemail");
- ProfileMap map = user.getProfile();
- assertNull(map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- map.put("foo", "value");
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
-
- begin();
- user = userModule.findUserByUserName("testname");
- map = user.getProfile();
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
- }
-
- public void testStaticProperty() throws Exception
- {
- begin();
-
- //
- User user = userModule.createUser("testname", "testpassword", "testemail");
- ProfileMap map = user.getProfile();
- assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
-
- // Test cannot remove a static property
- try
- {
- map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
- fail("Should not be capable to remove static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test read only property
- assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
- try
- {
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
- fail("Should not be capable to modify a read only static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test non nullable and writable property
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
- fail("Should not be capable to nullify a non nullable static property");
- }
- catch (NullPointerException expected)
- {
- }
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals(true, user.getViewRealEmail());
-
- // Test boolean property
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- user.setViewRealEmail(false);
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- user.setViewRealEmail(true);
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
- fail("Should not be capable to set a bad value to boolean property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test date
- Date date = user.getRegistrationDate();
- SimpleDateFormat sdf = new SimpleDateFormat();
- assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
-
- commit();
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,57 +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.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 LDAPMembershipModuleTestCase extends LDAPTestCase implements MembershipStrategyTest.Context
-{
-
- /** . */
- protected MembershipStrategyTest mstc;
-
- public 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();
- }*/
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,119 +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.test.identity;
-
-import junit.framework.TestSuite;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
-import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPSimpleRoleModuleTestCase extends LDAPTestCase
-{
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPSimpleRoleModuleTestCase.class);
-
- public static TestSuite suite() throws Exception
- {
- return createTestSuite(LDAPSimpleRoleModuleTestCase.class);
- }
-
- RoleModule roleModule;
-
- public void setUp() throws Exception
- {
- runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
- runtimeContext.addBean("LDAPTestBean", this);
-
- IdentityContextImpl context = new IdentityContextImpl();
- context.start();
-
- LDAPConnectionContext connection = createConnectionContext();
- connection.setIdentityContext(context);
- connection.start();
-
- LDAPRoleModuleImpl roleModule = new LDAPRoleModuleImpl();
- roleModule.setIdentityContext(context);
- roleModule.setContainerDN("ou=Roles,dc=jboss,dc=org");
- roleModule.setRidAttributeID("cn");
- roleModule.start();
- this.roleModule = roleModule;
-
- super.setUp();
- }
-
-
- public void testFirstSimple() throws Exception
- {
- log.info("test framework works ;]");
- }
-
- public void testFindRoleByName() throws Exception
- {
- LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles,dc=jboss,dc=org");
- assertEquals(ldapr.getName(), "Echo");
- }
-
- public void testRemoveRole() throws Exception
- {
- LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles,dc=jboss,dc=org");
- assertEquals(ldapr.getName(), "Echo");
- roleModule.removeRole("Echo");
- ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertNull(ldapr);
- }
-
- public void testCreateRole() throws Exception
- {
- LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.createRole("testRole", "testDisplayName");
- assertNotNull(ldapr);
- assertEquals("testRole", ldapr.getName());
- //assertEquals("testDisplayName",ldapr.getDisplayName());
-
- ldapr = (LDAPRoleImpl)roleModule.findRoleById("testRole");
- assertNotNull(ldapr);
- roleModule.removeRole("testRole");
-
- ldapr = (LDAPRoleImpl)roleModule.findRoleById("testRole");
- assertNull(ldapr);
-
- }
-
- public void testgetRoleCount() throws Exception
- {
- LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
- assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles,dc=jboss,dc=org");
- assertEquals(ldapr.getName(), "Echo");
-
- int count = roleModule.getRolesCount();
- assertEquals(2, count);
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,121 +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.test.identity;
-
-import junit.framework.TestSuite;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity2.ldap.LDAPUserImpl;
-import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPSimpleUserModuleTestCase extends LDAPTestCase
-{
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPSimpleUserModuleTestCase.class);
-
- public static TestSuite suite() throws Exception
- {
- System.out.println("###");
- return createTestSuite(LDAPSimpleUserModuleTestCase.class);
- }
-
- UserModule userModule;
-
- public void setUp() throws Exception
- {
- System.out.println("#########################");
- runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
- runtimeContext.addBean("LDAPTestBean", this);
-
- IdentityContextImpl context = new IdentityContextImpl();
- context.start();
-
- LDAPConnectionContext connection = createConnectionContext();
- connection.setIdentityContext(context);
- connection.start();
-
- LDAPUserModuleImpl userModule = new LDAPUserModuleImpl();
- userModule.setIdentityContext(context);
-
- userModule.setContainerDN("ou=People,dc=jboss,dc=org");
- userModule.setUidAttributeID("uid");
-
- userModule.start();
- this.userModule = userModule;
-
- super.setUp();
- }
-
-
- public void testFirstSimple() throws Exception
- {
- log.info("test framework works ;]");
- }
-
- public void testFindUserByName() throws Exception
- {
- LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People,dc=jboss,dc=org");
- assertEquals(ldapu.getUserName(), "jduke");
- }
-
- public void testRemoveUser() throws Exception
- {
- LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertNotNull(ldapu);
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People,dc=jboss,dc=org");
- userModule.removeUser("jduke");
- ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertNull(ldapu);
- }
-
- public void testCreateUser() throws Exception
- {
- LDAPUserImpl ldapu = (LDAPUserImpl)userModule.createUser("testUser", "testPassword", "email");
- assertNotNull(ldapu);
- assertEquals("testUser", ldapu.getUserName());
-
- ldapu = (LDAPUserImpl)userModule.findUserById("testUser");
- assertNotNull(ldapu);
- userModule.removeUser("testUser");
-
- ldapu = (LDAPUserImpl)userModule.findUserById("testUser");
- assertNull(ldapu);
-
- }
-
- public void testgetUserCount() throws Exception
- {
- LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
- assertEquals(ldapu.getDn(), "uid=jduke,ou=People,dc=jboss,dc=org");
- assertEquals(ldapu.getUserName(), "jduke");
-
- int count = userModule.getUserCount();
- assertEquals(5, count);
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,122 +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.test.identity;
-
-import junit.framework.TestSuite;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
-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.identity.UserModule;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
-
-
-import java.util.Set;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPStaticGroupMembershipModuleTestCase extends LDAPMembershipModuleTestCase
-{
-
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticGroupMembershipModuleTestCase.class);
-
- public static TestSuite suite() throws Exception
- {
- return createTestSuite(LDAPStaticGroupMembershipModuleTestCase.class);
- }
-
- private UserModule userModule;
-
- private RoleModule roleModule;
-
- private MembershipModule membershipModule;
-
- public void setUp() throws Exception
- {
- runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
- runtimeContext.addBean("LDAPTestBean", this);
-
- IdentityContextImpl context = new IdentityContextImpl();
- context.start();
-
- LDAPConnectionContext connection = createConnectionContext();
- connection.setIdentityContext(context);
- connection.start();
-
- LDAPUserModuleImpl userModule = new LDAPUserModuleImpl();
- userModule.setIdentityContext(context);
-
- userModule.setContainerDN("ou=People,dc=jboss,dc=org");
- userModule.setUidAttributeID("uid");
-
- userModule.start();
- this.userModule = userModule;
-
- LDAPRoleModuleImpl roleModule = new LDAPRoleModuleImpl();
- roleModule.setIdentityContext(context);
- roleModule.setContainerDN("ou=Roles,dc=jboss,dc=org");
- roleModule.setRidAttributeID("cn");
- roleModule.start();
- this.roleModule = roleModule;
-
- LDAPStaticGroupMembershipModuleImpl membership = new LDAPStaticGroupMembershipModuleImpl();
- membership.setIdentityContext(context);
- membership.setUidAttributeID("member");
- membership.setUidAttributeIsDN(true);
- membership.start();
- this.membershipModule = membership;
-
- mstc = new MembershipStrategyTest();
- mstc.setContext(this);
- mstc.setMembershipModule(membership);
- mstc.setUserModule(userModule);
- mstc.setRoleModule(roleModule);
-
-
- super.setUp();
- }
-
-
- public void testGetUsers() throws Exception
- {
- LDAPRoleImpl role = (LDAPRoleImpl)roleModule.findRoleByName("Echo");
- Set users = membershipModule.getUsers(role);
- assertEquals(3, users.size());
-
- for (Iterator iterator = users.iterator(); iterator.hasNext();)
- {
- User user = (User)iterator.next();
- log.info("####################3User: " + user.getUserName());
-
- }
-
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,277 +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.test.identity;
-
-//import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
-import org.apache.log4j.Appender;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-import org.jboss.portal.test.framework.embedded.DSConfig;
-import org.jboss.portal.test.framework.embedded.opends.OpenDSService;
-import org.jboss.portal.common.test.junit.JUnitAdapter;
-import org.jboss.portal.common.test.junit.POJOJUnitTest;
-import org.opends.server.tools.LDAPModify;
-//import org.jboss.portal.test.framework.embedded.apacheds.ApacheDSService;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.net.URL;
-import java.net.Socket;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.File;
-
-import junit.framework.TestSuite;
-
-/**
- * @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);
- Logger.getLogger("org.jboss.portal.identity2.ldap").setLevel(Level.DEBUG);
- }
-
- public static TestSuite createTestSuite(Class clazz) throws Exception
- {
- URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
- Map parameterMap = new HashMap();
- parameterMap.put("DirectoryServerConfig", DSConfig.fromXML2(configsURL));
- POJOJUnitTest abc = new POJOJUnitTest(clazz);
- JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
- TestSuite suite = new TestSuite();
- suite.addTest(adapter);
- return suite;
- }
-
- public LDAPTestCase()
- {
-
- }
-
- public LDAPTestCase(DSConfig dsConfig)
- {
- this.directoryServerConfigParameter = dsConfig;
- }
-
- protected TestRuntimeContext runtimeContext;
-
- private DSConfig directoryServerConfigParameter;
-
- protected OpenDSService embeddedDSService;
-
- public String getName()
- {
- return super.getName() + "," + directoryServerConfigParameter.getName() + "," + directoryServerConfigParameter.getDescription();
- }
-
- public DSConfig getDirectoryServerConfigParameter()
- {
- return directoryServerConfigParameter;
- }
-
- public void setDirectoryServerConfigParameter(DSConfig directoryServerConfigParameter)
- {
- this.directoryServerConfigParameter = directoryServerConfigParameter;
- }
-
- public void setUp() throws Exception
- {
- /*if(directoryServerConfigParameter.isUseEmbedded())
- {
- embeddedDSService = new OpenDSService();
- //embeddedDSService.setRemoveWorkingDir(true);
- embeddedDSService.start();
- //give a chance to come up...
- //Thread.sleep(500);
- }*/
- runtimeContext.start();
-
-
- populate();
- }
-
- public void tearDown() throws Exception
- {
-
- //on exit remove dc=jboss,dc=org
- cleanUp();
-
- runtimeContext.stop();
-
- /*if (embeddedDSService != null && directoryServerConfigParameter.isUseEmbedded())
- {
- embeddedDSService.stop();
- }*/
- }
-
-
- public void begin()
- {
-
- }
-
-
- public void commit()
- {
-
-
- }
-
- protected void populate()
- {
- try
- {
- //on start load the content into ldap
- log.info("Populate directory...");
-
- DirContext ctx = getDirContext();
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
-
- //URL ldif = tcl.getResource("ldap/ldif/example1.ldif");
- URL ldif = tcl.getResource(directoryServerConfigParameter.getPopulateLdif());
- log.info("ldif to load by loader: " + ldif.getPath());
-
- /* LdifFileLoader loader = new LdifFileLoader(ctx, ldif.getPath());
- loader.execute();*/
-
- //String fileurl = this.getResourceURL("security/opends/ldif/example1.ldif");
- //URL url = this.getDeployURL(fileurl);
- log.debug("ldap add ldif url="+ldif);
- File file = new File(ldif.getPath());
- String[] cmd = new String[] {"-h", "localhost", "-p",
- "10389", "-D", "cn=Directory Manager",
- "-w", "password",
- "-a", "-f",file.getPath()};
- /*String[] cmd = new String[] {"-h", directoryServerConfigParameter.getProviderUrl().split(":")[1],
- "-p", directoryServerConfigParameter.getProviderUrl().split(":")[2],
- "-D", directoryServerConfigParameter.getAdminDN(),
- "-w", directoryServerConfigParameter.getAdminPassword(),
- "-a", "-f",file.getPath()};*/
-
- //System.out.println("Populate success: :" + (LDAPModify.mainModify(cmd,false,System.out, System.err) == 0));
- System.out.println("Populate success: :" + (LDAPModify.mainModify(cmd) == 0));
- }
- catch (Exception e)
- {
- log.info("fail to import initial ldif for tests", e);
- }
- }
-
- protected void cleanUp()
- {
- try
- {
- log.info("Cleanup directory...");
- DirContext ctx = getDirContext();
- String fullDN = directoryServerConfigParameter.getCleanUpDN();
- String[] parts = fullDN.split(",");
- String removeContext = parts[0];
-
- //for embedded OpenDS it must be removed that way
- if (directoryServerConfigParameter.isUseEmbedded())
- {
- removeContext = fullDN;
- }
-
- String suffix = fullDN.substring(fullDN.indexOf(",")+1,fullDN.length());
-
- log.debug("Clean up: \'" + removeContext + "\' from \'" + suffix + "\'");
-
- //DirContext org = (DirContext)ctx.lookup("dc=org");
-
- //of we use embedded the "dc=org" is already a suffix - just a small hack for such DIT
- DirContext org = ctx;
-
- //if not lets obtain...
- if (!directoryServerConfigParameter.isUseEmbedded())
- {
- org = (DirContext)ctx.lookup(suffix);
- }
- removeContext(org, removeContext);
- }
- 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, directoryServerConfigParameter.getContextFactory());
- env.put(Context.PROVIDER_URL, directoryServerConfigParameter.getProviderUrl());
- //env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, directoryServerConfigParameter.getAdminDN());
- env.put(Context.SECURITY_CREDENTIALS, directoryServerConfigParameter.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(directoryServerConfigParameter.getName(),
- directoryServerConfigParameter.getProviderUrl(),
- directoryServerConfigParameter.getContextFactory(),
- directoryServerConfigParameter.getAdminDN(),
- directoryServerConfigParameter.getAdminPassword(),
- null,
- "simple");
- }
-
-
-}
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -1,411 +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.test.identity;
-
-import junit.framework.TestSuite;
-//import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
-import org.apache.log4j.Appender;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.jboss.portal.common.test.junit.POJOJUnitTest;
-import org.jboss.portal.common.test.junit.JUnitAdapter;
-import org.jboss.portal.test.framework.TestRuntimeContext;
-import org.jboss.portal.test.framework.embedded.DSConfig;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.net.URL;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @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 class LDAPUserTestCase extends junit.framework.TestCase implements UserTest.Context
-{
-
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserTestCase.class);
-
- public static TestSuite suite() throws Exception
- {
- URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
- Map parameterMap = new HashMap();
- parameterMap.put("DirectoryServerConfig", DSConfig.fromXML2(configsURL));
- POJOJUnitTest abc = new POJOJUnitTest(LDAPUserTestCase.class);
- JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
- TestSuite suite = new TestSuite();
- suite.addTest(adapter);
- return suite;
- }
-
- static
- {
- Appender appender = new ConsoleAppender(new SimpleLayout());
- Logger.getRoot().addAppender(appender);
- Logger.getRoot().setLevel(Level.INFO);
- }
-
- /** . */
- private TestRuntimeContext runtimeContext;
-
- /** . */
- private DSConfig directoryServerConfigParameter;
-
- /** . */
- private UserTest utc;
-
- /** . */
- //private DBUserModuleImpl userModule;
-
- public DSConfig getDirectoryServerConfigParameter()
- {
- return directoryServerConfigParameter;
- }
-
- public void setDirectoryServerConfigParameter(DSConfig directoryServerConfigParameter)
- {
- this.directoryServerConfigParameter = directoryServerConfigParameter;
- }
-
- /** . */
- //private DBRoleModuleImpl roleModule;
-
-
-
- public String getName()
- {
- return super.getName() + "," + directoryServerConfigParameter.getName() + "," + directoryServerConfigParameter.getDescription();
- }
-
- protected void setUp() throws Exception
- {
- runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
- runtimeContext.addBean("LDAPTestBean", this);
- runtimeContext.start();
-
- //
- utc = new UserTest();
- /*
- userModule = new DBUserModuleImpl();
- userModule.setSessionFactoryJNDIName("java:/SessionFactory");
- userModule.start();
-
- //
- roleModule = new DBRoleModuleImpl();
- roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
- roleModule.start();
-
- //
- utc.setUserModule(userModule);
- utc.setRoleModule(roleModule);
- utc.setContext(this);
- utc.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 tearDown() throws Exception
- {
-
- /*utc.setUserModule(null);
- utc.setRoleModule(null);
- utc.setContext(null);
- utc = null;
-
- //
- roleModule.destroy();
- userModule.destroy();
- roleModule = null;
- userModule = null;*/
-
- //
- //on exit remove dc=jboss,dc=org
- 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);
- }
-
- runtimeContext.stop();
- }
-
-
- public void begin()
- {
-
- }
-
-
- public void commit()
- {
-
-
- }
-
-
- public void testSimple() throws Exception
- {
- log.info("simple test");
- DirContext ctx = getDirContext();
- DirContext org = (DirContext)ctx.lookup("dc=org");
- NamingEnumeration bindings = ctx.listBindings("dc=org");
- log.info("listing before remove: ");
- while (bindings.hasMore())
- {
-
- Binding bd = (Binding)bindings.next();
- //log.info("name enum element: " + bd.getClass().getName());
- log.info(bd.getName() + ": " + bd.getObject());
- }
-
- //removeContext(org,"dc=jboss");
-
- bindings = ctx.listBindings("dc=org");
- log.info("listing after remove: ");
- while (bindings.hasMore())
- {
- Binding bd = (Binding)bindings.next();
- log.info(bd.getName() + ": " + bd.getObject());
- }
- }
-
- public void testSecondSimple() throws Exception
- {
- log.info("second test");
- }
-
- public void testThirdSimple() throws Exception
- {
- log.info("third test");
- }
- //
-
- /*public void testFindUsersUsingFilter() throws Exception
- {
- utc.testFindUsersUsingFilter();
- }
-
- public void testFindUser1() throws Exception
- {
- utc.testFindUser1();
- }
-
- public void testFindUser2() throws Exception
- {
- utc.testFindUser2();
- }
-
- public void testFindUsers() throws Exception
- {
- utc.testFindUsers();
- }
-
- public void testCreateUser() throws Exception
- {
- utc.testCreateUser();
- }
-
- public void testCreateRole() throws Exception
- {
- utc.testCreateRole();
- }
-
- public void testCountUser() throws Exception
- {
- utc.testCountUser();
- }
-
- public void testRemoveNonExistingRole() throws Exception
- {
- utc.testRemoveNonExistingRole();
- }
-
- public void testRemoveRole() throws Exception
- {
- utc.testRemoveRole();
- }
-
- public void testRemoveUser() throws Exception
- {
- utc.testRemoveUser();
- }
-
- public void testFindRoles() throws Exception
- {
- utc.testFindRoles();
- }
-
- public void testFindRoleMembers() throws Exception
- {
- utc.testFindRoleMembers();
- }
-
- public void testDynamicProperty() throws Exception
- {
- begin();
- User user = userModule.createUser("testname", "testpassword", "testemail");
- ProfileMap map = user.getProfile();
- assertNull(map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- map.put("foo", "value");
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
-
- begin();
- user = userModule.findUserByUserName("testname");
- map = user.getProfile();
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
- }
-
- public void testStaticProperty() throws Exception
- {
- begin();
-
- //
- User user = userModule.createUser("testname", "testpassword", "testemail");
- ProfileMap map = user.getProfile();
- assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
-
- // Test cannot remove a static property
- try
- {
- map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
- fail("Should not be capable to remove static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test read only property
- assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
- try
- {
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
- fail("Should not be capable to modify a read only static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test non nullable and writable property
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
- fail("Should not be capable to nullify a non nullable static property");
- }
- catch (NullPointerException expected)
- {
- }
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals(true, user.getViewRealEmail());
-
- // Test boolean property
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- user.setViewRealEmail(false);
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- user.setViewRealEmail(true);
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
- fail("Should not be capable to set a bad value to boolean property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test date
- Date date = user.getRegistrationDate();
- SimpleDateFormat sdf = new SimpleDateFormat();
- assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
-
- commit();
- }*/
-
- private DirContext getDirContext() throws Exception
- {
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY, directoryServerConfigParameter.getContextFactory());
- env.put(Context.PROVIDER_URL, directoryServerConfigParameter.getProviderUrl());
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, directoryServerConfigParameter.getAdminDN());
- env.put(Context.SECURITY_CREDENTIALS, directoryServerConfigParameter.getAdminPassword());
- return new InitialDirContext(env);
- }
-
- //subsequent remove of javax.naming.Context
- private 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);
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,325 @@
+/******************************************************************************
+ * 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.db;
+
+import junit.framework.TestSuite;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.test.junit.JUnitAdapter;
+import org.jboss.portal.common.p3p.P3PConstants;
+import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.db.DBRoleModuleImpl;
+import org.jboss.portal.identity.db.DBUserModuleImpl;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.framework.embedded.DataSourceSupport;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.identity.UserTest;
+
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class DBUserTestCase extends junit.framework.TestCase implements UserTest.Context
+{
+
+ static
+ {
+ Appender appender = new ConsoleAppender(new SimpleLayout());
+ Logger.getRoot().addAppender(appender);
+ Logger.getRoot().setLevel(Level.DEBUG);
+ Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+ }
+
+ public static TestSuite suite() throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
+ Map parameterMap = new HashMap();
+ parameterMap.put("DataSourceConfig", DataSourceSupport.Config.fromXML2(configsURL));
+ POJOJUnitTest abc = new POJOJUnitTest(DBUserTestCase.class);
+ JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
+ TestSuite suite = new TestSuite();
+ suite.addTest(adapter);
+ return suite;
+ }
+
+ /** . */
+ private DataSourceSupport.Config dataSourceConfigParameter;
+
+ /** . */
+ private TestRuntimeContext runtimeContext;
+
+ /** . */
+ private HibernateSupport hibernate;
+
+ /** . */
+ private UserTest utc;
+
+ /** . */
+ private DBUserModuleImpl userModule;
+
+ /** . */
+ private DBRoleModuleImpl roleModule;
+
+ public DataSourceSupport.Config getDataSourceConfigParameter()
+ {
+ return dataSourceConfigParameter;
+ }
+
+ public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfig)
+ {
+ this.dataSourceConfigParameter = dataSourceConfig;
+ }
+
+ public HibernateSupport getHibernate()
+ {
+ return hibernate;
+ }
+
+ public void setHibernate(HibernateSupport hibernate)
+ {
+ this.hibernate = hibernate;
+ }
+
+ public String getName()
+ {
+ return super.getName() + "," + dataSourceConfigParameter.getDisplayName();
+ }
+
+ public void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/db-beans.xml");
+ runtimeContext.addBean("DBTestBean", this);
+ runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
+ runtimeContext.start();
+
+ //
+ utc = new UserTest();
+ userModule = new DBUserModuleImpl();
+ userModule.setSessionFactoryJNDIName("java:/SessionFactory");
+ userModule.start();
+
+ //
+ roleModule = new DBRoleModuleImpl();
+ roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
+ roleModule.start();
+
+ //
+ utc.setUserModule(userModule);
+ utc.setRoleModule(roleModule);
+ utc.setContext(this);
+ utc.populate();
+ }
+
+ public void tearDown() throws Exception
+ {
+ utc.setUserModule(null);
+ utc.setRoleModule(null);
+ utc.setContext(null);
+ utc = null;
+
+ //
+ roleModule.destroy();
+ userModule.destroy();
+ roleModule = null;
+ userModule = null;
+
+ //
+ runtimeContext.stop();
+ }
+
+
+ public void begin()
+ {
+ hibernate.openSession();
+ }
+
+ public void commit()
+ {
+ assertTrue(hibernate.commitTransaction());
+ }
+
+ //
+
+ public void testFindUsersUsingFilter() throws Exception
+ {
+ utc.testFindUsersUsingFilter();
+ }
+
+ public void testFindUser1() throws Exception
+ {
+ utc.testFindUser1();
+ }
+
+ public void testFindUser2() throws Exception
+ {
+ utc.testFindUser2();
+ }
+
+ public void testFindUsers() throws Exception
+ {
+ utc.testFindUsers();
+ }
+
+ public void testCreateUser() throws Exception
+ {
+ utc.testCreateUser();
+ }
+
+ public void testCreateRole() throws Exception
+ {
+ utc.testCreateRole();
+ }
+
+ public void testCountUser() throws Exception
+ {
+ utc.testCountUser();
+ }
+
+ public void testRemoveNonExistingRole() throws Exception
+ {
+ utc.testRemoveNonExistingRole();
+ }
+
+ public void testRemoveRole() throws Exception
+ {
+ utc.testRemoveRole();
+ }
+
+ public void testRemoveUser() throws Exception
+ {
+ utc.testRemoveUser();
+ }
+
+ public void testFindRoles() throws Exception
+ {
+ utc.testFindRoles();
+ }
+
+ public void testFindRoleMembers() throws Exception
+ {
+ utc.testFindRoleMembers();
+ }
+
+ public void testDynamicProperty() throws Exception
+ {
+ begin();
+ User user = userModule.createUser("testname", "testpassword", "testemail");
+ ProfileMap map = user.getProfile();
+ assertNull(map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ map.put("foo", "value");
+ assertEquals("value", map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ commit();
+
+ begin();
+ user = userModule.findUserByUserName("testname");
+ map = user.getProfile();
+ assertEquals("value", map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ commit();
+ }
+
+ public void testStaticProperty() throws Exception
+ {
+ begin();
+
+ //
+ User user = userModule.createUser("testname", "testpassword", "testemail");
+ ProfileMap map = user.getProfile();
+ assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+
+ // Test cannot remove a static property
+ try
+ {
+ map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
+ fail("Should not be capable to remove static property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test read only property
+ assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
+ try
+ {
+ map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+ fail("Should not be capable to modify a read only static property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test non nullable and writable property
+ try
+ {
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
+ fail("Should not be capable to nullify a non nullable static property");
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals(true, user.getViewRealEmail());
+
+ // Test boolean property
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+ assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(false, user.getViewRealEmail());
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(true, user.getViewRealEmail());
+ user.setViewRealEmail(false);
+ assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(false, user.getViewRealEmail());
+ user.setViewRealEmail(true);
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(true, user.getViewRealEmail());
+ try
+ {
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+ fail("Should not be capable to set a bad value to boolean property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test date
+ Date date = user.getRegistrationDate();
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+
+ commit();
+ }
+}
Property changes on: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPMembershipModuleTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPMembershipModuleTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPMembershipModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * 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.ldap;
+
+import org.jboss.portal.test.identity.ldap.LDAPTestCase;
+import org.jboss.portal.test.identity.MembershipStrategyTest;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPMembershipModuleTestCase extends LDAPTestCase implements MembershipStrategyTest.Context
+{
+
+ /** . */
+ protected MembershipStrategyTest mstc;
+
+ public 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();
+ }*/
+}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleRoleModuleTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,126 @@
+/******************************************************************************
+ * 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.ldap;
+
+import junit.framework.TestSuite;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
+import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
+import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
+import org.jboss.portal.identity2.IdentityContextImpl;
+import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.identity.ldap.LDAPTestCase;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPSimpleRoleModuleTestCase extends LDAPTestCase
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPSimpleRoleModuleTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ return createTestSuite(LDAPSimpleRoleModuleTestCase.class);
+ }
+
+ RoleModule roleModule;
+
+ public void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+
+ IdentityContextImpl context = new IdentityContextImpl();
+ context.start();
+ identityContext = context;
+
+ SimpleConfigurationImpl configuration = new SimpleConfigurationImpl();
+ configuration.setIdentityContext(identityContext);
+ configuration.setConfigFile(getDirectoryServerConfigParameter().getConfigFile());
+ configuration.start();
+
+ LDAPConnectionContext connection = new LDAPConnectionContext();
+ connection.setIdentityContext(identityContext);
+ connection.start();
+
+ LDAPRoleModuleImpl roleModule = new LDAPRoleModuleImpl();
+ roleModule.setIdentityContext(identityContext);
+ //roleModule.setContainerDN("ou=Roles,dc=jboss,dc=org");
+ //roleModule.setRidAttributeID("cn");
+ roleModule.start();
+ this.roleModule = roleModule;
+
+ super.setUp();
+ }
+
+
+ public void testFirstSimple() throws Exception
+ {
+ log.info("test framework works ;]");
+ }
+
+ public void testFindRoleByName() throws Exception
+ {
+ LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
+ assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + getDirectoryServerConfigParameter().getCleanUpDN());
+ 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.getName(), "Echo");
+ roleModule.removeRole("Echo");
+ ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
+ assertNull(ldapr);
+ }
+
+ public void testCreateRole() throws Exception
+ {
+ LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.createRole("testRole", "testDisplayName");
+ assertNotNull(ldapr);
+ assertEquals("testRole", ldapr.getName());
+ //assertEquals("testDisplayName",ldapr.getDisplayName());
+
+ ldapr = (LDAPRoleImpl)roleModule.findRoleById("testRole");
+ assertNotNull(ldapr);
+ roleModule.removeRole("testRole");
+
+ ldapr = (LDAPRoleImpl)roleModule.findRoleById("testRole");
+ assertNull(ldapr);
+
+ }
+
+ public void testgetRoleCount() throws Exception
+ {
+ LDAPRoleImpl ldapr = (LDAPRoleImpl)roleModule.findRoleById("Echo");
+ assertEquals(ldapr.getDn(), "cn=Echo,ou=Roles," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapr.getName(), "Echo");
+
+ int count = roleModule.getRolesCount();
+ assertEquals(2, count);
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPSimpleUserModuleTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,129 @@
+/******************************************************************************
+ * 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.ldap;
+
+import junit.framework.TestSuite;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity2.ldap.LDAPUserImpl;
+import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
+import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
+import org.jboss.portal.identity2.IdentityContextImpl;
+import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.identity.ldap.LDAPTestCase;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPSimpleUserModuleTestCase extends LDAPTestCase
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPSimpleUserModuleTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ System.out.println("###");
+ return createTestSuite(LDAPSimpleUserModuleTestCase.class);
+ }
+
+ UserModule userModule;
+
+ public void setUp() throws Exception
+ {
+ System.out.println("#########################");
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+
+ IdentityContextImpl context = new IdentityContextImpl();
+ context.start();
+ identityContext = context;
+
+ SimpleConfigurationImpl configuration = new SimpleConfigurationImpl();
+ configuration.setIdentityContext(identityContext);
+ configuration.setConfigFile(getDirectoryServerConfigParameter().getConfigFile());
+ configuration.start();
+
+ LDAPConnectionContext connection = new LDAPConnectionContext();
+ connection.setIdentityContext(identityContext);
+ connection.start();
+
+ LDAPUserModuleImpl userModule = new LDAPUserModuleImpl();
+ userModule.setIdentityContext(identityContext);
+
+ //userModule.setContainerDN("ou=People,dc=jboss,dc=org");
+ //userModule.setUidAttributeID("uid");
+
+ userModule.start();
+ this.userModule = userModule;
+
+ super.setUp();
+ }
+
+
+ public void testFirstSimple() throws Exception
+ {
+ log.info("test framework works ;]");
+ }
+
+ public void testFindUserByName() throws Exception
+ {
+ LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapu.getUserName(), "jduke");
+ }
+
+ public void testRemoveUser() throws Exception
+ {
+ LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
+ assertNotNull(ldapu);
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ userModule.removeUser("jduke");
+ ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
+ assertNull(ldapu);
+ }
+
+ public void testCreateUser() throws Exception
+ {
+ LDAPUserImpl ldapu = (LDAPUserImpl)userModule.createUser("testUser", "testPassword", "email");
+ assertNotNull(ldapu);
+ assertEquals("testUser", ldapu.getUserName());
+
+ ldapu = (LDAPUserImpl)userModule.findUserById("testUser");
+ assertNotNull(ldapu);
+ userModule.removeUser("testUser");
+
+ ldapu = (LDAPUserImpl)userModule.findUserById("testUser");
+ assertNull(ldapu);
+
+ }
+
+ public void testgetUserCount() throws Exception
+ {
+ LDAPUserImpl ldapu = (LDAPUserImpl)userModule.findUserById("jduke");
+ assertEquals(ldapu.getDn(), "uid=jduke,ou=People," + getDirectoryServerConfigParameter().getCleanUpDN());
+ assertEquals(ldapu.getUserName(), "jduke");
+
+ int count = userModule.getUserCount();
+ assertEquals(5, count);
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * 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.ldap;
+
+import junit.framework.TestSuite;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.identity.ldap.LDAPMembershipModuleTestCase;
+import org.jboss.portal.test.identity.MembershipStrategyTest;
+import org.jboss.portal.identity2.IdentityContextImpl;
+import org.jboss.portal.identity2.MembershipModule;
+import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
+import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
+import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
+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.identity.UserModule;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+
+
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPStaticGroupMembershipModuleTestCase extends LDAPMembershipModuleTestCase
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPStaticGroupMembershipModuleTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ return createTestSuite(LDAPStaticGroupMembershipModuleTestCase.class);
+ }
+
+ private UserModule userModule;
+
+ private RoleModule roleModule;
+
+ private MembershipModule membershipModule;
+
+ public void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+
+ IdentityContextImpl context = new IdentityContextImpl();
+ context.start();
+ identityContext = context;
+
+ SimpleConfigurationImpl configuration = new SimpleConfigurationImpl();
+ configuration.setIdentityContext(identityContext);
+ configuration.setConfigFile(getDirectoryServerConfigParameter().getConfigFile());
+ configuration.start();
+
+ LDAPConnectionContext connection = new LDAPConnectionContext();
+ connection.setIdentityContext(identityContext);
+ connection.start();
+
+ LDAPUserModuleImpl userModule = new LDAPUserModuleImpl();
+ userModule.setIdentityContext(identityContext);
+
+ //userModule.setContainerDN("ou=People,dc=jboss,dc=org");
+ //userModule.setUidAttributeID("uid");
+
+ userModule.start();
+ this.userModule = userModule;
+
+ LDAPRoleModuleImpl roleModule = new LDAPRoleModuleImpl();
+ roleModule.setIdentityContext(identityContext);
+ //roleModule.setContainerDN("ou=Roles,dc=jboss,dc=org");
+ //roleModule.setRidAttributeID("cn");
+ roleModule.start();
+ this.roleModule = roleModule;
+
+ LDAPStaticGroupMembershipModuleImpl membership = new LDAPStaticGroupMembershipModuleImpl();
+ membership.setIdentityContext(identityContext);
+ //membership.setUidAttributeID("member");
+ //membership.setUidAttributeIsDN(true);
+ membership.start();
+ this.membershipModule = membership;
+
+ mstc = new MembershipStrategyTest();
+ mstc.setContext(this);
+ mstc.setMembershipModule(membership);
+ mstc.setUserModule(userModule);
+ mstc.setRoleModule(roleModule);
+
+
+ super.setUp();
+ }
+
+
+ public void testGetUsers() throws Exception
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)roleModule.findRoleByName("Echo");
+ Set users = membershipModule.getUsers(role);
+ assertEquals(3, users.size());
+
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ User user = (User)iterator.next();
+ log.info("####################3User: " + user.getUserName());
+
+ }
+
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,266 @@
+/******************************************************************************
+ * 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.ldap;
+
+//import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.portal.common.test.junit.JUnitAdapter;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.opends.server.tools.LDAPModify;
+//import org.jboss.portal.test.framework.embedded.apacheds.ApacheDSService;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.File;
+
+import junit.framework.TestSuite;
+
+/**
+ * @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);
+ Logger.getLogger("org.jboss.portal.identity2.ldap").setLevel(Level.DEBUG);
+ }
+
+ public static TestSuite createTestSuite(Class clazz) throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
+ Map parameterMap = new HashMap();
+ parameterMap.put("DirectoryServerConfig", DSConfig.fromXML2(configsURL));
+ POJOJUnitTest abc = new POJOJUnitTest(clazz);
+ JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
+ TestSuite suite = new TestSuite();
+ suite.addTest(adapter);
+ return suite;
+ }
+
+ public LDAPTestCase()
+ {
+
+ }
+
+ public LDAPTestCase(DSConfig dsConfig)
+ {
+ this.directoryServerConfigParameter = dsConfig;
+ }
+
+ protected TestRuntimeContext runtimeContext;
+
+ protected IdentityContext identityContext;
+
+ private DSConfig directoryServerConfigParameter;
+
+ //protected OpenDSService embeddedDSService;
+
+ public String getName()
+ {
+ return super.getName() + "," + directoryServerConfigParameter.getName() + "," + directoryServerConfigParameter.getDescription();
+ }
+
+ public DSConfig getDirectoryServerConfigParameter()
+ {
+ return directoryServerConfigParameter;
+ }
+
+ public void setDirectoryServerConfigParameter(DSConfig directoryServerConfigParameter)
+ {
+ this.directoryServerConfigParameter = directoryServerConfigParameter;
+ }
+
+ public void setUp() throws Exception
+ {
+ /*if(directoryServerConfigParameter.isUseEmbedded())
+ {
+ embeddedDSService = new OpenDSService();
+ //embeddedDSService.setRemoveWorkingDir(true);
+ embeddedDSService.start();
+ //give a chance to come up...
+ //Thread.sleep(500);
+ }*/
+ runtimeContext.start();
+
+
+ populate();
+ }
+
+ public void tearDown() throws Exception
+ {
+
+ //on exit remove dc=jboss,dc=org
+ cleanUp();
+
+ runtimeContext.stop();
+
+ /*if (embeddedDSService != null && directoryServerConfigParameter.isUseEmbedded())
+ {
+ embeddedDSService.stop();
+ }*/
+ }
+
+
+ public void begin()
+ {
+
+ }
+
+
+ public void commit()
+ {
+
+
+ }
+
+ protected void populate()
+ {
+ try
+ {
+ //on start load the content into ldap
+ log.info("Populate directory...");
+
+ DirContext ctx = getDirContext();
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+
+ //URL ldif = tcl.getResource("ldap/ldif/example1.ldif");
+ URL ldif = tcl.getResource(directoryServerConfigParameter.getPopulateLdif());
+ log.info("ldif to load by loader: " + ldif.getPath());
+
+ /* LdifFileLoader loader = new LdifFileLoader(ctx, ldif.getPath());
+ loader.execute();*/
+
+ //String fileurl = this.getResourceURL("security/opends/ldif/example1.ldif");
+ //URL url = this.getDeployURL(fileurl);
+ log.debug("ldap add ldif url="+ldif);
+ File file = new File(ldif.getPath());
+ String[] cmd = new String[] {"-h", directoryServerConfigParameter.getHost(),
+ "-p", directoryServerConfigParameter.getPort(),
+ "-D", directoryServerConfigParameter.getAdminDN(),
+ "-w", directoryServerConfigParameter.getAdminPassword(),
+ "-a", "-f",file.getPath()};
+
+ System.out.println("Populate success: :" + (LDAPModify.mainModify(cmd) == 0));
+ }
+ catch (Exception e)
+ {
+ log.info("fail to import initial ldif for tests", e);
+ }
+ }
+
+ protected void cleanUp()
+ {
+ try
+ {
+ log.info("Cleanup directory...");
+ DirContext ctx = getDirContext();
+ String fullDN = directoryServerConfigParameter.getCleanUpDN();
+ //String[] parts = fullDN.split(",");
+
+ String removeContext = fullDN;
+
+ String suffix = fullDN.substring(fullDN.indexOf(",")+1,fullDN.length());
+
+ log.debug("Clean up: \'" + removeContext + "\' from \'" + suffix + "\'");
+
+
+ DirContext org = ctx;
+
+
+ removeContext(org, removeContext);
+ }
+ 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, directoryServerConfigParameter.getContextFactory());
+
+ env.put(Context.PROVIDER_URL, directoryServerConfigParameter.getURL());
+ //env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, directoryServerConfigParameter.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, directoryServerConfigParameter.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(directoryServerConfigParameter.getName(),
+ directoryServerConfigParameter.getURL(),
+ directoryServerConfigParameter.getContextFactory(),
+ directoryServerConfigParameter.getAdminDN(),
+ directoryServerConfigParameter.getAdminPassword(),
+ null,
+ "simple");*//*
+ LDAPConnectionContext conn = new LDAPConnectionContext();
+ conn.setIdentityContext(identityContext);
+
+
+ }*/
+
+
+}
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java (from rev 5599, trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/LDAPUserTestCase.java 2006-11-08 13:14:24 UTC (rev 5599)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,412 @@
+/******************************************************************************
+ * 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.ldap;
+
+import junit.framework.TestSuite;
+//import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.test.junit.JUnitAdapter;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.framework.embedded.DSConfig;
+import org.jboss.portal.test.identity.UserTest;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @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 class LDAPUserTestCase extends junit.framework.TestCase implements UserTest.Context
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserTestCase.class);
+
+ public static TestSuite suite() throws Exception
+ {
+ URL configsURL = Thread.currentThread().getContextClassLoader().getResource("directories.xml");
+ Map parameterMap = new HashMap();
+ parameterMap.put("DirectoryServerConfig", DSConfig.fromXML2(configsURL));
+ POJOJUnitTest abc = new POJOJUnitTest(LDAPUserTestCase.class);
+ JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
+ TestSuite suite = new TestSuite();
+ suite.addTest(adapter);
+ return suite;
+ }
+
+ static
+ {
+ Appender appender = new ConsoleAppender(new SimpleLayout());
+ Logger.getRoot().addAppender(appender);
+ Logger.getRoot().setLevel(Level.INFO);
+ }
+
+ /** . */
+ private TestRuntimeContext runtimeContext;
+
+ /** . */
+ private DSConfig directoryServerConfigParameter;
+
+ /** . */
+ private UserTest utc;
+
+ /** . */
+ //private DBUserModuleImpl userModule;
+
+ public DSConfig getDirectoryServerConfigParameter()
+ {
+ return directoryServerConfigParameter;
+ }
+
+ public void setDirectoryServerConfigParameter(DSConfig directoryServerConfigParameter)
+ {
+ this.directoryServerConfigParameter = directoryServerConfigParameter;
+ }
+
+ /** . */
+ //private DBRoleModuleImpl roleModule;
+
+
+
+ public String getName()
+ {
+ return super.getName() + "," + directoryServerConfigParameter.getName() + "," + directoryServerConfigParameter.getDescription();
+ }
+
+ protected void setUp() throws Exception
+ {
+ runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/ldap-beans.xml");
+ runtimeContext.addBean("LDAPTestBean", this);
+ runtimeContext.start();
+
+ //
+ utc = new UserTest();
+ /*
+ userModule = new DBUserModuleImpl();
+ userModule.setSessionFactoryJNDIName("java:/SessionFactory");
+ userModule.start();
+
+ //
+ roleModule = new DBRoleModuleImpl();
+ roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
+ roleModule.start();
+
+ //
+ utc.setUserModule(userModule);
+ utc.setRoleModule(roleModule);
+ utc.setContext(this);
+ utc.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 tearDown() throws Exception
+ {
+
+ /*utc.setUserModule(null);
+ utc.setRoleModule(null);
+ utc.setContext(null);
+ utc = null;
+
+ //
+ roleModule.destroy();
+ userModule.destroy();
+ roleModule = null;
+ userModule = null;*/
+
+ //
+ //on exit remove dc=jboss,dc=org
+ 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);
+ }
+
+ runtimeContext.stop();
+ }
+
+
+ public void begin()
+ {
+
+ }
+
+
+ public void commit()
+ {
+
+
+ }
+
+
+ public void testSimple() throws Exception
+ {
+ log.info("simple test");
+ DirContext ctx = getDirContext();
+ DirContext org = (DirContext)ctx.lookup("dc=org");
+ NamingEnumeration bindings = ctx.listBindings("dc=org");
+ log.info("listing before remove: ");
+ while (bindings.hasMore())
+ {
+
+ Binding bd = (Binding)bindings.next();
+ //log.info("name enum element: " + bd.getClass().getName());
+ log.info(bd.getName() + ": " + bd.getObject());
+ }
+
+ //removeContext(org,"dc=jboss");
+
+ bindings = ctx.listBindings("dc=org");
+ log.info("listing after remove: ");
+ while (bindings.hasMore())
+ {
+ Binding bd = (Binding)bindings.next();
+ log.info(bd.getName() + ": " + bd.getObject());
+ }
+ }
+
+ public void testSecondSimple() throws Exception
+ {
+ log.info("second test");
+ }
+
+ public void testThirdSimple() throws Exception
+ {
+ log.info("third test");
+ }
+ //
+
+ /*public void testFindUsersUsingFilter() throws Exception
+ {
+ utc.testFindUsersUsingFilter();
+ }
+
+ public void testFindUser1() throws Exception
+ {
+ utc.testFindUser1();
+ }
+
+ public void testFindUser2() throws Exception
+ {
+ utc.testFindUser2();
+ }
+
+ public void testFindUsers() throws Exception
+ {
+ utc.testFindUsers();
+ }
+
+ public void testCreateUser() throws Exception
+ {
+ utc.testCreateUser();
+ }
+
+ public void testCreateRole() throws Exception
+ {
+ utc.testCreateRole();
+ }
+
+ public void testCountUser() throws Exception
+ {
+ utc.testCountUser();
+ }
+
+ public void testRemoveNonExistingRole() throws Exception
+ {
+ utc.testRemoveNonExistingRole();
+ }
+
+ public void testRemoveRole() throws Exception
+ {
+ utc.testRemoveRole();
+ }
+
+ public void testRemoveUser() throws Exception
+ {
+ utc.testRemoveUser();
+ }
+
+ public void testFindRoles() throws Exception
+ {
+ utc.testFindRoles();
+ }
+
+ public void testFindRoleMembers() throws Exception
+ {
+ utc.testFindRoleMembers();
+ }
+
+ public void testDynamicProperty() throws Exception
+ {
+ begin();
+ User user = userModule.createUser("testname", "testpassword", "testemail");
+ ProfileMap map = user.getProfile();
+ assertNull(map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ map.put("foo", "value");
+ assertEquals("value", map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ commit();
+
+ begin();
+ user = userModule.findUserByUserName("testname");
+ map = user.getProfile();
+ assertEquals("value", map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ commit();
+ }
+
+ public void testStaticProperty() throws Exception
+ {
+ begin();
+
+ //
+ User user = userModule.createUser("testname", "testpassword", "testemail");
+ ProfileMap map = user.getProfile();
+ assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+
+ // Test cannot remove a static property
+ try
+ {
+ map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
+ fail("Should not be capable to remove static property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test read only property
+ assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
+ try
+ {
+ map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+ fail("Should not be capable to modify a read only static property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test non nullable and writable property
+ try
+ {
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
+ fail("Should not be capable to nullify a non nullable static property");
+ }
+ catch (NullPointerException expected)
+ {
+ }
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals(true, user.getViewRealEmail());
+
+ // Test boolean property
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+ assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(false, user.getViewRealEmail());
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(true, user.getViewRealEmail());
+ user.setViewRealEmail(false);
+ assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(false, user.getViewRealEmail());
+ user.setViewRealEmail(true);
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals(true, user.getViewRealEmail());
+ try
+ {
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+ fail("Should not be capable to set a bad value to boolean property");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ // Test date
+ Date date = user.getRegistrationDate();
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+
+ commit();
+ }*/
+
+ private DirContext getDirContext() throws Exception
+ {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, directoryServerConfigParameter.getContextFactory());
+ env.put(Context.PROVIDER_URL, directoryServerConfigParameter.getHost());
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+ env.put(Context.SECURITY_PRINCIPAL, directoryServerConfigParameter.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, directoryServerConfigParameter.getAdminPassword());
+ return new InitialDirContext(env);
+ }
+
+ //subsequent remove of javax.naming.Context
+ private 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);
+ }
+}
Modified: trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/db-beans.xml
===================================================================
--- trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/db-beans.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/db-beans.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -63,7 +63,7 @@
</property>
</bean>
- <bean name="DBTestBean" class="org.jboss.portal.test.identity.DBUserTestCase">
+ <bean name="DBTestBean" class="org.jboss.portal.test.identity.db.DBUserTestCase">
<constructor factoryMethod="getBean">
<factory bean="BeanFactory"/>
<parameter>DBTestBean</parameter>
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-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/ldap-beans.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -39,7 +39,7 @@
<bean name="JNDISupport" class="org.jboss.portal.test.framework.embedded.JNDISupport">
</bean>
- <bean name="LDAPTestBean" class="org.jboss.portal.test.identity.LDAPUserTestCase">
+ <bean name="LDAPTestBean" class="org.jboss.portal.test.identity.ldap.LDAPUserTestCase">
<constructor factoryMethod="getBean">
<factory bean="BeanFactory"/>
<parameter>LDAPTestBean</parameter>
Added: trunk/identity/src/resources/test-identity-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/identity/src/resources/test-identity-sar/META-INF/jboss-service.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/identity/src/resources/test-identity-sar/META-INF/jboss-service.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,31 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<server>
+
+ <!-- OpenDS service (LDAP) -->
+ <mbean
+ code="org.jboss.portal.test.framework.embedded.opends.OpenDSService"
+ name="portal.test:service=OpenDSService">
+ </mbean>
+</server>
\ No newline at end of file
Modified: trunk/test/build.xml
===================================================================
--- trunk/test/build.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/build.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -250,9 +250,6 @@
<fileset dir="${build.resources}/portal-test-sar"/>
<!--<fileset dir="${junit.junit.lib}" includes="junit.jar"/>-->
<fileset dir="${build.lib}" includes="portal-test-agent-lib.jar"/>
- <fileset dir="${sun.opends.lib}" includes="OpenDS.jar"/>
- <fileset dir="${build.etc}/opends/" includes="*"/>
- <fileset dir="${sleepycat.sleepycat.lib}" includes="je.jar"/>
<!--<fileset dir="${sun.jaf.lib}" includes="activation.jar"/>-->
</jar>
</target>
@@ -293,10 +290,6 @@
description="Deploy."
depends="output">
<require file="${jboss.home}/server/${portal.deploy.dir}"/>
- <mkdir dir="${jboss.home}/server/${portal.deploy.dir}/../conf/opends"/>
- <copy todir="${jboss.home}/server/${portal.deploy.dir}/../conf/opends" overwrite="true">
- <fileset dir="${build.etc}/opends"/>
- </copy>
<copy file="${build.lib}/portal-test.sar" todir="${jboss.home}/server/${portal.deploy.dir}"/>
</target>
@@ -305,6 +298,5 @@
depends="init">
<require file="${jboss.home}/server/${portal.deploy.dir}"/>
<delete file="${jboss.home}/server/${portal.deploy.dir}/portal-test.sar"/>
- <delete dir="${jboss.home}/server/${portal.deploy.dir}/../conf/opends"/>
</target>
</project>
Modified: trunk/test/src/etc/directories.xml
===================================================================
--- trunk/test/src/etc/directories.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/etc/directories.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -23,14 +23,18 @@
<directories>
<directory>
- <name>ApacheDS</name>
- <description>Embedded OpenDS service</description>
- <provider-url>ldap://localhost:10389</provider-url>
+ <name>OpenDS</name>
+ <description>OpenDS service deployed on JBoss AS as an mbean</description>
+ <!--identity configuration file-->
+ <config-file>identityconfig/opends-config.xml</config-file>
+ <host>localhost</host>
+ <port>10389</port>
<context-factory>com.sun.jndi.ldap.LdapCtxFactory</context-factory>
<admin-dn>cn=Directory Manager</admin-dn>
<admin-password>password</admin-password>
- <use-embedded>true</use-embedded>
+ <!--ldif from which LDAP will be populated before each test-->
<populate-ldif>ldap/ldif/example1.ldif</populate-ldif>
+ <!--DN that will be removed to perform cleanup after each test-->
<cleanup-dn>dc=jboss,dc=org</cleanup-dn>
</directory>
</directories>
Added: trunk/test/src/etc/identityconfig/opends-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<identity-configuration>
+ <option-group>
+ <group-name>connection</group-name>
+ <option>
+ <name>host</name>
+ <value>localhost</value>
+ </option>
+ <option>
+ <name>port</name>
+ <value>10389</value>
+ </option>
+ <option>
+ <name>context-factory</name>
+ <value>com.sun.jndi.ldap.LdapCtxFactory</value>
+ </option>
+ <option>
+ <name>admin-dn</name>
+ <value>cn=Directory Manager</value>
+ </option>
+ <option>
+ <name>admin-password</name>
+ <value>password</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>common</group-name>
+ <option>
+ <name>userContainerDN</name>
+ <value>ou=People,dc=jboss,dc=org</value>
+ </option>
+ <option>
+ <name>uidAttributeId</name>
+ <value>uid</value>
+ </option>
+ <option>
+ <name>roleContainerDN</name>
+ <value>ou=Roles,dc=jboss,dc=org</value>
+ </option>
+ <option>
+ <name>ridAttributeId</name>
+ <value>cn</value>
+ </option>
+ <option>
+ <name>roleDisplayNameAttributeID</name>
+ <value>cn</value>
+ </option>
+ <option>
+ <name>roleMemberAttributeID</name>
+ <value>member</value>
+ </option>
+ <option>
+ <name>memberAttributeIsDN</name>
+ <value>true</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>userCreateAttibutes</group-name>
+ <option>
+ <name>objectClass</name>
+ <value>top</value>
+ <value>uidObject</value>
+ <value>person</value>
+ </option>
+ <!--Schema requires those to have initial value-->
+ <option>
+ <name>cn</name>
+ <value>none</value>
+ </option>
+ <option>
+ <name>sn</name>
+ <value>none</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>roleCreateAttibutes</group-name>
+ <option>
+ <name>objectClass</name>
+ <value>top</value>
+ <value>groupOfNames</value>
+ </option>
+ <!--Schema requires those to have initial value-->
+ <option>
+ <name>cn</name>
+ <value>none</value>
+ </option>
+ <!--Some directory servers require this attribute to be valid DN-->
+ <!--For safety reasons point to the admin user here-->
+ <option>
+ <name>member</name>
+ <value>uid=dummynonexistinguser,ou=People,dc=jboss,dc=org</value>
+ </option>
+ </option-group>
+</identity-configuration>
\ No newline at end of file
Added: trunk/test/src/etc/identityconfig/test-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/test-config.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/etc/identityconfig/test-config.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<identity-configuration>
+ <option-group>
+ <group-name>connection</group-name>
+ <option>
+ <name>host</name>
+ <value>localhost</value>
+ </option>
+ <option>
+ <name>port</name>
+ <value>10389</value>
+ </option>
+ <option>
+ <name>context-factory</name>
+ <value>com.sun.jndi.ldap.LdapCtxFactory</value>
+ </option>
+ <option>
+ <name>admin-dn</name>
+ <value>cn=Directory Manager</value>
+ </option>
+ <option>
+ <name>admin-password</name>
+ <value>password</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>common</group-name>
+ <option>
+ <name>user.containerDN</name>
+ <value>ou=People,dc=jboss,dc=com</value>
+ </option>
+ <option>
+ <name>user.uidAttributeId</name>
+ <value>uid</value>
+ </option>
+ <option>
+ <name>role.containerDN</name>
+ <value>ou=Role,dc=jboss,dc=com</value>
+ </option>
+ <option>
+ <name>role.ridAttributeId</name>
+ <value>cn</value>
+ </option>
+ <option>
+ <name>role.displayNameAttributeID</name>
+ <value>xxx</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>user.createAttibutes</group-name>
+ <option>
+ <name>objectClass</name>
+ <value>top</value>
+ <value>uidObject</value>
+ <value>person</value>
+ </option>
+ <option>
+ <name>extraSchemaAtrribute</name>
+ <value>extraValue</value>
+ </option>
+ </option-group>
+</identity-configuration>
\ No newline at end of file
Added: trunk/test/src/etc/identityconfig/test2-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/test2-config.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/etc/identityconfig/test2-config.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<identity-configuration>
+ <modules>
+ <module>
+ <!--type used to correctly map in IdentityContext registry-->
+ <type>UserModule</type>
+
+ <!--name of service and class for creating mbean-->
+ <service-name>portal:service=Module,type=User</service-name>
+ <class>org.jboss.portal.identity.db.DBUserModuleImp</class>
+ <jndi-name>java:/portal/UserModule</jndi-name>
+
+ <!--set of options that are passed to a class constructor-->
+ <config>
+ <option>
+ <name>SessionFactoryJNDIName</name>
+ <value>java:/portal/UserSessionFactory</value>
+ </option>
+ <option>
+ <name>HibernateConfigLocation</name>
+ <value>conf/hibernate/user/hibernate.cfg.xml</value>
+ </option>
+ <option>
+ <name>HibernateSetupLocation</name>
+ <value>conf/hibernate/user/setup.txt</value>
+ </option>
+ <!--other set of options needed by the module...-->
+ </config>
+ </module>
+
+ ...
+ <!--similar sections for role, membership and user profile modules-->
+ ...
+
+ <!--example for ldap module...-->
+ <module>
+ <!--type used to correctly map in IdentityContext registry-->
+ <type>RoleModule</type>
+
+ <!--name of service and class for creating mbean-->
+ <service-name>portal:service=Module,type=Role</service-name>
+ <class>org.jboss.portal.identity.ldap.LDAPUserModuleImp</class>
+ <jndi-name>java:/portal/RoleModule</jndi-name>
+
+ <!--set of options that are passed to a class constructor-->
+ <config>
+ <option>
+ <name>LDAPConnectionJNDIName</name>
+ <value>java:/portal/UserSessionFactory</value>
+ </option>
+ </config>
+ </module>
+
+ <!--For ldap configuration this is needed additionally to use ldap connection...-->
+ <module>
+ <!--type used to correctly map in IdentityContext registry-->
+ <type>LDAPContextModule</type>
+
+ <!--name of service and class for creating mbean-->
+ <service-name>portal:service=Module,type=LDAPContext</service-name>
+ <class>org.jboss.portal.identity.ldap.LDAPContextImp</class>
+ <jndi-name>java:/portal/LDAPContext</jndi-name>
+
+ <!--set of options that are passed to a class constructor-->
+ <config>
+ <option>
+ <name>host</name>
+ <value>localhost</value>
+ </option>
+ <option>
+ <name>port</name>
+ <value>10389</value>
+ </option>
+ <option>
+ <name>context-factory</name>
+ <value>com.sun.jndi.ldap.LdapCtxFactory</value>
+ </option>
+ <option>
+ <name>admin-dn</name>
+ <value>cn=Directory Manager</value>
+ </option>
+ <option>
+ <name>admin-password</name>
+ <value>password</value>
+ </option>
+ <option>
+ <name>authentication</name>
+ <value>simple</value>
+ </option>
+ </config>
+ </module>
+ </modules>
+
+
+ <!--Common options section-->
+ <options>
+ <option-group>
+ <group-name>common</group-name>
+ <option>
+ <name>userContainerDN</name>
+ <value>ou=People,dc=jboss,dc=com</value>
+ </option>
+ <option>
+ <name>uidAttributeId</name>
+ <value>uid</value>
+ </option>
+ <option>
+ <name>roleContainerDN</name>
+ <value>ou=Role,dc=jboss,dc=com</value>
+ </option>
+ <option>
+ <name>ridAttributeId</name>
+ <value>cn</value>
+ </option>
+ <option>
+ <name>roleDisplayNameAttributeID</name>
+ <value>xxx</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>userCreateAttibutes</group-name>
+ <option>
+ <name>objectClass</name>
+ <value>top</value>
+ <value>uidObject</value>
+ <value>person</value>
+ </option>
+ <option>
+ <name>extraSchemaAtrribute</name>
+ <value>extraValue</value>
+ </option>
+ </option-group>
+ <option-group>
+ <group-name>roleCreateAttibutes</group-name>
+ <option>
+ <name>objectClass</name>
+ <value>top</value>
+ <value>groupOfNames</value>
+ </option>
+ <option>
+ <name>extraSchemaAtrribute</name>
+ <value>extraValue</value>
+ </option>
+ </option-group>
+ </options>
+</identity-configuration>
\ No newline at end of file
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-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -49,33 +49,66 @@
private String description;
- private String providerUrl;
+ private String host;
+ private String port;
+
private String contextFactory;
private String adminDN;
private String adminPassword;
- private boolean useEmbedded;
+ //private boolean useEmbedded;
+ private String configFile;
+
private String populateLdif;
private String cleanUpDN;
- public DSConfig(String name, String description, String url, String contextFactory, String adminDN, String adminPass, boolean useEmbedded, String populateLdif, String cleanUpDN)
+ public DSConfig(String name, String description, String host, String port, String contextFactory, String adminDN, String adminPass, String configFile, String populateLdif, String cleanUpDN)
{
this.name = name;
this.description = description;
- this.providerUrl = url;
+ this.host = host;
+ this.port = port;
this.contextFactory = contextFactory;
this.adminDN = adminDN;
this.adminPassword = adminPass;
- this.useEmbedded = useEmbedded;
+ this.configFile = configFile;
this.populateLdif = populateLdif;
this.cleanUpDN = cleanUpDN;
}
+ /*public DSConfig(String name, String description, String configFile, String populateLdif, String cleanUpDN)
+ {
+ this.name = name;
+ this.description = description;
+ *//*this.host = host;
+ this.port = port;
+ this.contextFactory = contextFactory;
+ this.adminDN = adminDN;
+ this.adminPassword = adminPass;
+ this.useEmbedded = useEmbedded;*//*
+ this.configFile = configFile;
+ this.populateLdif = populateLdif;
+ this.cleanUpDN = cleanUpDN;
+ }*/
+
+ public String toString()
+ {
+ return new StringBuffer().append(name).
+ append("_").
+ append(description).
+ append(host).
+ append(":").
+ append(port).
+ append(":").
+ append(configFile).
+ toString();
+ }
+
public static MultiValuedTestParameterValue fromXML2(URL url) throws Exception
{
DSConfig[] configs = fromXML(url);
@@ -96,34 +129,45 @@
Element childElt = (Element)i.next();
Element nm = XML.getUniqueChild(childElt, "name", true);
Element desc = XML.getUniqueChild(childElt, "description", true);
- Element purl = XML.getUniqueChild(childElt, "provider-url", true);
+ Element config = XML.getUniqueChild(childElt, "config-file", true);
+ Element h = XML.getUniqueChild(childElt, "host", true);
+ Element p = XML.getUniqueChild(childElt, "port", true);
Element context = XML.getUniqueChild(childElt, "context-factory", true);
Element admin = XML.getUniqueChild(childElt, "admin-dn", true);
Element password = XML.getUniqueChild(childElt, "admin-password", true);
- Element embedded = XML.getUniqueChild(childElt, "use-embedded", true);
+ //Element embedded = XML.getUniqueChild(childElt, "use-embedded", true);
Element populate = XML.getUniqueChild(childElt, "populate-ldif", true);
Element cleanup = XML.getUniqueChild(childElt, "cleanup-dn", true);
String name = XML.asString(nm);
String description = XML.asString(desc);
- String providerURL = XML.asString(purl);
+ String configFile = XML.asString(config);
+ String host = XML.asString(h);
+ String port = XML.asString(p);
String contextFactory = XML.asString(context);
String adminDN = XML.asString(admin);
String adminPassword = XML.asString(password);
- boolean embedd = XML.asString(embedded).equals("true");
+ //boolean embedd = XML.asString(embedded).equals("true");
String populateLdif = XML.asString(populate);
String cleanUpDN = XML.asString(cleanup);
DSConfig dsCfg = new DSConfig(
name,
description,
- providerURL,
+ host,
+ port,
contextFactory,
adminDN,
adminPassword,
- embedd,
+ configFile,
populateLdif,
cleanUpDN);
+ /*DSConfig dsCfg = new DSConfig(
+ name,
+ description,
+ configFile,
+ populateLdif,
+ cleanUpDN);*/
configs.add(dsCfg);
}
return (DSConfig[])configs.toArray(new DSConfig[configs.size()]);
@@ -134,16 +178,24 @@
}
}
- public String getProviderUrl()
+ public String getURL()
{
- return providerUrl;
+ return new StringBuffer("ldap://").append(getHost())
+ .append(":")
+ .append(getPort())
+ .toString();
}
- public void setProviderUrl(String providerUrl)
+ public String getHost()
{
- this.providerUrl = providerUrl;
+ return host;
}
+ public void setHost(String host)
+ {
+ this.host = host;
+ }
+
public String getContextFactory()
{
return contextFactory;
@@ -194,7 +246,7 @@
this.description = description;
}
- public boolean isUseEmbedded()
+ /*public boolean isUseEmbedded()
{
return useEmbedded;
}
@@ -202,7 +254,7 @@
public void setUseEmbedded(boolean useEmbedded)
{
this.useEmbedded = useEmbedded;
- }
+ }*/
public String getPopulateLdif()
{
@@ -224,4 +276,24 @@
this.cleanUpDN = cleanUpDN;
}
+ public String getPort()
+ {
+ return port;
+ }
+
+ public void setPort(String port)
+ {
+ this.port = port;
+ }
+
+ public String getConfigFile()
+ {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile)
+ {
+ this.configFile = configFile;
+ }
+
}
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/opends/OpenDSService.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/opends/OpenDSService.java 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/opends/OpenDSService.java 2006-11-08 17:46:41 UTC (rev 5604)
@@ -96,7 +96,7 @@
public void stopService() throws Exception
{
- log.debug("Asking DS to shutdown");
+ log.info("Asking DS to shutdown");
DirectoryServer.shutDown(getClass().getName(), "Shut down DS");
}
Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml 2006-11-08 17:44:42 UTC (rev 5603)
+++ trunk/testsuite/build.xml 2006-11-08 17:46:41 UTC (rev 5604)
@@ -130,9 +130,9 @@
<antcall target="internal-test-module">
<param name="module" value="security"/>
</antcall>
- <!--<antcall target="internal-test-module">
+ <antcall target="internal-test-module">
<param name="module" value="identity"/>
- </antcall>-->
+ </antcall>
<antcall target="internal-test-module">
<param name="module" value="server"/>
</antcall>
@@ -204,7 +204,17 @@
<undeploy file="../test/output/lib/portal-test.sar" config="default"/>
</target>
- <target name="help">
+
+ <!--<target name="deploy-identity">
+ <ant antfile="../identity/build.xml" output="output.log" dir="../identity" target="deploy-ldap"/>
+ </target>
+
+
+ <target name="undeploy-identity">
+ <ant antfile="../identity/build.xml" output="output.log" dir="../identity" target="undeploy-ldap"/>
+ </target>-->
+
+ <target name="help">
<echo message="To run individual module tests use the test-module target with -Dmodule=the module you want to test,
e.g. ant -Dmodule=portlet test-module"/>
</target>
More information about the jboss-svn-commits
mailing list