Added initial version of SimpleLdapTemplate in new project; spring-ldap-tiger.
This commit is contained in:
51
spring-ldap-tiger/.classpath
Normal file
51
spring-ldap-tiger/.classpath
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="src" path="src/itest/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/global/commons-lang.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/commons-logging.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/ldapbp.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/spring-beans.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/spring-context.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/spring-core.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/spring-dao.jar"/>
|
||||
<classpathentry kind="lib" path="lib/global/spring-ldap.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/antlr.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-core-shared.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-core.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-kerberos-shared.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-protocol-changepw.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-protocol-kerberos.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-protocol-ldap.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-protocol-shared.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-server-jndi.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/apacheds-server-main.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/backport-util-concurrent.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/cglib-nodep.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/clover.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/commons-collections.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/commons-logging.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/DDSteps.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/easymock.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/ehcache-constructs.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/ehcache.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/gsbase.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/jdbm.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/junit-addons.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/junit.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/junitperf.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/jxl.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/log4j.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/mina-core.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/mina-filter-ssl.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/shared-asn1-codec.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/shared-asn1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/shared-ldap.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/slf4j-log4j12.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/spring-mock.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/xercesImpl.jar"/>
|
||||
<classpathentry kind="lib" path="lib/test/xmlParserAPIs.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
spring-ldap-tiger/.project
Normal file
17
spring-ldap-tiger/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>spring-ldap-tiger</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
85
spring-ldap-tiger/build.xml
Normal file
85
spring-ldap-tiger/build.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project name="spring-ldap-tiger" default="dist">
|
||||
|
||||
<property file="build.properties" />
|
||||
<property file="project.properties" />
|
||||
<property file="${common.build.dir}/build.properties" />
|
||||
<property file="${common.build.dir}/project.properties" />
|
||||
<property file="${user.home}/build.properties" />
|
||||
|
||||
<property name="project.title" value="Spring LDAP Tiger" />
|
||||
<property name="project.package" value="org.springframework.ldap" />
|
||||
|
||||
<property name="ldap.server" value="127.0.0.1" />
|
||||
<property name="ldap.user" value=""cn=Manager,dc=jayway,dc=se"" />
|
||||
<property name="ldap.password" value="secret" />
|
||||
|
||||
<!-- Cannot import common-targets since itest-targets already does -->
|
||||
<import file="${common.build.dir}/itest-targets.xml" />
|
||||
<import file="${common.build.dir}/common-targets.xml" />
|
||||
<import file="${common.build.dir}/clover-targets.xml" />
|
||||
<import file="${common.build.dir}/jdiff-targets.xml" />
|
||||
|
||||
<!-- extend common-build with source capability -->
|
||||
<target name="build.prepare.make.config.dirs" depends="common-targets.build.prepare.make.config.dirs">
|
||||
<mkdir dir="${lib.dir}/source" />
|
||||
</target>
|
||||
|
||||
<!--
|
||||
Overridden to create test report and run integration tests as well.
|
||||
-->
|
||||
<target name="tests" depends="tests-local,test-report,itests,itest-report" description="Runs all tests, first local then server (if any)" />
|
||||
|
||||
<!--
|
||||
Overridden only to have the errorproperty and failureproperty attributes
|
||||
added to the junit task.
|
||||
-->
|
||||
<!-- Runs the local unit tests. -->
|
||||
<target name="tests-local" depends="tests.prepare" description="Run all local tests">
|
||||
<!-- for the time being we just halt on failure, since these are
|
||||
local tests and there is no server to shut down, etc. But if
|
||||
we want to optionally run all tests and report on the whole
|
||||
batch, then we need to set a failure property as in the server
|
||||
tests. -->
|
||||
<junit forkmode="perBatch" printsummary="yes" haltonfailure="no" haltonerror="no" dir="${basedir}" errorproperty="tests.failed" failureproperty="tests.failed">
|
||||
<jvmarg value="${unitvm}" />
|
||||
<jvmarg value="-Djava.security.auth.login.config=${target.testclasses.dir}/auth.conf" />
|
||||
<jvmarg value="${test.arguments}" />
|
||||
<classpath>
|
||||
<pathelement location="${target.classes.dir}" />
|
||||
<pathelement location="${target.testclasses.dir}" />
|
||||
<pathelement location="${target.genclasses.dir}" />
|
||||
<path refid="test.classpath" />
|
||||
</classpath>
|
||||
|
||||
<formatter type="plain" />
|
||||
<formatter type="xml" />
|
||||
|
||||
<batchtest fork="yes" todir="${target.testresults.dir}">
|
||||
<fileset dir="${target.testclasses.dir}" includes="${test.includes}" excludes="${test.excludes}" />
|
||||
</batchtest>
|
||||
</junit>
|
||||
|
||||
</target>
|
||||
|
||||
<property name="target.testresults.html.dir" location="${target.testresults.dir}/html" />
|
||||
|
||||
<!-- Generate the unit test report -->
|
||||
<target name="test-report" depends="build.prepare" description="Generate HTML report of unit test results">
|
||||
<delete dir="${target.testresults.html.dir}" />
|
||||
<mkdir dir="${target.testresults.html.dir}" />
|
||||
<junitreport todir="${target.testresults.html.dir}">
|
||||
<fileset dir="${target.testresults.dir}">
|
||||
<include name="TEST-*.xml" />
|
||||
</fileset>
|
||||
<report format="frames" todir="${target.testresults.html.dir}" />
|
||||
</junitreport>
|
||||
<echo>
|
||||
Unit test report has been generated.
|
||||
The HTML report is ${target.testresults.html.dir}/index.html
|
||||
</echo>
|
||||
<fail if="tests.failed" message="Unit tests failed" />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
96
spring-ldap-tiger/ivy.xml
Normal file
96
spring-ldap-tiger/ivy.xml
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ivy-module version="1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://www.jayasoft.org/misc/ivy/samples/ivy.xsd">
|
||||
|
||||
<info organisation="org.springframework" module="spring-ldap-tiger" />
|
||||
|
||||
<configurations>
|
||||
<conf name="default" extends="global" />
|
||||
<conf name="global" visibility="private" />
|
||||
<conf name="buildtime" visibility="private" />
|
||||
<conf name="test" visibility="private" />
|
||||
<conf name="source" visibility="public" />
|
||||
</configurations>
|
||||
|
||||
<publications>
|
||||
<artifact name="spring-ldap-tiger" type="jar" conf="default" />
|
||||
<artifact name="spring-ldap-tiger-src" type="zip" conf="source" />
|
||||
</publications>
|
||||
|
||||
<dependencies defaultconf="global->default">
|
||||
<dependency org="org.springframework" name="spring-ldap"
|
||||
rev="latest.integration" />
|
||||
|
||||
<!-- test time only dependencies -->
|
||||
<dependency org="commons-collections" name="commons-collections"
|
||||
rev="3.1" conf="test->default" />
|
||||
<dependency org="com.cenqua.clover" name="clover" rev="1.3.12"
|
||||
conf="test->default" />
|
||||
<dependency org="org.springframework" name="spring-mock"
|
||||
rev="2.0.4" conf="test->default" />
|
||||
<dependency org="gsbase" name="gsbase" rev="2.0.1"
|
||||
conf="test->default" />
|
||||
<dependency org="junit" name="junit" rev="3.8.1"
|
||||
conf="test->default" />
|
||||
<dependency org="junit-addons" name="junit-addons" rev="1.4"
|
||||
conf="test->default" />
|
||||
<dependency org="junitperf" name="junitperf" rev="1.8"
|
||||
conf="test->default" />
|
||||
<dependency org="easymock" name="easymock" rev="2.0"
|
||||
conf="test->default" />
|
||||
<dependency org="ehcache" name="ehcache" rev="1.1"
|
||||
conf="test->default" />
|
||||
<dependency org="net.sf.ehcache" name="ehcache-constructs"
|
||||
rev="0.6" conf="test->default" />
|
||||
<dependency org="jexcelapi" name="jxl" rev="2.5.9"
|
||||
conf="test->default" />
|
||||
<dependency org="org.ddsteps" name="DDSteps" rev="1.1"
|
||||
conf="test->default" />
|
||||
<dependency org="cglib" name="cglib-nodep" rev="2.1_3"
|
||||
conf="test->default" />
|
||||
|
||||
<!-- Test dependencies for Apache Directory Server -->
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-core" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-core-shared" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-server-jndi" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-server-main" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-protocol-shared" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-protocol-changepw" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-protocol-kerberos" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-kerberos-shared" rev="1.0.0" conf="test->default" />
|
||||
<dependency org="org.apache.directory.server"
|
||||
name="apacheds-protocol-ldap" rev="1.0.0" conf="test->default" />
|
||||
|
||||
<dependency org="org.apache.directory.shared" name="shared-asn1"
|
||||
rev="0.9.5.3" conf="test->default" />
|
||||
<dependency org="org.apache.directory.shared"
|
||||
name="shared-asn1-codec" rev="0.9.5.3" conf="test->default" />
|
||||
<dependency org="org.apache.directory.shared" name="shared-ldap"
|
||||
rev="0.9.5.3" conf="test->default" />
|
||||
|
||||
<dependency org="log4j" name="log4j" rev="1.2.9"
|
||||
conf="test->default" />
|
||||
<dependency org="antlr" name="antlr" rev="2.7.2"
|
||||
conf="test->default" />
|
||||
<dependency org="jdbm" name="jdbm" rev="1.0"
|
||||
conf="test->default" />
|
||||
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.0"
|
||||
conf="test->default" />
|
||||
<dependency org="org.apache.mina" name="mina-core" rev="1.0.0"
|
||||
conf="test->default" />
|
||||
<dependency org="org.apache.mina" name="mina-filter-ssl"
|
||||
rev="1.0.0" conf="test->default" />
|
||||
<!-- End test dependencies for Apache Directory Server -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
</ivy-module>
|
||||
14
spring-ldap-tiger/project.properties
Normal file
14
spring-ldap-tiger/project.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# properties defined in this file are overridable by a local build.properties in this project dir
|
||||
|
||||
# The location of the common build system
|
||||
common.build.dir=${basedir}/../common-build
|
||||
|
||||
project.base.version=1.2-RC2
|
||||
#project.version=${project.base.version}
|
||||
#ivy.status=release
|
||||
|
||||
javac.source=1.5
|
||||
javac.target=1.5
|
||||
|
||||
# extend common-build with source capability
|
||||
main.build.configs=global,buildtime,test,source
|
||||
84
spring-ldap-tiger/src/itest/java/conf/apacheDsContext.xml
Normal file
84
spring-ldap-tiger/src/itest/java/conf/apacheDsContext.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
This context automatically starts the Apache Directory Server
|
||||
and sets up the test data
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<!-- JNDI environment variable -->
|
||||
<bean id="environment"
|
||||
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="java.naming.security.authentication">
|
||||
simple
|
||||
</prop>
|
||||
<prop key="java.naming.security.principal">
|
||||
${userDn}
|
||||
</prop>
|
||||
<prop key="java.naming.security.credentials">
|
||||
${password}
|
||||
</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Note the non-standard port, in order to leave 389 unused, thus
|
||||
making it easier for the integration tests requiring OpenLDAP.
|
||||
-->
|
||||
<bean id="configuration" class="org.apache.directory.server.configuration.MutableServerStartupConfiguration">
|
||||
<property name="ldapPort" value="3900" />
|
||||
<property name="contextPartitionConfigurations">
|
||||
<set>
|
||||
<ref bean="jaywayPartitionConfiguration"/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jaywayPartitionConfiguration"
|
||||
class="org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration">
|
||||
<property name="name" value="jayway" />
|
||||
<property name="suffix" value="dc=jayway,dc=se" />
|
||||
<property name="contextEntry">
|
||||
<value>
|
||||
objectClass: top
|
||||
objectClass: domain
|
||||
objectClass: extensibleObject
|
||||
dc: jayway
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="configEnvHelper" class="org.springframework.ldap.ConfigEnvHelper">
|
||||
<constructor-arg ref="environment" />
|
||||
<constructor-arg ref="configuration" />
|
||||
</bean>
|
||||
|
||||
<bean name="serverContext" class="javax.naming.InitialContext">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
|
||||
<property name="targetObject" ref="configEnvHelper" />
|
||||
<property name="propertyPath" value="env" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean name="ldapServerManager" class="org.springframework.ldap.LdapServerManager">
|
||||
<property name="contextSource" ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<!-- Custom editors required to launch ApacheDS -->
|
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
<entry key="javax.naming.directory.Attributes">
|
||||
<bean class="org.apache.directory.server.core.configuration.AttributesPropertyEditor"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
4
spring-ldap-tiger/src/itest/java/conf/ldap.properties
Normal file
4
spring-ldap-tiger/src/itest/java/conf/ldap.properties
Normal file
@@ -0,0 +1,4 @@
|
||||
urls=ldap://127.0.0.1:3900
|
||||
userDn=uid=admin,ou=system
|
||||
password=secret
|
||||
base=dc=jayway,dc=se
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/apacheDsContext.xml"/>
|
||||
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/conf/ldap.properties" />
|
||||
</bean>
|
||||
|
||||
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource" >
|
||||
<property name="urls" value="${urls}" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="base" value="${base}" />
|
||||
<property name="dirObjectFactory" value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="simpleLdapTemplate" class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
|
||||
<constructor-arg ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
|
||||
</beans>
|
||||
9
spring-ldap-tiger/src/itest/java/log4j.properties
Normal file
9
spring-ldap-tiger/src/itest/java/log4j.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
log4j.rootCategory=WARN, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
||||
|
||||
#Enable debug logging
|
||||
log4j.category.net.sf.ldaptemplate=INFO
|
||||
log4j.category.net.sf.ldaptemplate.LdapTemplate=DEBUG
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
public abstract class AbstractLdapTemplateIntegrationTest extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private LdapServerManager ldapServerManager;
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
|
||||
ldapServerManager.cleanAndSetup("setup_data.ldif");
|
||||
}
|
||||
|
||||
public void setLdapServerManager(LdapServerManager ldapServerManager) {
|
||||
this.ldapServerManager = ldapServerManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
|
||||
import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
|
||||
import org.apache.directory.server.jndi.ServerContextFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* Helper class to simplify Spring configuration of ApacheDS.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class ConfigEnvHelper implements InitializingBean {
|
||||
private final MutableServerStartupConfiguration configuration;
|
||||
|
||||
private final Hashtable initialEnv;
|
||||
|
||||
private final File workingDir = new File(System
|
||||
.getProperty("java.io.tmpdir")
|
||||
+ File.separator + "ldaptemplate_apacheds");
|
||||
|
||||
public ConfigEnvHelper(Hashtable initialEnv,
|
||||
MutableServerStartupConfiguration configuration) {
|
||||
|
||||
this.initialEnv = initialEnv;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public Hashtable getEnv() {
|
||||
return initialEnv;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
initialEnv.put(Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName());
|
||||
configuration.setWorkingDirectory(workingDir);
|
||||
initialEnv.putAll(configuration.toJndiEnvironment());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.ContextNotEmptyException;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.directory.server.core.configuration.ShutdownConfiguration;
|
||||
import org.apache.directory.server.jndi.ServerContextFactory;
|
||||
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
|
||||
|
||||
/**
|
||||
* Utility class to initialize the apache directory server for use in the
|
||||
* integration tests.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*
|
||||
*/
|
||||
public class LdapServerManager implements DisposableBean {
|
||||
private static Log log = LogFactory.getLog(LdapServerManager.class);
|
||||
|
||||
private ContextSource contextSource;
|
||||
|
||||
public void setContextSource(ContextSource contextSource) {
|
||||
this.contextSource = contextSource;
|
||||
}
|
||||
|
||||
public void destroy() throws Exception {
|
||||
Properties env = new Properties();
|
||||
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
ServerContextFactory.class.getName());
|
||||
env.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
|
||||
env.setProperty(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
|
||||
env.setProperty(Context.SECURITY_CREDENTIALS, "secret");
|
||||
|
||||
ShutdownConfiguration configuration = new ShutdownConfiguration();
|
||||
env.putAll(configuration.toJndiEnvironment());
|
||||
|
||||
new InitialContext(env);
|
||||
}
|
||||
|
||||
public void cleanAndSetup(String ldifFile) throws Exception {
|
||||
DirContext ctx = contextSource.getReadWriteContext();
|
||||
|
||||
// First of all, make sure the database is empty.
|
||||
Name startingPoint = null;
|
||||
|
||||
// Different test cases have different base paths. This means that the
|
||||
// starting point will be different.
|
||||
if (ctx.getEnvironment().get(
|
||||
DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY) != null) {
|
||||
startingPoint = DistinguishedName.EMPTY_PATH;
|
||||
} else {
|
||||
startingPoint = new DistinguishedName("dc=jayway,dc=se");
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("Cleaning all present data.");
|
||||
clearSubContexts(ctx, startingPoint);
|
||||
// Load the ldif to the recently started server
|
||||
log.info("Loading setup data");
|
||||
LdifFileLoader loader = new LdifFileLoader(ctx, ldifFile);
|
||||
loader.execute();
|
||||
} finally {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void clearSubContexts(DirContext ctx, Name name)
|
||||
throws NamingException {
|
||||
|
||||
NamingEnumeration enumeration = null;
|
||||
try {
|
||||
enumeration = ctx.listBindings(name);
|
||||
while (enumeration.hasMore()) {
|
||||
Binding element = (Binding) enumeration.next();
|
||||
DistinguishedName childName = new DistinguishedName(element
|
||||
.getName());
|
||||
childName.prepend((DistinguishedName) name);
|
||||
|
||||
try {
|
||||
ctx.destroySubcontext(childName);
|
||||
} catch (ContextNotEmptyException e) {
|
||||
clearSubContexts(ctx, childName);
|
||||
ctx.destroySubcontext(childName);
|
||||
}
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
enumeration.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.springframework.ldap.core.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
|
||||
public class SimpleLdapTemplateTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private SimpleLdapTemplate ldapTemplate;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "/conf/ldapTemplateTestContext.xml" };
|
||||
}
|
||||
|
||||
public void setSimplLdapTemplate(SimpleLdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
public void testLookup() {
|
||||
String result = ldapTemplate.lookup("cn=Some Person,ou=company1,c=Sweden", new CnContextMapper());
|
||||
assertEquals("Some Person", result);
|
||||
}
|
||||
|
||||
public void testSearch1() {
|
||||
List<String> cns = ldapTemplate.search("", "(&(objectclass=person)(sn=Person3))", new CnContextMapper());
|
||||
|
||||
assertEquals(1, cns.size());
|
||||
assertEquals("Some Person3", cns.get(0));
|
||||
}
|
||||
|
||||
private static class CnContextMapper implements ParametrizedContextMapper<String> {
|
||||
|
||||
public String mapFromContext(Object ctx) {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx;
|
||||
|
||||
return adapter.getStringAttribute("cn");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
110
spring-ldap-tiger/src/itest/java/setup_data.ldif
Normal file
110
spring-ldap-tiger/src/itest/java/setup_data.ldif
Normal file
@@ -0,0 +1,110 @@
|
||||
dn: ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: groups
|
||||
|
||||
dn: cn=ROLE_USER,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_USER
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: cn=ROLE_ADMIN,ou=groups,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: groupOfUniqueNames
|
||||
cn: ROLE_ADMIN
|
||||
uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Norway
|
||||
description: The country of Norway
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
dn: ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company2
|
||||
description: Second company in Sweden
|
||||
|
||||
dn: ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Norway
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company1, Some Person
|
||||
telephoneNumber: +46 555-123456
|
||||
|
||||
dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person2
|
||||
userPassword: password
|
||||
cn: Some Person2
|
||||
sn: Person2
|
||||
description: Sweden, Company1, Some Person2
|
||||
telephoneNumber: +46 555-654321
|
||||
|
||||
dn: cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person3
|
||||
userPassword: password
|
||||
cn: Some Person3
|
||||
sn: Person3
|
||||
description: Sweden, Company1, Some Person3
|
||||
telephoneNumber: +46 555-123654
|
||||
|
||||
dn: cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person4
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company2, Some Person
|
||||
telephoneNumber: +46 555-456321
|
||||
|
||||
dn: cn=Some Person+sn=Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.norwegian
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Norway, Company1, Some Person+Person
|
||||
telephoneNumber: +45 555-654123
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.ldap.core.simple;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
|
||||
/**
|
||||
* Extension of the {@link ContextMapper} interface. Uses Java 5 covariant
|
||||
* return types to override the return type of the
|
||||
* {@link #mapFromContext(Object)} method to be the type parameter T.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface ParametrizedContextMapper<T> extends ContextMapper {
|
||||
|
||||
/**
|
||||
* Map a single LDAP Context to an object. The supplied Object
|
||||
* <code>ctx</code> is the object from a single {@link SearchResult},
|
||||
* {@link Binding}, or a lookup operation.
|
||||
*
|
||||
* @param ctx the context to map to an object.
|
||||
* @return an object built from the data in the context.
|
||||
*/
|
||||
public T mapFromContext(Object ctx);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.springframework.ldap.core.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.core.DirContextProcessor;
|
||||
import org.springframework.ldap.core.LdapOperations;
|
||||
|
||||
public interface SimpleLdapOperations {
|
||||
|
||||
LdapOperations getLdapOperations();
|
||||
|
||||
<T> List<T> search(String base, String filter, ParametrizedContextMapper<T> mapper);
|
||||
|
||||
<T> List<T> search(String base, String filter, SearchControls controls, ParametrizedContextMapper<T> mapper,
|
||||
DirContextProcessor processor);
|
||||
|
||||
<T> T lookup(String dn, ParametrizedContextMapper<T> mapper);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.springframework.ldap.core.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.directory.SearchControls;
|
||||
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DirContextProcessor;
|
||||
import org.springframework.ldap.core.LdapOperations;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
|
||||
public class SimpleLdapTemplate implements SimpleLdapOperations {
|
||||
|
||||
private LdapOperations ldapOperations;
|
||||
|
||||
public SimpleLdapTemplate(LdapOperations ldapOperations) {
|
||||
this.ldapOperations = ldapOperations;
|
||||
}
|
||||
|
||||
public SimpleLdapTemplate(ContextSource contextSource) {
|
||||
this.ldapOperations = new LdapTemplate(contextSource);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.simple.SimpleLdapOperations#getLdapOperations()
|
||||
*/
|
||||
public LdapOperations getLdapOperations() {
|
||||
return ldapOperations;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.simple.SimpleLdapOperations#lookup(java.lang.String,
|
||||
* org.springframework.ldap.core.simple.ParametrizedContextMapper)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T lookup(String dn, ParametrizedContextMapper<T> mapper) {
|
||||
return (T) ldapOperations.lookup(dn, mapper);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.simple.SimpleLdapOperations#search(java.lang.String,
|
||||
* java.lang.String,
|
||||
* org.springframework.ldap.core.simple.ParametrizedContextMapper)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> search(String base, String filter, ParametrizedContextMapper<T> mapper) {
|
||||
return ldapOperations.search(base, filter, mapper);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.ldap.core.simple.SimpleLdapOperations#search(java.lang.String,
|
||||
* java.lang.String, javax.naming.directory.SearchControls,
|
||||
* org.springframework.ldap.core.simple.ParametrizedContextMapper,
|
||||
* org.springframework.ldap.core.DirContextProcessor)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> search(String base, String filter, SearchControls controls, ParametrizedContextMapper<T> mapper,
|
||||
DirContextProcessor processor) {
|
||||
return ldapOperations.search(base, filter, controls, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user