Last active
December 19, 2015 02:28
-
-
Save MoriTanosuke/5882934 to your computer and use it in GitHub Desktop.
Embedded Apache DS LDAP and Spring Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample LDIF data for the ApacheDS v1.0 Basic User's Guide | |
# | |
# Some sailors and their ships | |
# userpassword for all persons is "pass" | |
# | |
version: 1 | |
dn: ou=people,o=sevenSeas | |
objectclass: organizationalUnit | |
objectclass: top | |
description: Contains entries which describe persons (seamen) | |
ou: people | |
#dn: ou=groups,o=sevenSeas | |
#objectclass: organizationalUnit | |
#objectclass: top | |
#description: Contains entries which describe groups (crews, for instance) | |
#ou: groups | |
# | |
#dn: ou=crews,ou=groups,o=sevenSeas | |
#objectclass: organizationalUnit | |
#objectclass: top | |
#description: Contains entries which describe ship crews | |
#ou: crews | |
# | |
#dn: ou=ranks,ou=groups,o=sevenSeas | |
#objectclass: organizationalUnit | |
#objectclass: top | |
#description: Contains entries which describe naval ranks (e.g. captain) | |
#ou: ranks | |
# HMS Lydia Crew | |
# -------------- | |
dn: cn=Horatio Hornblower,ou=people,o=sevenSeas | |
objectclass: person | |
objectclass: organizationalPerson | |
objectclass: inetOrgPerson | |
objectclass: top | |
cn: Horatio Hornblower | |
description: Capt. Horatio Hornblower, R.N | |
givenname: Horatio | |
sn: Hornblower | |
uid: hhornblo | |
mail: hhornblo@royalnavy.mod.uk | |
userpassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ= | |
dn: cn=William Bush,ou=people,o=sevenSeas | |
objectclass: person | |
objectclass: organizationalPerson | |
objectclass: inetOrgPerson | |
objectclass: top | |
cn: William Bush | |
description: Lt. William Bush | |
givenname: William | |
manager: cn=Horatio Hornblower,ou=people,o=sevenSeas | |
sn: Bush | |
uid: wbush | |
mail: wbush@royalnavy.mod.uk | |
userpassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ= | |
dn: cn=Thomas Quist,ou=people,o=sevenSeas | |
objectclass: person | |
objectclass: organizationalPerson | |
objectclass: inetOrgPerson | |
objectclass: top | |
cn: Thomas Quist | |
description: Seaman Quist | |
givenname: Thomas | |
manager: cn=Horatio Hornblower,ou=people,o=sevenSeas | |
sn: Quist | |
uid: tquist | |
mail: tquist@royalnavy.mod.uk | |
userpassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ= | |
dn: cn=Moultrie Crystal,ou=people,o=sevenSeas | |
objectclass: person | |
objectclass: organizationalPerson | |
objectclass: inetOrgPerson | |
objectclass: top | |
cn: Moultrie Crystal | |
description: Lt. Crystal | |
givenname: Moultrie | |
manager: cn=Horatio Hornblower,ou=people,o=sevenSeas | |
sn: Crystal | |
uid: mchrysta | |
mail: mchrysta@royalnavy.mod.uk | |
userpassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ= | |
#dn: cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas | |
#objectclass: groupOfUniqueNames | |
#objectclass: top | |
#cn: HMS Lydia | |
#uniquemember: cn=Horatio Hornblower,ou=people,o=sevenSeas | |
#uniquemember: cn=William Bush,ou=people,o=sevenSeas | |
#uniquemember: cn=Thomas Quist,ou=people,o=sevenSeas | |
#uniquemember: cn=Moultrie Crystal,ou=people,o=sevenSeas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:camel="http://camel.apache.org/schema/spring" | |
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxws="http://cxf.apache.org/jaxws" | |
xmlns:security="http://www.springframework.org/schema/security" | |
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 | |
http://camel.apache.org/schema/spring | |
http://camel.apache.org/schema/spring/camel-spring.xsd | |
http://www.springframework.org/schema/security | |
http://www.springframework.org/schema/security/spring-security.xsd | |
http://camel.apache.org/schema/cxf | |
http://camel.apache.org/schema/cxf/camel-cxf.xsd"> | |
<!-- ldap settings --> | |
<security:ldap-server root="ou=people,o=sevenseas" ldif="classpath:apache-ds-tutorial.ldif" /> | |
<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" | |
scope="prototype"> | |
<constructor-arg> | |
<props> | |
<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop> | |
<prop key="java.naming.provider.url">ldap://127.0.0.1:33389</prop> | |
<prop key="java.naming.security.authentication">none</prop> | |
</props> | |
</constructor-arg> | |
</bean> | |
<camelContext xmlns="http://camel.apache.org/schema/spring"> | |
<route> | |
<from uri="direct:start" /> | |
<to uri="ldap:ldapserver?base=ou=people,o=sevenseas" /> | |
<to uri="mock:result" /> | |
</route> | |
</camelContext> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import org.apache.camel.CamelContext; | |
import org.apache.camel.EndpointInject; | |
import org.apache.camel.Exchange; | |
import org.apache.camel.Produce; | |
import org.apache.camel.ProducerTemplate; | |
import org.apache.camel.component.mock.MockEndpoint; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration | |
public class LdapRouteTest { | |
@Autowired | |
protected CamelContext camelContext; | |
@Produce(uri = "direct:start") | |
protected ProducerTemplate template; | |
@EndpointInject(uri = "mock:result") | |
protected MockEndpoint resultEndpoint; | |
@Test | |
public void testGetUserFromLdap() throws Exception { | |
// TODO what to expect | |
resultEndpoint.expectedBodiesReceived("(uid=admin,ou=system)"); | |
template.sendBody("(&(objectClass=*)(uid=hhornblo))"); | |
List<Exchange> exchanges = resultEndpoint.getExchanges(); | |
for (Exchange msg : exchanges) { | |
System.out.println(">>> " + msg.getOut()); | |
} | |
resultEndpoint.assertIsSatisfied(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<properties> | |
<cxf-version>2.7.4</cxf-version> | |
<camel-version>2.11.0</camel-version> | |
<junit-version>4.11</junit-version> | |
<log4j-version>1.2.17</log4j-version> | |
<slf4j-version>1.7.5</slf4j-version> | |
<spring-version>3.1.4.RELEASE</spring-version> | |
<apacheds-version>1.5.5</apacheds-version> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<checkstyle.suppressions>/suppression.xml</checkstyle.suppressions> | |
<checkstyle.ruleset>/checkstyle.xml</checkstyle.ruleset> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-core</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-spring</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-cxf</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-servlet</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-spring-ws</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-ldap</artifactId> | |
<version>${camel-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-core</artifactId> | |
<version>${spring-version}</version> | |
</dependency> | |
<!-- cxf --> | |
<!-- regular http transport --> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-transports-http</artifactId> | |
<version>${cxf-version}</version> | |
</dependency> | |
<!-- logging --> | |
<dependency> | |
<groupId>log4j</groupId> | |
<artifactId>log4j</artifactId> | |
<version>${log4j-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-log4j12</artifactId> | |
<version>${slf4j-version}</version> | |
</dependency> | |
<!-- cxf web container for unit testing --> | |
<dependency> | |
<groupId>org.apache.cxf</groupId> | |
<artifactId>cxf-rt-transports-http-jetty</artifactId> | |
<version>${cxf-version}</version> | |
</dependency> | |
<!-- spring security for ldap testing --> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-config</artifactId> | |
<version>${spring-version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.security</groupId> | |
<artifactId>spring-security-ldap</artifactId> | |
<version>${spring-version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.directory.server</groupId> | |
<artifactId>apacheds-all</artifactId> | |
<version>${apacheds-version}</version> | |
<scope>test</scope> | |
</dependency> | |
<!-- camel junit --> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>${junit-version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.camel</groupId> | |
<artifactId>camel-test-spring</artifactId> | |
<version>${camel-version}</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment