Reverted to apache ds 1.0.2 and added article sample.
This commit is contained in:
50
mvn-build/samples/samples-utils/pom.xml
Normal file
50
mvn-build/samples/samples-utils/pom.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>spring-ldap-samples-utils</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
<name>Spring LDAP utilities for samples</name>
|
||||
<parent>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>master</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>spring-ldap-tiger</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>spring-ldap-test</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public class HtmlRowLdapTreeVisitor implements LdapTreeVisitor {
|
||||
|
||||
private List<String> rows = new LinkedList<String>();
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < currentDepth; i++) {
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
sb.append(node.getDn()).append("<br>\n");
|
||||
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public List<String> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public class LdapTree {
|
||||
private final DirContextOperations node;
|
||||
|
||||
private List<LdapTree> subContexts = new LinkedList<LdapTree>();
|
||||
|
||||
public LdapTree(DirContextOperations node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public DirContextOperations getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public List<LdapTree> getSubContexts() {
|
||||
return subContexts;
|
||||
}
|
||||
|
||||
public void setSubContexts(List<LdapTree> subContexts) {
|
||||
this.subContexts = subContexts;
|
||||
}
|
||||
|
||||
public void addSubTree(LdapTree ldapTree) {
|
||||
subContexts.add(ldapTree);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void traverse(LdapTreeVisitor visitor) {
|
||||
traverse(visitor, 0);
|
||||
}
|
||||
|
||||
private void traverse(LdapTreeVisitor visitor, int currentDepth) {
|
||||
visitor.visit(node, currentDepth);
|
||||
for (LdapTree subContext : subContexts) {
|
||||
subContext.traverse(visitor, currentDepth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
|
||||
public class LdapTreeBuilder {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public LdapTreeBuilder(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
public LdapTree getLdapTree(DistinguishedName root) {
|
||||
DirContextOperations context = ldapTemplate.lookupContext(root.toString());
|
||||
return getLdapTree(context);
|
||||
}
|
||||
|
||||
private LdapTree getLdapTree(final DirContextOperations rootContext) {
|
||||
final LdapTree ldapTree = new LdapTree(rootContext);
|
||||
ldapTemplate.listBindings(rootContext.getDn(), new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
DistinguishedName dn = (DistinguishedName) ctx.getDn();
|
||||
dn.prepend((DistinguishedName) rootContext.getDn());
|
||||
|
||||
ldapTree.addSubTree(getLdapTree(ctx));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return ldapTree;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public interface LdapTreeVisitor {
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
@ContextConfiguration(locations = { "/conf/testContext.xml" })
|
||||
public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTreeBuilder tested;
|
||||
|
||||
@Test
|
||||
public void testGetLdapTree() {
|
||||
LdapTree ldapTree = tested.getLdapTree(new DistinguishedName("c=Sweden"));
|
||||
ldapTree.traverse(new TestVisitor());
|
||||
}
|
||||
|
||||
private static final class TestVisitor implements LdapTreeVisitor {
|
||||
private static final DistinguishedName DN_1 = new DistinguishedName("c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_2 = new DistinguishedName("ou=company1,c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_3 = new DistinguishedName("cn=Some Person,ou=company1,c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_4 = new DistinguishedName("cn=Some Person2,ou=company1,c=Sweden");
|
||||
|
||||
private Map<DistinguishedName, Integer> names = new LinkedHashMap<DistinguishedName, Integer>();
|
||||
|
||||
private Iterator<DistinguishedName> keyIterator;
|
||||
|
||||
public TestVisitor() {
|
||||
names.put(DN_1, 0);
|
||||
names.put(DN_2, 1);
|
||||
names.put(DN_3, 2);
|
||||
names.put(DN_4, 2);
|
||||
|
||||
keyIterator = names.keySet().iterator();
|
||||
}
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth) {
|
||||
DistinguishedName next = keyIterator.next();
|
||||
assertEquals(next, node.getDn());
|
||||
assertEquals(names.get(next).intValue(), currentDepth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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">
|
||||
|
||||
<!--
|
||||
This context configuration file defines common beans,
|
||||
minimizing duplication in the various test context files.
|
||||
-->
|
||||
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/conf/ldap.properties" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -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,27 @@
|
||||
<?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/commonTestContext.xml" />
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
|
||||
<constructor-arg ref="ldapTemplate" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,36 @@
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
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
|
||||
|
||||
13
mvn-build/samples/spring-ldap-article/.springBeans
Normal file
13
mvn-build/samples/spring-ldap-article/.springBeans
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[2.0.5.v200805211800]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
<enableImports><![CDATA[false]]></enableImports>
|
||||
<configs>
|
||||
</configs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
18
mvn-build/samples/spring-ldap-article/build.xml
Normal file
18
mvn-build/samples/spring-ldap-article/build.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project name="spring-ldap-article-sample" 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" />
|
||||
|
||||
<import file="${common.build.dir}/common-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>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
dn: dc=jayway,dc=se
|
||||
objectclass: dcObject
|
||||
objectclass: organization
|
||||
o: jayway
|
||||
dc: jayway
|
||||
|
||||
dn: cn=Manager,dc=jayway,dc=se
|
||||
objectclass:organizationalRole
|
||||
cn: Manager
|
||||
21
mvn-build/samples/spring-ldap-article/docs/ldap.conf.example
Normal file
21
mvn-build/samples/spring-ldap-article/docs/ldap.conf.example
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# LDAP Defaults
|
||||
#
|
||||
|
||||
# See ldap.conf(5) for details
|
||||
# This file should be world readable but not world writable.
|
||||
|
||||
#BASE dc=example, dc=com
|
||||
#URI ldap://ldap.example.com ldap://ldap-master.example.com:666
|
||||
|
||||
#SIZELIMIT 12
|
||||
#TIMELIMIT 15
|
||||
#DEREF never
|
||||
|
||||
include "[open_ldap_path]/schema/core.schema"
|
||||
#include "c:/Program Files/OpenLDAP/schema/inetorgperson.schema"
|
||||
database bdb
|
||||
suffix "dc=jayway,dc=se"
|
||||
rootdn "cn=Manager,dc=jayway,dc=se"
|
||||
rootpw secret
|
||||
directory "[open_ldap_path]/data"
|
||||
52
mvn-build/samples/spring-ldap-article/docs/readme.txt
Normal file
52
mvn-build/samples/spring-ldap-article/docs/readme.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
LDAP server setup for samples.
|
||||
|
||||
We need to semi-manually set up the server environment. I have used
|
||||
OpenLDAP (http://www.openldap.org/) with a minimal amount of data set up from an
|
||||
LDIF file.
|
||||
|
||||
There is a Windows version of OpenLDAP available at:
|
||||
|
||||
http://lucas.bergmans.us/hacks/openldap/
|
||||
|
||||
The LDIF file and sample application both expect to find the base suffix
|
||||
"dc=jayway,dc=se" in the LDAP Server.
|
||||
|
||||
For help in setting up the LDAP environment, three files are supplied:
|
||||
1. ldap.conf.example
|
||||
Modify paths in this file to suit your installation by replacing
|
||||
the placeholder [open_ldap_path].
|
||||
2. base_data.ldif
|
||||
Base domain and Admin data as specified in ldap.conf.
|
||||
3. setup_data.ldif
|
||||
The data expected by the integration test cases.
|
||||
|
||||
Start the LDAP Server:
|
||||
slapd -d 1 -f ldap.conf.example
|
||||
|
||||
Add the LDIF files (the default password in ldap.conf.example is "secret"):
|
||||
ldapadd -x -D "cn=Manager,dc=jayway,dc=se" -W -f base_data.ldif
|
||||
ldapadd -x -D "cn=Manager,dc=jayway,dc=se" -W -f setup_data.ldif
|
||||
|
||||
Verify the installation by running this search:
|
||||
|
||||
ldapsearch -LLL -b dc=jayway,dc=se "(objectclass=*)" dn
|
||||
|
||||
It should result in a list that looks like this:
|
||||
|
||||
dn: dc=jayway,dc=se
|
||||
|
||||
dn: cn=Manager,dc=jayway,dc=se
|
||||
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
|
||||
dn: c=Norway,dc=jayway,dc=se
|
||||
...
|
||||
|
||||
You should now be all set to run the integration tests.
|
||||
|
||||
If you choose to run the tests on another instance, or specifically with
|
||||
another suffix than the one mentioned above, you may need to modify data in
|
||||
the following files:
|
||||
|
||||
setup_data.ldif
|
||||
/src/iutest/config/ldap.properties
|
||||
70
mvn-build/samples/spring-ldap-article/docs/setup_data.ldif
Normal file
70
mvn-build/samples/spring-ldap-article/docs/setup_data.ldif
Normal file
@@ -0,0 +1,70 @@
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company2, Some Person
|
||||
telephoneNumber: +46 555-456321
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Norway,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Norway, Company1, Some Person
|
||||
telephoneNumber: +45 555-654123
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
c=Sweden,dc=jayway,dc=se
|
||||
|
||||
c=Norway,dc=jayway,dc=se
|
||||
31
mvn-build/samples/spring-ldap-article/ivy.xml
Normal file
31
mvn-build/samples/spring-ldap-article/ivy.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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-article-sample" />
|
||||
|
||||
<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>
|
||||
|
||||
<dependencies defaultconf="global->default">
|
||||
<!-- global dependencies -->
|
||||
<dependency org="commons-logging" name="commons-logging" rev="1.0.4" />
|
||||
<dependency org="log4j" name="log4j" rev="1.2.9" />
|
||||
<dependency org="org.springframework" name="spring-ldap" rev="latest.integration"
|
||||
conf="global->default;source->@" />
|
||||
|
||||
<!-- build time only dependencies -->
|
||||
|
||||
<!-- test-time only dependencies -->
|
||||
<dependency org="com.cenqua.clover" name="clover" rev="1.3.12" conf="test->default" />
|
||||
<dependency org="org.springframework" name="spring-mock" rev="2.0.8" conf="test->default" />
|
||||
<dependency org="junit" name="junit" rev="3.8.2" conf="test->default" />
|
||||
<dependency org="easymock" name="easymock" rev="1.2_Java1.3" conf="test->default"/>
|
||||
</dependencies>
|
||||
|
||||
</ivy-module>
|
||||
89
mvn-build/samples/spring-ldap-article/pom.xml
Normal file
89
mvn-build/samples/spring-ldap-article/pom.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project>
|
||||
<parent>
|
||||
<artifactId>master</artifactId>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-ldap-person-article</artifactId>
|
||||
<name>Spring LDAP Article Source Code Sample</name>
|
||||
<version>1.2</version>
|
||||
<packaging>war</packaging>
|
||||
<description>
|
||||
Example code that matches the article published on java.net on
|
||||
April 18, 2006.
|
||||
</description>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>maven-jetty-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>spring-ldap-test</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ldap</groupId>
|
||||
<artifactId>spring-ldap-samples-utils</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!--
|
||||
Requires an ldap server to be up and running. Uncomment to enable integration tests
|
||||
<build>
|
||||
<testSourceDirectory>src/itest/java</testSourceDirectory>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/itest/java</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
</build>
|
||||
-->
|
||||
</project>
|
||||
10
mvn-build/samples/spring-ldap-article/project.properties
Normal file
10
mvn-build/samples/spring-ldap-article/project.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
# 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
|
||||
|
||||
javac.source=1.3
|
||||
javac.target=1.3
|
||||
|
||||
# extend common-build with source capability
|
||||
main.build.configs=global,buildtime,test,source
|
||||
1
mvn-build/samples/spring-ldap-article/readme.txt
Normal file
1
mvn-build/samples/spring-ldap-article/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
For setup instructions on how to run this sample project, see docs/readme.txt.
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.samples.article.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.ldap.samples.article.dao.PersonDao;
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Abstract base class for PersonDao integration tests.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public abstract class AbstractPersonDaoIntegrationTest
|
||||
extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
protected Person person;
|
||||
|
||||
protected PersonDao personDao;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "config/testContext.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
person = new Person();
|
||||
person.setCountry("Sweden");
|
||||
person.setCompany("company1");
|
||||
person.setFullName("Some Person");
|
||||
person.setLastName("Person");
|
||||
person
|
||||
.setDescription("Sweden, Company1, Some Person");
|
||||
person.setPhone("+46 555-123456");
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
person = null;
|
||||
personDao = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Having a single test method test create, update and delete is not exactly
|
||||
* the ideal way of testing, since they depend on each other. A better way
|
||||
* would be to separate the tests and load a test fixture before each
|
||||
* operation, in order to guarantee the expected state every time. See the
|
||||
* ldaptemplate-person sample for the correct way to do this.
|
||||
*/
|
||||
public void testCreateUpdateDelete() {
|
||||
try {
|
||||
person.setFullName("Another Person");
|
||||
personDao.create(person);
|
||||
personDao.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
// if we got here, create succeeded
|
||||
|
||||
person
|
||||
.setDescription("Another description");
|
||||
personDao.update(person);
|
||||
Person result = personDao
|
||||
.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
assertEquals(
|
||||
"Another description", result
|
||||
.getDescription());
|
||||
} finally {
|
||||
personDao.delete(person);
|
||||
try {
|
||||
personDao.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
fail("DataRetrievalFailureException expected");
|
||||
} catch (DataRetrievalFailureException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAllPersonNames() {
|
||||
List result = personDao.getAllPersonNames();
|
||||
assertEquals(5, result.size());
|
||||
String first = (String) result.get(0);
|
||||
assertEquals("Some Person", first);
|
||||
}
|
||||
|
||||
public void testFindAll() {
|
||||
List result = personDao.findAll();
|
||||
assertEquals(5, result.size());
|
||||
Person first = (Person) result.get(0);
|
||||
assertEquals("Some Person", first
|
||||
.getFullName());
|
||||
}
|
||||
|
||||
public void testFindByPrimaryKey() {
|
||||
Person result = personDao.findByPrimaryKey(
|
||||
"Sweden", "company1", "Some Person");
|
||||
assertEquals(person, result);
|
||||
}
|
||||
}
|
||||
@@ -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.samples.article.dao;
|
||||
|
||||
import org.springframework.ldap.samples.article.dao.PersonDaoImpl;
|
||||
|
||||
/**
|
||||
* Integration tests for the PersonDaoImpl class.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PersonDaoImplIntegrationTest extends
|
||||
AbstractPersonDaoIntegrationTest {
|
||||
|
||||
public void setPersonDao(
|
||||
PersonDaoImpl personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
}
|
||||
@@ -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.samples.article.dao;
|
||||
|
||||
import org.springframework.ldap.samples.article.dao.TraditionalPersonDaoImpl;
|
||||
|
||||
/**
|
||||
* Integration tests for the TraditionalPersonDaoImpl class.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class TraditionalPersonDaoImplIntegrationTest
|
||||
extends AbstractPersonDaoIntegrationTest {
|
||||
|
||||
public void setPersonDao(
|
||||
TraditionalPersonDaoImpl personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
log4j.rootCategory=INFO, 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
|
||||
|
||||
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.logfile.File=${ldaptemplate.root}/ldaptemplate.log
|
||||
log4j.appender.logfile.MaxFileSize=512KB
|
||||
|
||||
# Keep three backup files
|
||||
log4j.appender.logfile.MaxBackupIndex=3
|
||||
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
#Pattern to output : date priority [category] - <message>line_separator
|
||||
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
||||
|
||||
#Enable debug logging
|
||||
#log4j.category.net.sf.ldaptemplate=DEBUG
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.samples.article.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
|
||||
|
||||
/**
|
||||
* Data Access Object interface for the Person entity.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface PersonDao {
|
||||
void create(Person person);
|
||||
|
||||
void update(Person person);
|
||||
|
||||
void delete(Person person);
|
||||
|
||||
List getAllPersonNames();
|
||||
|
||||
List findAll();
|
||||
|
||||
Person findByPrimaryKey(String country,
|
||||
String company, String fullname);
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* 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.samples.article.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
import org.springframework.ldap.core.ContextMapper;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.filter.EqualsFilter;
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
|
||||
/**
|
||||
* Default implementation of PersonDao. This implementation uses
|
||||
* DirContextAdapter for managing attribute values. It has been specified in the
|
||||
* Spring Context that the DirObjectFactory should be used when creating objects
|
||||
* from contexts, which defaults to creating DirContextAdapter objects. This
|
||||
* means that we can use a ContextMapper to map from the found contexts to our
|
||||
* domain objects. This is especially useful since we in this case have
|
||||
* properties in our domain objects that depend on parts of the DN.
|
||||
*
|
||||
* We could have worked with Attributes and an AttributesMapper implementation
|
||||
* instead, but working with Attributes is a bore and also, working with
|
||||
* AttributesMapper objects (or, indeed Attributes) does not give us access to
|
||||
* the distinguished name. However, we do use it in one method that only needs a
|
||||
* single attribute: {@link #getAllPersonNames()}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PersonDaoImpl implements PersonDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
/*
|
||||
* @see PersonDao#create(Person)
|
||||
*/
|
||||
public void create(Person person) {
|
||||
Name dn = buildDn(person);
|
||||
DirContextAdapter context = new DirContextAdapter(dn);
|
||||
mapToContext(person, context);
|
||||
ldapTemplate.bind(dn, context, null);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#update(Person)
|
||||
*/
|
||||
public void update(Person person) {
|
||||
Name dn = buildDn(person);
|
||||
DirContextAdapter context = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
mapToContext(person, context);
|
||||
ldapTemplate.modifyAttributes(dn, context.getModificationItems());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#delete(Person)
|
||||
*/
|
||||
public void delete(Person person) {
|
||||
ldapTemplate.unbind(buildDn(person));
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#getAllPersonNames()
|
||||
*/
|
||||
public List getAllPersonNames() {
|
||||
EqualsFilter filter = new EqualsFilter("objectclass", "person");
|
||||
return ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), new AttributesMapper() {
|
||||
public Object mapFromAttributes(Attributes attrs) throws NamingException {
|
||||
return attrs.get("cn").get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#findAll()
|
||||
*/
|
||||
public List findAll() {
|
||||
EqualsFilter filter = new EqualsFilter("objectclass", "person");
|
||||
return ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), getContextMapper());
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#findByPrimaryKey(java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public Person findByPrimaryKey(String country, String company, String fullname) {
|
||||
DistinguishedName dn = buildDn(country, company, fullname);
|
||||
return (Person) ldapTemplate.lookup(dn, getContextMapper());
|
||||
}
|
||||
|
||||
private ContextMapper getContextMapper() {
|
||||
return new PersonContextMapper();
|
||||
}
|
||||
|
||||
private DistinguishedName buildDn(Person person) {
|
||||
return buildDn(person.getCountry(), person.getCompany(), person.getFullName());
|
||||
}
|
||||
|
||||
private DistinguishedName buildDn(String country, String company, String fullname) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("c", country);
|
||||
dn.add("ou", company);
|
||||
dn.add("cn", fullname);
|
||||
return dn;
|
||||
}
|
||||
|
||||
private void mapToContext(Person person, DirContextAdapter context) {
|
||||
context.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
context.setAttributeValue("cn", person.getFullName());
|
||||
context.setAttributeValue("sn", person.getLastName());
|
||||
context.setAttributeValue("description", person.getDescription());
|
||||
context.setAttributeValue("telephoneNumber", person.getPhone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps from DirContextAdapter to Person objects. A DN for a person will be
|
||||
* of the form <code>cn=[fullname],ou=[company],c=[country]</code>, so
|
||||
* the values of these attributes must be extracted from the DN. For this,
|
||||
* we use the DistinguishedName.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private static class PersonContextMapper implements ContextMapper {
|
||||
|
||||
public Object mapFromContext(Object ctx) {
|
||||
DirContextAdapter context = (DirContextAdapter) ctx;
|
||||
DistinguishedName dn = new DistinguishedName(context.getDn());
|
||||
Person person = new Person();
|
||||
person.setCountry(dn.getLdapRdn(0).getComponent().getValue());
|
||||
person.setCompany(dn.getLdapRdn(1).getComponent().getValue());
|
||||
person.setFullName(context.getStringAttribute("cn"));
|
||||
person.setLastName(context.getStringAttribute("sn"));
|
||||
person.setDescription(context.getStringAttribute("description"));
|
||||
person.setPhone(context.getStringAttribute("telephoneNumber"));
|
||||
|
||||
return person;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* 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.samples.article.dao;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
|
||||
/**
|
||||
* Traditional implementation of PersonDao. This implementation uses the basic
|
||||
* JNDI interfaces and classes {@link DirContext}, {@link Attributes},
|
||||
* {@link Attribute}, and {@link NamingEnumeration}. The purpose is to
|
||||
* contrast this implementation with that of {@link PersonDaoImpl}.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class TraditionalPersonDaoImpl implements
|
||||
PersonDao {
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
|
||||
private String url;
|
||||
|
||||
private String base;
|
||||
|
||||
/*
|
||||
* @see PersonDao#create(Person)
|
||||
*/
|
||||
public void create(Person person) {
|
||||
DirContext ctx = createAuthenticatedContext();
|
||||
String dn = buildDn(person);
|
||||
try {
|
||||
Attributes attrs = getAttributesToBind(person);
|
||||
ctx.bind(dn, null, attrs);
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#update(Person)
|
||||
*/
|
||||
public void update(Person person) {
|
||||
DirContext ctx = createAuthenticatedContext();
|
||||
String dn = buildDn(person);
|
||||
try {
|
||||
ctx
|
||||
.rebind(
|
||||
dn, null,
|
||||
getAttributesToBind(person));
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#delete(Person)
|
||||
*/
|
||||
public void delete(Person person) {
|
||||
DirContext ctx = createAuthenticatedContext();
|
||||
String dn = buildDn(person);
|
||||
try {
|
||||
ctx.unbind(dn);
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#getAllPersonNames()
|
||||
*/
|
||||
public List getAllPersonNames() {
|
||||
DirContext ctx = createAnonymousContext();
|
||||
|
||||
LinkedList list = new LinkedList();
|
||||
NamingEnumeration results = null;
|
||||
try {
|
||||
SearchControls controls = new SearchControls();
|
||||
controls
|
||||
.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
results = ctx.search(
|
||||
"", "(objectclass=person)", controls);
|
||||
|
||||
while (results.hasMore()) {
|
||||
SearchResult searchResult = (SearchResult) results
|
||||
.next();
|
||||
Attributes attributes = searchResult
|
||||
.getAttributes();
|
||||
Attribute attr = attributes.get("cn");
|
||||
String cn = (String) attr.get();
|
||||
list.add(cn);
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
// The base context was not found.
|
||||
// Just clean up and exit.
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (results != null) {
|
||||
try {
|
||||
results.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#findAll()
|
||||
*/
|
||||
public List findAll() {
|
||||
DirContext ctx = createAnonymousContext();
|
||||
|
||||
LinkedList list = new LinkedList();
|
||||
NamingEnumeration results = null;
|
||||
try {
|
||||
SearchControls controls = new SearchControls();
|
||||
controls
|
||||
.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
results = ctx.search(
|
||||
"", "(objectclass=person)", controls);
|
||||
|
||||
while (results.hasMore()) {
|
||||
SearchResult searchResult = (SearchResult) results
|
||||
.next();
|
||||
String dn = searchResult.getName();
|
||||
Attributes attributes = searchResult
|
||||
.getAttributes();
|
||||
list.add(mapToPerson(dn, attributes));
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
// The base context was not found, which basically means
|
||||
// that the search did not return any results. Just clean up and
|
||||
// exit.
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (results != null) {
|
||||
try {
|
||||
results.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see PersonDao#findByPrimaryKey(java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public Person findByPrimaryKey(String country,
|
||||
String company, String fullname) {
|
||||
|
||||
DirContext ctx = createAnonymousContext();
|
||||
String dn = buildDn(
|
||||
country, company, fullname);
|
||||
try {
|
||||
Attributes attributes = ctx
|
||||
.getAttributes(dn);
|
||||
return mapToPerson(dn, attributes);
|
||||
} catch (NameNotFoundException e) {
|
||||
throw new DataRetrievalFailureException(
|
||||
"Did not find entry with primary key '"
|
||||
+ dn + "'", e);
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String buildDn(Person person) {
|
||||
return buildDn(person.getCountry(), person
|
||||
.getCompany(), person.getFullName());
|
||||
}
|
||||
|
||||
private String buildDn(String country, String company,
|
||||
String fullname) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("cn=");
|
||||
sb.append(fullname);
|
||||
sb.append(", ");
|
||||
sb.append("ou=");
|
||||
sb.append(company);
|
||||
sb.append(", ");
|
||||
sb.append("c=");
|
||||
sb.append(country);
|
||||
String dn = sb.toString();
|
||||
return dn;
|
||||
}
|
||||
|
||||
private DirContext createContext(Hashtable env) {
|
||||
env.put(
|
||||
Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.ldap.LdapCtxFactory");
|
||||
String tempUrl = createUrl();
|
||||
env.put(Context.PROVIDER_URL, tempUrl);
|
||||
DirContext ctx;
|
||||
try {
|
||||
ctx = new InitialDirContext(env);
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private DirContext createAnonymousContext() {
|
||||
Hashtable env = new Hashtable();
|
||||
return createContext(env);
|
||||
}
|
||||
|
||||
private DirContext createAuthenticatedContext() {
|
||||
Hashtable env = new Hashtable();
|
||||
env.put(
|
||||
Context.SECURITY_AUTHENTICATION,
|
||||
"simple");
|
||||
env.put(
|
||||
Context.SECURITY_PRINCIPAL, userName);
|
||||
env.put(
|
||||
Context.SECURITY_CREDENTIALS, password);
|
||||
return createContext(env);
|
||||
}
|
||||
|
||||
private Attributes getAttributesToBind(
|
||||
Person person) {
|
||||
Attributes attrs = new BasicAttributes();
|
||||
BasicAttribute ocattr = new BasicAttribute(
|
||||
"objectclass");
|
||||
ocattr.add("top");
|
||||
ocattr.add("person");
|
||||
attrs.put(ocattr);
|
||||
attrs.put("cn", person.getFullName());
|
||||
attrs.put("sn", person.getLastName());
|
||||
attrs.put("description", person
|
||||
.getDescription());
|
||||
attrs.put("telephoneNumber", person
|
||||
.getPhone());
|
||||
return attrs;
|
||||
}
|
||||
|
||||
private Person mapToPerson(String dn,
|
||||
Attributes attributes)
|
||||
throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullName((String) attributes.get(
|
||||
"cn").get());
|
||||
person.setLastName((String) attributes.get(
|
||||
"sn").get());
|
||||
person.setDescription((String) attributes
|
||||
.get("description").get());
|
||||
person.setPhone((String) attributes.get(
|
||||
"telephoneNumber").get());
|
||||
|
||||
// Remove any trailing spaces after comma
|
||||
String cleanedDn = dn
|
||||
.replaceAll(", *", ",");
|
||||
|
||||
String countryMarker = ",c=";
|
||||
int countryIndex = cleanedDn
|
||||
.lastIndexOf(countryMarker);
|
||||
|
||||
String companyMarker = ",ou=";
|
||||
int companyIndex = cleanedDn
|
||||
.lastIndexOf(companyMarker);
|
||||
|
||||
String country = cleanedDn
|
||||
.substring(countryIndex
|
||||
+ countryMarker.length());
|
||||
person.setCountry(country);
|
||||
String company = cleanedDn.substring(
|
||||
companyIndex + companyMarker.length(),
|
||||
countryIndex);
|
||||
person.setCompany(company);
|
||||
return person;
|
||||
}
|
||||
|
||||
private String createUrl() {
|
||||
String tempUrl = url;
|
||||
if (!tempUrl.endsWith("/")) {
|
||||
tempUrl += "/";
|
||||
}
|
||||
if (StringUtils.isNotEmpty(base)) {
|
||||
tempUrl += base;
|
||||
}
|
||||
return tempUrl;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setBase(String base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public void setPassword(String credentials) {
|
||||
this.password = credentials;
|
||||
}
|
||||
|
||||
public void setUserDn(String principal) {
|
||||
this.userName = principal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.samples.article.domain;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Simple class representing a single person.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class Person {
|
||||
private String fullName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String description;
|
||||
|
||||
private String country;
|
||||
|
||||
private String company;
|
||||
|
||||
private String phone;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public void setFullName(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(String company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(
|
||||
this, obj);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder
|
||||
.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(
|
||||
this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.springframework.ldap.samples.article.web;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.samples.article.dao.PersonDao;
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
import org.springframework.ldap.samples.utils.HtmlRowLdapTreeVisitor;
|
||||
import org.springframework.ldap.samples.utils.LdapTree;
|
||||
import org.springframework.ldap.samples.utils.LdapTreeBuilder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
public class DefaultController {
|
||||
|
||||
@Autowired
|
||||
private LdapTreeBuilder ldapTreeBuilder;
|
||||
|
||||
@Autowired
|
||||
private PersonDao personDao;
|
||||
|
||||
@RequestMapping("/welcome.do")
|
||||
public void welcomeHandler() {
|
||||
}
|
||||
|
||||
@RequestMapping("/doStuff.do")
|
||||
public ModelAndView showTree() {
|
||||
LdapTree ldapTree = ldapTreeBuilder.getLdapTree(DistinguishedName.EMPTY_PATH);
|
||||
HtmlRowLdapTreeVisitor visitor = new HtmlRowLdapTreeVisitor();
|
||||
ldapTree.traverse(visitor);
|
||||
return new ModelAndView("showTree", "rows", visitor.getRows());
|
||||
}
|
||||
|
||||
@RequestMapping("/addPerson.do")
|
||||
public ModelAndView addPerson() {
|
||||
Person person = getPerson();
|
||||
|
||||
personDao.create(person);
|
||||
return showTree();
|
||||
}
|
||||
|
||||
@RequestMapping("/removePerson.do")
|
||||
public ModelAndView removePerson() {
|
||||
Person person = getPerson();
|
||||
|
||||
personDao.delete(person);
|
||||
return showTree();
|
||||
}
|
||||
|
||||
|
||||
private Person getPerson() {
|
||||
Person person = new Person();
|
||||
person.setFullName("John Doe");
|
||||
person.setLastName("Doe");
|
||||
person.setCompany("company1");
|
||||
person.setCountry("Sweden");
|
||||
person.setDescription("Test user");
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<body>
|
||||
This document is the API specification for the Spring LDAP Article sample.
|
||||
</body>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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.xsd">
|
||||
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="/WEB-INF/ldap.properties" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="/WEB-INF/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTreeBuilder"
|
||||
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
|
||||
<constructor-arg ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="personDao"
|
||||
class="org.springframework.ldap.samples.article.dao.PersonDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:component-scan
|
||||
base-package="org.springframework.ldap.samples.article.web" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
|
||||
<property name="prefix" value="/WEB-INF/jsp/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<html>
|
||||
<body>
|
||||
<a href="addPerson.do">Add new test person</a>
|
||||
<a href="removePerson.do">Remove test person</a>
|
||||
|
||||
<c:forEach var="row" items="${rows}">
|
||||
${row}
|
||||
</c:forEach>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Hello
|
||||
</body>
|
||||
</html>
|
||||
@@ -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,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,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app id="Tiink-preview" xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
||||
version="2.4">
|
||||
|
||||
<display-name>Spring LDAP Basic Example</display-name>
|
||||
<listener>
|
||||
<listener-class>
|
||||
org.springframework.web.context.ContextLoaderListener
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>basic</servlet-name>
|
||||
<servlet-class>
|
||||
org.springframework.web.servlet.DispatcherServlet
|
||||
</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/basic-servlet.xml</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>basic</servlet-name>
|
||||
<url-pattern>*.do</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
@@ -0,0 +1,4 @@
|
||||
urls=ldap://127.0.0.1
|
||||
userDn=cn=Manager,dc=jayway,dc=se
|
||||
password=secret
|
||||
base=dc=jayway,dc=se
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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">
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/config/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}" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="personDao"
|
||||
class="org.springframework.ldap.samples.article.dao.PersonDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="traditionalPersonDao"
|
||||
class="org.springframework.ldap.samples.article.dao.TraditionalPersonDaoImpl">
|
||||
<property name="url" value="ldap://localhost:389" />
|
||||
<property name="base" value="dc=jayway,dc=se" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -22,8 +22,8 @@
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.4</source>
|
||||
<target>1.4</target>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@@ -35,6 +35,16 @@
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- External Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.opends</groupId>
|
||||
<artifactId>openDS</artifactId>
|
||||
<version>1.0.0-build005</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
@@ -43,7 +53,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.directory.server</groupId>
|
||||
<artifactId>apacheds-server-main</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.0.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ldap.core.ContextSource;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.support.AbstractContextSource;
|
||||
|
||||
/**
|
||||
* Utilities for starting, stopping and populating an in-process Apache
|
||||
@@ -96,7 +95,7 @@ public class LdapTestUtils {
|
||||
partitionConfiguration.setContextEntry(getRootPartitionAttributes(defaultPartitionName));
|
||||
partitionConfiguration.setName(defaultPartitionName);
|
||||
|
||||
cfg.setPartitionConfigurations(Collections.singleton(partitionConfiguration));
|
||||
cfg.setContextPartitionConfigurations(Collections.singleton(partitionConfiguration));
|
||||
// Start the Server
|
||||
|
||||
Hashtable env = createEnv(principal, credentials);
|
||||
@@ -213,7 +212,7 @@ public class LdapTestUtils {
|
||||
|
||||
public static void cleanAndSetup(ContextSource contextSource, DistinguishedName rootNode, Resource ldifFile)
|
||||
throws NamingException, IOException {
|
||||
|
||||
|
||||
clearSubContexts(contextSource, rootNode);
|
||||
loadLdif(contextSource, ldifFile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user