Moved everything from mvn-build to trunk root.

This commit is contained in:
Ulrik Sandberg
2008-10-12 21:34:09 +00:00
parent 22122636b1
commit a74ed8dafd
513 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
To run the automatic open LDAP EC2 instance launching tests, do:
mvn -Daws.key=<Your AWS Account Key> -Daws.secret.key=<Your AWS secret key> test
You can optionally tune the EC2 launch using the following parameters:
-Daws.ami=<Your AMI image identifier>
-Daws.key=<The AWS key to use when launching the instance>
-Daws.security.group=<The AWS security group to use when launching the instance>

Binary file not shown.

View File

@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-ldap-openldap-integration-tests</artifactId>
<packaging>jar</packaging>
<name>Spring LDAP Integration Tests (OpenLDAP)</name>
<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-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core-tiger</artifactId>
</dependency>
<dependency>
<groupId>com.xerox.amazonws</groupId>
<artifactId>typica</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/etc/lib/typica-1.4.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>logkit</groupId>
<artifactId>logkit</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<!--
Stax Parser/impl Marked as optional as -you can use a different
implementation -built in to some JVMs
-->
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jsr173</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<!--
Declaration of JAXB artifacts. These are all marked as optional
because the need for them varies with Java runtime
-->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
<optional>true</optional>
</dependency>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gsbase</groupId>
<artifactId>gsbase</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>ldapbp</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,97 @@
package org.springframework.ldap;
import java.util.Collections;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.util.Assert;
import com.xerox.amazonws.ec2.Jec2;
import com.xerox.amazonws.ec2.LaunchConfiguration;
import com.xerox.amazonws.ec2.ReservationDescription;
import com.xerox.amazonws.ec2.ReservationDescription.Instance;
public abstract class AbstractEc2InstanceLaunchingFactoryBean extends AbstractFactoryBean {
private static final int SLEEP_TIME = 1000;
private static final Log log = LogFactory.getLog(AbstractEc2InstanceLaunchingFactoryBean.class);
private String imageName;
private String awsKey;
private String awsSecretKey;
private String keyName;
private String groupName;
private Instance instance;
public void setImageName(String imageName) {
this.imageName = imageName;
}
public void setAwsKey(String awsKey) {
this.awsKey = awsKey;
}
public void setAwsSecretKey(String awsSecretKey) {
this.awsSecretKey = awsSecretKey;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
@Override
protected final Object createInstance() throws Exception {
Assert.hasLength(imageName, "ImageName must be set");
Assert.hasLength(awsKey, "AwsKey must be set");
Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
Assert.hasLength(keyName, "KeyName must be set");
Assert.hasLength(groupName, "GroupName must be set");
log.info("Launching EC2 instance for image: " + imageName);
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
launchConfiguration.setKeyName(keyName);
launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));
ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
instance = reservationDescription.getInstances().get(0);
while (!instance.isRunning() && !instance.isTerminated()) {
log.info("Instance still starting up; sleeping " + SLEEP_TIME + "ms");
Thread.sleep(SLEEP_TIME);
reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())).get(0);
instance = reservationDescription.getInstances().get(0);
}
if (instance.isRunning()) {
log.info("EC2 instance is now running");
return doCreateInstance(instance.getDnsName());
}
else {
throw new IllegalStateException("Failed to start a new instance");
}
}
protected abstract Object doCreateInstance(String dnsName) throws Exception;
@Override
protected void destroyInstance(Object ignored) throws Exception {
if (this.instance != null) {
log.info("Shutting down instance");
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
jec2.terminateInstances(Collections.singletonList(this.instance.getInstanceId()));
}
}
}

View File

@@ -0,0 +1,54 @@
package org.springframework.ldap;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.support.LdapContextSource;
public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2InstanceLaunchingFactoryBean {
private String base;
private String userDn;
private String password;
@Override
public final Class getObjectType() {
return ContextSource.class;
}
@Override
protected final Object doCreateInstance(final String dnsName) throws Exception {
LdapContextSource instance = new LdapContextSource();
instance.setUrl("ldap://" + dnsName);
instance.setUserDn(userDn);
instance.setPassword(password);
instance.setBase(base);
setAdditionalContextSourceProperties(instance, dnsName);
instance.afterPropertiesSet();
return instance;
}
/**
* Override to set additional properties on the ContextSource.
*
* @param ctx The created instance.
* @param dnsName The dns name of the created Ec2 instance.
*/
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
}
public void setBase(String base) {
this.base = base;
}
public void setUserDn(String userDn) {
this.userDn = userDn;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@@ -0,0 +1,23 @@
package org.springframework.ldap;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy;
import org.springframework.ldap.core.support.LdapContextSource;
public class TlsContextSourceEc2InstanceLaunchingFactoryBean extends ContextSourceEc2InstanceLaunchingFactoryBean {
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
DefaultTlsDirContextAuthenticationStrategy authenticationStrategy = new DefaultTlsDirContextAuthenticationStrategy();
authenticationStrategy.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return hostname.equals(dnsName);
}
});
ctx.setAuthenticationStrategy(authenticationStrategy);
ctx.setPooled(false);
}
}

View File

@@ -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.control;
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);
}
}

View File

@@ -0,0 +1,179 @@
/*
* 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.control;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import java.util.List;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.ContextMapperCallbackHandler;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.SearchExecutor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Tests the paged search result capability of LdapTemplate.
* <p>
* Note: Currently, ApacheDS does not support paged results controls, so this
* test must be run under another directory server, for example OpenLdap. This
* test will not run under ApacheDS, and the other integration tests assume
* ApacheDS and will probably not run under OpenLdap.
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplatePagedSearchITest extends AbstractJUnit4SpringContextTests {
private static final Name BASE = DistinguishedName.EMPTY_PATH;
private static final String FILTER_STRING = "(&(objectclass=person))";
@Autowired
private LdapTemplate tested;
private CollectingNameClassPairCallbackHandler callbackHandler;
private SearchControls searchControls;
@Before
public void onSetUp() throws Exception {
PersonContextMapper mapper = new PersonContextMapper();
callbackHandler = new ContextMapperCallbackHandler(mapper);
searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchControls.setReturningObjFlag(true);
}
@After
public void onTearDown() throws Exception {
callbackHandler = null;
tested = null;
searchControls = null;
}
@Test
public void testSearch_PagedResult() {
SearchExecutor searchExecutor = new SearchExecutor() {
public NamingEnumeration executeSearch(DirContext ctx) throws NamingException {
return ctx.search(BASE, FILTER_STRING, searchControls);
}
};
Person person;
List list;
PagedResultsCookie cookie;
PagedResultsRequestControl requestControl;
// Prepare for first search
requestControl = new PagedResultsRequestControl(3);
tested.search(searchExecutor, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNotNull("Cookie should not be null yet", cookie.getCookie());
list = callbackHandler.getList();
assertEquals(3, list.size());
person = (Person) list.get(0);
assertEquals("Some Person", person.getFullName());
assertEquals("+46 555-123456", person.getPhone());
person = (Person) list.get(1);
assertEquals("Some Person2", person.getFullName());
assertEquals("+46 555-654321", person.getPhone());
person = (Person) list.get(2);
assertEquals("Some Person3", person.getFullName());
assertEquals("+46 555-123654", person.getPhone());
// Prepare for second and last search
requestControl = new PagedResultsRequestControl(3, cookie);
tested.search(searchExecutor, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNull("Cookie should be null now", cookie.getCookie());
assertEquals(5, list.size());
person = (Person) list.get(3);
assertEquals("Some Person", person.getFullName());
assertEquals("+46 555-456321", person.getPhone());
person = (Person) list.get(4);
assertEquals("Some Person", person.getFullName());
assertEquals("+45 555-654123", person.getPhone());
}
public void testSearch_PagedResult_ConvenienceMethod() {
Person person;
List list;
PagedResultsCookie cookie;
PagedResultsRequestControl requestControl;
// Prepare for first search
requestControl = new PagedResultsRequestControl(3);
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNotNull("Cookie should not be null yet", cookie.getCookie());
list = callbackHandler.getList();
assertEquals(3, list.size());
person = (Person) list.get(0);
assertEquals("Some Person", person.getFullName());
person = (Person) list.get(1);
assertEquals("Some Person2", person.getFullName());
person = (Person) list.get(2);
assertEquals("Some Person3", person.getFullName());
// Prepare for second and last search
requestControl = new PagedResultsRequestControl(3, cookie);
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNull("Cookie should be null now", cookie.getCookie());
assertEquals(5, list.size());
person = (Person) list.get(3);
assertEquals("Some Person", person.getFullName());
person = (Person) list.get(4);
assertEquals("Some Person", person.getFullName());
}
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 setTested(LdapTemplate tested) {
this.tested = tested;
}
}

View File

@@ -0,0 +1,181 @@
/*
* 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.core;
import static junit.framework.Assert.assertEquals;
import java.util.List;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Verifies that LdapTemplate search methods work against OpenLDAP with TLS.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext-tls.xml" })
public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTests {
@Autowired
private LdapTemplate tested;
private AttributeCheckAttributesMapper attributesMapper;
private AttributeCheckContextMapper contextMapper;
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
private static final String[] CN_SN_ATTRS = { "cn", "sn" };
private static final String[] ABSENT_ATTRIBUTES = { "description", "telephoneNumber" };
private static final String[] CN_SN_VALUES = { "Some Person2", "Person2" };
private static final String[] ALL_VALUES = { "Some Person2", "Person2", "Sweden, Company1, Some Person2",
"+46 555-654321" };
private static final String BASE_STRING = "";
private static final String FILTER_STRING = "(&(objectclass=person)(sn=Person2))";
private static final Name BASE_NAME = new DistinguishedName(BASE_STRING);
@Before
public void prepareTestedInstance() throws Exception {
attributesMapper = new AttributeCheckAttributesMapper();
contextMapper = new AttributeCheckContextMapper();
}
@After
public void cleanup() throws Exception {
attributesMapper = null;
contextMapper = null;
}
@Test
public void testSearch_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper() {
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
attributesMapper.setExpectedValues(CN_SN_VALUES);
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
attributesMapper.setExpectedValues(CN_SN_VALUES);
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested
.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper_Name() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
}

View File

@@ -0,0 +1,8 @@
itest.openldap.serverAddress=spring-ldap-test.dyndns.org
userDn=cn=admin,dc=jayway,dc=se
password=secret
base=dc=jayway,dc=se
aws.ami=ami-56ec083f
aws.keypair=spring-ldap-keypair
aws.security.group=spring-ldap

View File

@@ -0,0 +1,42 @@
<?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 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/conf/ldap.properties" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
<bean id="contextSource" class="org.springframework.ldap.TlsContextSourceEc2InstanceLaunchingFactoryBean">
<property name="awsKey" value="${aws.key}" />
<property name="awsSecretKey" value="${aws.secret.key}" />
<property name="imageName" value="${aws.ami}" />
<property name="groupName" value="${aws.security.group}" />
<property name="keyName" value="${aws.keypair}" />
<property name="base" value="dc=jayway,dc=se" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
</bean>
<!--
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="base" value="dc=jayway,dc=se" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
<property name="url" value="ldap://${itest.openldap.serverAddress}:389" />
<property name="authenticationStrategy">
<bean class="org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy" />
</property>
<property name="pooled" value="false" />
</bean>
-->
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -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">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/conf/ldap.properties" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
<bean id="contextSource" class="org.springframework.ldap.ContextSourceEc2InstanceLaunchingFactoryBean">
<property name="awsKey" value="${aws.key}" />
<property name="awsSecretKey" value="${aws.secret.key}" />
<property name="imageName" value="${aws.ami}" />
<property name="groupName" value="${aws.security.group}" />
<property name="keyName" value="${aws.keypair}" />
<property name="base" value="dc=jayway,dc=se" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,6 @@
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%r [%t] %-5p\: %-15c{2} - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.logger.org.apache.directory.server.schema.registries.DefaultSyntaxRegistry=WARN

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-ldap-sunone-integration-tests</artifactId>
<packaging>jar</packaging>
<name>Spring LDAP Integration Tests (SunONE)</name>
<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-test</artifactId>
</dependency>
<!-- need domain objects and mappers -->
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-integration-tests</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core-tiger</artifactId>
</dependency>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>ldapbp</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>gsbase</groupId>
<artifactId>gsbase</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,268 @@
/*
* 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.core;
import static junit.framework.Assert.assertEquals;
import java.util.List;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.Person;
import org.springframework.ldap.PersonContextMapper;
import org.springframework.ldap.control.VirtualListViewControlDirContextProcessor;
import org.springframework.ldap.control.VirtualListViewResultsCookie;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Integration tests for the virtual list view search result capability of
* LdapTemplate. The test should reflect the example in Chapter 7 of the <a
* href=
* "http://www3.tools.ietf.org/html/draft-ietf-ldapext-ldapv3-vlv-09">Virtual
* List View RFC draft</a>.
*
* <blockquote> Here we walk through the client-server interaction for a
* specific virtual list view example: The task is to display a list of all
* 78564 persons in the US company "Ace Industry". This will be done by creating
* a graphical user interface object to display the list contents, and by
* repeatedly sending different versions of the same virtual list view search
* request to the server. The list view displays 20 entries on the screen at a
* time.
* <p>
* We form a search with baseObject of "o=Ace Industry,c=us"; scope of
* wholeSubtree; and filter of "(objectClass=person)". We attach a server-side
* sort control [SSS] to the search request, specifying ascending sort on
* attribute "cn". To this search request, we attach a virtual list view request
* control with contents determined by the user activity and send the search
* request to the server. We display the results from each search result entry
* in the list window and update the slider position.
* <p>
* When the list view is first displayed, we want to initialize the contents
* showing the beginning of the list. Therefore, we set beforeCount to 0,
* afterCount to 19, contentCount to 0, offset to 1 and send the request to the
* server. The server duly returns the first 20 entries in the list, plus a
* content count of 78564 and targetPosition of 1. We therefore leave the scroll
* bar slider at its current location (the top of its range).
* <p>
* Say that next the user drags the scroll bar slider down to the bottom of its
* range. We now wish to display the last 20 entries in the list, so we set
* beforeCount to 19, afterCount to 0, contentCount to 78564, offset to 78564
* and send the request to the server. The server returns the last 20 entries in
* the list, plus a content count of 78564 and a targetPosition of 78564.
* <p>
* Next the user presses a page up key. Our page size is 20, so we set
* beforeCount to 0, afterCount to 19, contentCount to 78564, offset to
* 78564-19-20 and send the request to the server. The server returns the
* preceding 20 entries in the list, plus a content count of 78564 and a
* targetPosition of 78525.
* <p>
* Now the user grabs the scroll bar slider and drags it to 68% of the way down
* its travel. 68% of 78564 is 53424 so we set beforeCount to 9, afterCount to
* 10, contentCount to 78564, offset to 53424 and send the request to the
* server. The server returns the preceding 20 entries in the list, plus a
* content count of 78564 and a targetPosition of 53424.
* <p>
* Lastly, the user types the letter "B". We set beforeCount to 9, afterCount to
* 10 and greaterThanOrEqual to "B". The server finds the first entry in the
* list not less than "B", let's say "Babs Jensen", and returns the nine
* preceding entries, the target entry, and the proceeding 10 entries. The
* server returns a content count of 78564 and a targetPosition of 5234 and so
* the client updates its scroll bar slider to 6.7% of full scale. </blockquote>
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateVirtualListViewSearchITest extends
AbstractJUnit4SpringContextTests {
@Autowired
private LdapTemplate tested;
private static final String BASE_STRING = "";
private static final String FILTER_STRING = "(objectclass=person)";
private SearchControls searchControls;
private CollectingNameClassPairCallbackHandler callbackHandler;
@Before
public void prepareTestedInstance() throws Exception {
searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
@After
public void cleanup() throws Exception {
searchControls = null;
}
@Test
public void testSearchUsingVirtualListView() {
List list;
Person person;
VirtualListViewResultsCookie cookie;
VirtualListViewControlDirContextProcessor requestControl;
PersonContextMapper contextMapper = new PersonContextMapper();
int listSize;
int targetOffset;
//
// Step 1: Prepare for getting the first 20
//
callbackHandler = new ContextMapperCallbackHandler(contextMapper);
requestControl = new VirtualListViewControlDirContextProcessor(20);
tested.search(BASE_STRING, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
// assert that total count is still 78564
listSize = requestControl.getListSize();
assertEquals(78564, listSize);
// assert that we are now at 1
targetOffset = requestControl.getTargetOffset();
assertEquals(1, targetOffset);
// assert that we got the right 20
list = callbackHandler.getList();
assertEquals(20, list.size());
person = (Person) list.get(0);
assertEquals("Adam Ace", person.getFullname());
//
// Step 2: Prepare for getting the last 20
//
callbackHandler = new ContextMapperCallbackHandler(contextMapper);
// we need a constructor that takes a beforeCount and an afterCount
requestControl = new VirtualListViewControlDirContextProcessor(20,
78564, listSize, cookie);
tested.search(BASE_STRING, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
// assert that total count is still 78564
listSize = requestControl.getListSize();
assertEquals(78564, listSize);
// assert that we are now at 78564
targetOffset = requestControl.getTargetOffset();
assertEquals(78564, targetOffset);
// assert that we got the right 20
list = callbackHandler.getList();
assertEquals(20, list.size());
person = (Person) list.get(19);
assertEquals("Xavier Zyxel", person.getFullname());
//
// Step 3: Prepare for getting the next to last 20
//
callbackHandler = new ContextMapperCallbackHandler(contextMapper);
// we need a constructor that takes a beforeCount and an afterCount
requestControl = new VirtualListViewControlDirContextProcessor(20,
78564 - 19 - 20, listSize, cookie);
tested.search(BASE_STRING, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
// assert that total count is still 78564
listSize = requestControl.getListSize();
assertEquals(78564, listSize);
// assert that we are now at 78525
targetOffset = requestControl.getTargetOffset();
assertEquals(78525, targetOffset);
// assert that we got the right 20
list = callbackHandler.getList();
assertEquals(20, list.size());
person = (Person) list.get(0);
assertEquals("William Schnyder", person.getFullname());
//
// Step 4: Prepare for getting the 20 entries around 68%, ie 53424
//
callbackHandler = new ContextMapperCallbackHandler(contextMapper);
// we need a constructor that takes a beforeCount and an afterCount
requestControl = new VirtualListViewControlDirContextProcessor(20,
68, listSize, cookie);
requestControl.setOffsetPercentage(true);
tested.search(BASE_STRING, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
// assert that total count is still 78564
listSize = requestControl.getListSize();
assertEquals(78564, listSize);
// assert that we are now at 53424
targetOffset = requestControl.getTargetOffset();
assertEquals(53424, targetOffset);
// assert that we got the right 20
list = callbackHandler.getList();
assertEquals(20, list.size());
person = (Person) list.get(9);
assertEquals("Peter Sellers", person.getFullname());
//
// Step 5: Prepare for getting the 20 entries around the letter 'B', ie 5234
//
callbackHandler = new ContextMapperCallbackHandler(contextMapper);
// we need a constructor that takes a String for 'greaterThanOrEqual'
// also beforeCount and afterCount
requestControl = new VirtualListViewControlDirContextProcessor(20,
5234, listSize, cookie);
requestControl.setOffsetPercentage(true);
tested.search(BASE_STRING, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
// assert that total count is still 78564
listSize = requestControl.getListSize();
assertEquals(78564, listSize);
// assert that we are now at 5234
targetOffset = requestControl.getTargetOffset();
assertEquals(5234, targetOffset);
// assert that we got the right 20
list = callbackHandler.getList();
assertEquals(20, list.size());
person = (Person) list.get(9);
assertEquals("Babs Jensen", person.getFullname());
}
}

View File

@@ -0,0 +1,4 @@
itest.sunone.serverAddress=spring-ldap-test.dyndns.org
userDn=cn=admin,o=Ace Industry,c=us
password=secret
base=o=Ace Industry,c=us

View File

@@ -0,0 +1,28 @@
<?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 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/conf/ldap.properties" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="base" value="${base}" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
<property name="url" value="ldap://${itest.sunone.serverAddress}:389" />
<property name="authenticationStrategy">
<bean class="org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy" />
</property>
<property name="pooled" value="false" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,6 @@
log4j.rootCategory=warn, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%r [%t] %-5p\: %-15c{2} - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.logger.org.apache.directory.server.schema.registries.DefaultSyntaxRegistry=WARN

View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-ldap-integration-tests</artifactId>
<packaging>jar</packaging>
<name>Spring LDAP Integration Tests (Generic)</name>
<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-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core-tiger</artifactId>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gsbase</groupId>
<artifactId>gsbase</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,64 @@
/*
* 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;
/**
* Dummy bean to be used in the LdapTemplate integration tests.
*
* @author Mattias Arthursson
*/
public class Person {
private String fullname;
private String lastname;
private String description;
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 getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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 javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.ldap.core.AttributesMapper;
/**
* Dummy implementation of AttributesMapper for use in integration tests.
*
* @author Mattias Arthursson
*
*/
public class PersonAttributesMapper implements AttributesMapper {
/**
* Maps the given attributes into a {@link Person} object.
*
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
*/
public Object mapFromAttributes(Attributes attributes)
throws NamingException {
Person person = new Person();
person.setFullname((String) attributes.get("cn").get());
person.setLastname((String) attributes.get("sn").get());
person.setPhone((String) attributes.get("telephoneNumber").get());
person.setDescription((String) attributes.get("description").get());
return person;
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.ldap.core.DirContextOperations;
import org.springframework.ldap.core.support.AbstractContextMapper;
/**
* Dummy implemention of ContextMapper for use in the integration tests and for
* illustration purposes.
*
* @author Mattias Arthursson
*/
public class PersonContextMapper extends AbstractContextMapper {
protected Object doMapFromContext(DirContextOperations ctx) {
Person person = new Person();
person.setFullname(ctx.getStringAttribute("cn"));
person.setLastname(ctx.getStringAttribute("sn"));
person.setPhone(ctx.getStringAttribute("telephoneNumber"));
person.setDescription(ctx.getStringAttribute("description"));
return person;
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.core;
/**
* Dummy implementation of a class that has a {@link DistinguishedName} setter,
* used for testing purposes.
*
* @author Mattias Arthursson
*/
public class DummyDistinguishedNameConsumer {
private DistinguishedName distinguishedName;
public DistinguishedName getDistinguishedName() {
return distinguishedName;
}
public void setDistinguishedName(DistinguishedName distinguishedName) {
this.distinguishedName = distinguishedName;
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.core.support;
import org.springframework.ldap.core.DistinguishedName;
/**
* Dummy implementation of {@link BaseLdapPathAware}.
*
* @author Mattias Arthursson
*/
public class DummyBaseLdapPathAware implements BaseLdapPathAware {
private DistinguishedName base;
public void setBaseLdapPath(DistinguishedName baseLdapPath) {
this.base = baseLdapPath;
}
public DistinguishedName getBase() {
return base;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2005-2008 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.filter;
/**
* Dummy class to test Filter property editor.
*
* @author Mattias Hellborg Arthursson
*/
public class DummyFilterConsumer {
private Filter filter;
public Filter getFilter() {
return filter;
}
public void setFilter(Filter filter) {
this.filter = filter;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2002-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.transaction.compensating.manager;
public interface DummyDao {
void createWithException(String country, String company, String fullname,
String lastname, String description);
void create(String country, String company, String fullname,
String lastname, String description);
void update(String dn, String fullname, String lastname, String description);
void updateWithException(String dn, String fullname, String lastname,
String description);
void updateAndRename(String dn, String newDn, String description);
void updateAndRenameWithException(String dn, String newDn,
String description);
void modifyAttributes(String dn, String lastName, String description);
void modifyAttributesWithException(String dn, String lastName,
String description);
void unbind(String dn, String fullname);
void unbindWithException(String dn, String fullname);
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 2002-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.transaction.compensating.manager;
public class DummyException extends RuntimeException {
public DummyException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2002-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.transaction.compensating.manager;
public class DummyServiceImpl {
private DummyDao dummyDaoImpl;
public void setDummyDaoImpl(DummyDao dummyDaoImpl) {
this.dummyDaoImpl = dummyDaoImpl;
}
}

View File

@@ -0,0 +1,166 @@
/*
* Copyright 2002-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.transaction.compensating.manager;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
public class LdapAndJdbcDummyDaoImpl implements DummyDao {
private LdapTemplate ldapTemplate;
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public void createWithException(String country, String company, String fullname, String lastname, String description) {
create(country, company, fullname, lastname, description);
throw new DummyException("This method failed");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public void create(String country, String company, String fullname, String lastname, String description) {
DistinguishedName dn = new DistinguishedName();
dn.add("c", country);
dn.add("ou", company);
dn.add("cn", fullname);
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
ctx.setAttributeValue("cn", fullname);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ldapTemplate.bind(dn, ctx, null);
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { fullname, lastname, description });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void update(String dn, String fullname, String lastname, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] {
lastname, description, fullname });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateWithException(String dn, String fullname, String lastname, String description) {
update(dn, fullname, lastname, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRename(String dn, String newDn, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
ldapTemplate.rename(dn, newDn);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRenameWithException(String dn, String newDn, String description) {
updateAndRename(dn, newDn, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributes(String dn, String lastName, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastName);
ctx.setAttributeValue("description", description);
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributesWithException(String dn, String lastName, String description) {
modifyAttributes(dn, lastName, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
*/
public void unbind(String dn, String fullname) {
ldapTemplate.unbind(dn);
jdbcTemplate.update("delete from PERSON where fullname=?", new Object[] { fullname });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
*/
public void unbindWithException(String dn, String fullname) {
unbind(dn, fullname);
throw new DummyException("This operation failed.");
}
}

View File

@@ -0,0 +1,163 @@
/*
* Copyright 2002-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.transaction.compensating.manager;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
public class LdapDummyDaoImpl implements DummyDao {
private LdapTemplate ldapTemplate;
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.lang.String)
*/
public void createWithException(String country, String company,
String fullname, String lastname, String description) {
create(country, company, fullname, lastname, description);
throw new DummyException("This method failed");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.lang.String)
*/
public void create(String country, String company, String fullname,
String lastname, String description) {
DistinguishedName dn = new DistinguishedName();
dn.add("c", country);
dn.add("ou", company);
dn.add("cn", fullname);
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
ctx.setAttributeValue("cn", fullname);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ldapTemplate.bind(dn, ctx, null);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void update(String dn, String fullname, String lastname,
String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateWithException(String dn, String fullname,
String lastname, String description) {
update(dn, fullname, lastname, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRename(String dn, String newDn, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
ldapTemplate.rename(dn, newDn);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRenameWithException(String dn, String newDn,
String description) {
updateAndRename(dn, newDn, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributes(String dn, String lastName, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastName);
ctx.setAttributeValue("description", description);
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributesWithException(String dn, String lastName,
String description) {
modifyAttributes(dn, lastName, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
*/
public void unbind(String dn, String fullname) {
ldapTemplate.unbind(dn);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
*/
public void unbindWithException(String dn, String fullname) {
unbind(dn, fullname);
throw new DummyException("This operation failed.");
}
}

View File

@@ -0,0 +1,107 @@
package org.springframework.ldap.transaction.compensating.manager.hibernate;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.transaction.compensating.manager.DummyException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* @author Hans Westerbeek
*/
public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements OrgPersonDao {
private LdapTemplate ldapTemplate;
public void create(OrgPerson person) {
DistinguishedName dn = new DistinguishedName();
dn.add("c", person.getCountry());
dn.add("ou", person.getCompany());
dn.add("cn", person.getFullname());
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
ctx.setAttributeValue("cn", person.getFullname());
ctx.setAttributeValue("sn", person.getLastname());
ctx.setAttributeValue("description", person.getDescription());
ldapTemplate.bind(dn, ctx, null);
this.getHibernateTemplate().saveOrUpdate(person);
}
public void createWithException(OrgPerson person) {
this.create(person);
throw new DummyException("This method failed");
}
public void modifyAttributes(String dn, String lastName, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastName);
ctx.setAttributeValue("description", description);
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
}
public void modifyAttributesWithException(String dn, String lastName,
String description) {
modifyAttributes(dn, lastName, description);
throw new DummyException("This method failed.");
}
public void unbind(OrgPerson person) {
String dn = prepareDn(person);
ldapTemplate.unbind(dn);
this.getHibernateTemplate().delete(person);
}
public void unbindWithException(OrgPerson person) {
this.unbind(person);
throw new DummyException("This method failed");
}
public void update(OrgPerson person) {
String dn = prepareDn(person);
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", person.getLastname());
ctx.setAttributeValue("description", person.getDescription());
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
this.getHibernateTemplate().saveOrUpdate(person);
}
public void updateWithException(OrgPerson person) {
this.update(person);
throw new DummyException("This method failed");
}
public void updateAndRename(String dn, String newDn, String updatedDescription) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("description", updatedDescription);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
ldapTemplate.rename(dn, newDn);
}
public void updateAndRenameWithException(String dn, String newDn, String updatedDescription) {
this.updateAndRename(dn, newDn, updatedDescription);
throw new DummyException("This method failed");
}
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
private String prepareDn(OrgPerson person){
return "cn=" + person.getFullname() + ",ou=" + person.getCompany() + ",c=" + person.getCountry();
}
}

View File

@@ -0,0 +1,123 @@
package org.springframework.ldap.transaction.compensating.manager.hibernate;
/**
* Pojo for use with the ContextSourceAndHibernateTransactionManager integration tests
* @author Hans Westerbeek
*
*/
public class OrgPerson{
private Integer id;
private String fullname;
private String lastname;
private String company;
private String country;
private String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
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 getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((company == null) ? 0 : company.hashCode());
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((fullname == null) ? 0 : fullname.hashCode());
result = prime * result + ((lastname == null) ? 0 : lastname.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final OrgPerson other = (OrgPerson) obj;
if (company == null) {
if (other.company != null)
return false;
}
else if (!company.equals(other.company))
return false;
if (country == null) {
if (other.country != null)
return false;
}
else if (!country.equals(other.country))
return false;
if (description == null) {
if (other.description != null)
return false;
}
else if (!description.equals(other.description))
return false;
if (fullname == null) {
if (other.fullname != null)
return false;
}
else if (!fullname.equals(other.fullname))
return false;
if (lastname == null) {
if (other.lastname != null)
return false;
}
else if (!lastname.equals(other.lastname))
return false;
return true;
}
}

View File

@@ -0,0 +1,23 @@
package org.springframework.ldap.transaction.compensating.manager.hibernate;
public interface OrgPersonDao {
void createWithException(OrgPerson person);
void create(OrgPerson person);
void update(OrgPerson person);
void updateWithException(OrgPerson person);
void updateAndRename(String dn, String newDn, String updatedDescription);
void updateAndRenameWithException(String dn, String newDn, String updatedDescription);
void modifyAttributes(String dn, String lastName, String description);
void modifyAttributesWithException(String dn, String lastName, String description);
void unbind(OrgPerson person);
void unbindWithException(OrgPerson person);
}

View File

@@ -0,0 +1,46 @@
/*
* 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.IOException;
import javax.naming.NamingException;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.test.LdapTestUtils;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
public abstract class AbstractLdapTemplateIntegrationTest extends AbstractJUnit4SpringContextTests {
private static final ClassPathResource LDIF_FILE_RESOURCE = new ClassPathResource("setup_data.ldif");
@Autowired
@Qualifier("contextSource")
private ContextSource contextSource;
@Before
public void cleanAndSetup() throws NamingException, IOException {
LdapTestUtils.cleanAndSetup(contextSource, getRoot(), LDIF_FILE_RESOURCE);
}
protected DistinguishedName getRoot() {
return DistinguishedName.EMPTY_PATH;
}
}

View File

@@ -0,0 +1,112 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import java.util.List;
import javax.naming.CompositeName;
import javax.naming.InvalidNameException;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
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;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the rename methods of LdapTemplate.
*
* We rely on that the bind, unbind and lookup methods work as they should -
* that should be ok, since that is verified in a separate test class. *
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private static DistinguishedName DN = new DistinguishedName("cn=Some\\\\Person6,ou=company1,c=Sweden");
@Before
public void prepareTestedInstance() throws Exception {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some\\Person6");
adapter.setAttributeValue("sn", "Person6");
adapter.setAttributeValue("description", "Some description");
tested.unbind(DN);
tested.bind(DN, adapter, null);
}
@After
public void cleanup() throws Exception {
tested.unbind(DN);
}
/**
* Test for LDAP-109, LDAP-50. When an entry has a distinguished name
* including a backslach ('\') the Name supplied to DefaultDirObjectFactory
* will be invalid.
* <p>
* E.g. the distinguished name "cn=Some\\Person6,ou=company1,c=Sweden"
* (indicating that the cn value is 'Some\Person'), will be represented by a
* <code>CompositeName</code> with the string representation
* "cn=Some\\\Person6,ou=company1,c=Sweden", which is in fact an invalid DN.
* This will be supplied to <code>DistinguishedName</code> for parsing,
* causing it to fail. This test makes sure that Spring LDAP properly works
* around this bug.
* </p>
* <p>
* What happens under the covers is (in the Java LDAP Provider code):
*
* <pre>
* LdapName ldapname = new LdapName(&quot;cn=Some\\\\Person6,ou=company1,c=Sweden&quot;);
* compositeName compositeName = new CompositeName();
* compositeName.add(ldapname.get(ldapname.size() - 1)); // for some odd reason
* </pre>
* <code>CompositeName#add()</code> cannot handle this and the result is
* the spoiled DN.
* </p>
* @throws InvalidNameException
*/
@Test
public void testSearchForDnSpoiledByCompositeName() throws InvalidNameException {
List result = tested.search("", "(sn=Person6)", new AbstractContextMapper() {
@Override
protected Object doMapFromContext(DirContextOperations ctx) {
DistinguishedName dn = (DistinguishedName) ctx.getDn();
assertEquals("cn=Some\\\\Person6, ou=company1, c=Sweden", dn.toString());
assertEquals("Some\\Person6", dn.getLdapRdn("cn").getValue());
return new Object();
}
});
assertEquals(1, result.size());
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import java.util.LinkedList;
import java.util.List;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the attributes mapper search method.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
protected String[] getConfigLocations() {
return new String[] { "/conf/ldapTemplateTestContext.xml" };
}
@Test
public void testSearch_AttributeMapper() throws Exception {
AttributesMapper mapper = new PersonAttributesMapper();
List result = tested.search("ou=company1,c=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
assertEquals(1, result.size());
Person person = (Person) result.get(0);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
}
/**
* Demonstrates how to retrieve all values of a multi-value attribute.
*
* @see LdapTemplateContextMapperITest#testSearch_ContextMapper_MultiValue()
*/
@Test
public void testSearch_AttributesMapper_MultiValue() throws Exception {
AttributesMapper mapper = new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
LinkedList list = new LinkedList();
NamingEnumeration enumeration = attributes.get("uniqueMember").getAll();
while (enumeration.hasMoreElements()) {
String value = (String) enumeration.nextElement();
list.add(value);
}
String[] members = (String[]) list.toArray(new String[0]);
return members;
}
};
List result = tested.search("ou=groups", "(objectclass=groupOfUniqueNames)", mapper);
assertEquals(2, result.size());
assertEquals(1, ((String[]) result.get(0)).length);
assertEquals(5, ((String[]) result.get(1)).length);
}
}

View File

@@ -0,0 +1,122 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
* class tests a little too much, but we need to clean up after binding, so the
* most efficient way to test is to do it all in one test method. Also, the
* methods in this class relies on that the lookup method works as it should -
* that should be ok, since that is verified in a separate test class. NOTE: if
* any of the tests in this class fails, it may be necessary to run the cleanup
* script as described in README.txt under /src/iutest/.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateBindUnbindITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private static String DN = "cn=Some Person4,ou=company1,c=Sweden";
@Test
public void testBindAndUnbind_Attributes_Plain() {
Attributes attributes = setupAttributes();
tested.bind(DN, null, attributes);
verifyBoundCorrectData();
tested.unbind(DN);
verifyCleanup();
}
@Test
public void testBindAndUnbind_Attributes_DIstinguishedName() {
Attributes attributes = setupAttributes();
tested.bind(new DistinguishedName(DN), null, attributes);
verifyBoundCorrectData();
tested.unbind(new DistinguishedName(DN));
verifyCleanup();
}
@Test
public void testBindAndUnbind_DirContextAdapter_Plain() {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person4");
adapter.setAttributeValue("sn", "Person4");
tested.bind(DN, adapter, null);
verifyBoundCorrectData();
tested.unbind(DN);
verifyCleanup();
}
@Test
public void testBindAndUnbind_DirContextAdapter_DIstinguishedName() {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person4");
adapter.setAttributeValue("sn", "Person4");
tested.bind(new DistinguishedName(DN), adapter, null);
verifyBoundCorrectData();
tested.unbind(new DistinguishedName(DN));
verifyCleanup();
}
private Attributes setupAttributes() {
Attributes attributes = new BasicAttributes();
BasicAttribute ocattr = new BasicAttribute("objectclass");
ocattr.add("top");
ocattr.add("person");
attributes.put(ocattr);
attributes.put("cn", "Some Person4");
attributes.put("sn", "Person4");
return attributes;
}
private void verifyBoundCorrectData() {
DirContextAdapter result = (DirContextAdapter) tested.lookup(DN);
assertEquals("Some Person4", result.getStringAttribute("cn"));
assertEquals("Person4", result.getStringAttribute("sn"));
}
private void verifyCleanup() {
try {
tested.lookup(DN);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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 static junit.framework.Assert.assertTrue;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.ContextExecutor;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests for LdapTemplate's context executor methods.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateContextExecutorTest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
@Test
public void testLookupLink() {
ContextExecutor executor = new ContextExecutor() {
public Object executeWithContext(DirContext ctx) throws NamingException {
return ctx.lookupLink("cn=Some Person,ou=company1,c=Sweden");
}
};
Object object = tested.executeReadOnly(executor);
assertTrue("Should be a DirContextAdapter", object instanceof DirContextAdapter);
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the ContextMapper search method. In its way this method also
* demonstrates the use of DirContextAdapter and the DirObjectFactory.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateContextMapperITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
/**
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void testSearch_ContextMapper() {
ContextMapper mapper = new PersonContextMapper();
List result = tested.search("ou=company1,c=Sweden", "(&(objectclass=person)(sn=Person2))", mapper);
assertEquals(1, result.size());
Person person = (Person) result.get(0);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
}
/**
* Demonstrates how to retrieve all values of a multi-value attribute.
*
* @see LdapTemplateAttributesMapperITest#testSearch_AttributesMapper_MultiValue()
*/
@Test
public void testSearch_ContextMapper_MultiValue() throws Exception {
ContextMapper mapper = new ContextMapper() {
public Object mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
String[] members = adapter.getStringAttributes("uniqueMember");
return members;
}
};
List result = tested.search("ou=groups", "(objectclass=groupOfUniqueNames)", mapper);
assertEquals(2, result.size());
assertEquals(1, ((String[]) result.get(0)).length);
assertEquals(5, ((String[]) result.get(1)).length);
}
}

View File

@@ -0,0 +1,155 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests for LdapTemplate's list methods.
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private AttributeCheckContextMapper contextMapper;
private static final String BASE_STRING = "";
private static final DistinguishedName BASE_NAME = new DistinguishedName(BASE_STRING);
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
private static final String[] ALL_VALUES = { "Some Person", "Person", "Sweden, Company2, Some Person",
"+46 555-456321" };
@Before
public void prepareTestedInstance() throws Exception {
contextMapper = new AttributeCheckContextMapper();
}
@After
public void tearDown() throws Exception {
contextMapper = null;
}
@Test
public void testListBindings_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.listBindings("ou=company2,c=Sweden" + BASE_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testListBindings_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
DistinguishedName dn = new DistinguishedName("ou=company2,c=Sweden");
dn.append(BASE_NAME);
List list = tested.listBindings(dn, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testListBindings_ContextMapper_MapToPersons() {
DistinguishedName dn = new DistinguishedName("ou=company1,c=Sweden");
dn.append(BASE_NAME);
List list = tested.listBindings(dn, new PersonContextMapper());
assertEquals(3, list.size());
String personClass = "org.springframework.ldap.Person";
assertEquals(personClass, list.get(0).getClass().getName());
assertEquals(personClass, list.get(1).getClass().getName());
assertEquals(personClass, list.get(2).getClass().getName());
}
@Test
public void testList() {
List list = tested.list(BASE_STRING);
assertEquals(3, list.size());
assertTrue(list.contains("ou=groups"));
assertTrue(list.contains("c=Norway"));
assertTrue(list.contains("c=Sweden"));
}
@Test
public void testList_Name() {
List list = tested.list(BASE_NAME);
assertEquals(3, list.size());
assertTrue(list.contains("ou=groups"));
assertTrue(list.contains("c=Norway"));
assertTrue(list.contains("c=Sweden"));
}
@Test
public void testList_Handler() throws Exception {
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
tested.list(BASE_STRING, handler);
assertEquals(3, handler.getNoOfRows());
}
@Test
public void testList_Name_Handler() throws Exception {
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
tested.list(BASE_NAME, handler);
assertEquals(3, handler.getNoOfRows());
}
@Test
public void testListBindings() {
List list = tested.listBindings(BASE_STRING);
assertEquals(3, list.size());
assertTrue(list.contains("ou=groups"));
assertTrue(list.contains("c=Norway"));
assertTrue(list.contains("c=Sweden"));
}
@Test
public void testListBindings_Name() {
List list = tested.listBindings(BASE_NAME);
assertEquals(3, list.size());
}
@Test
public void testListBindings_Handler() throws Exception {
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
tested.listBindings(BASE_STRING, handler);
assertEquals(3, handler.getNoOfRows());
}
@Test
public void testListBindings_Name_Handler() throws Exception {
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
tested.listBindings(BASE_NAME, handler);
assertEquals(3, handler.getNoOfRows());
}
}

View File

@@ -0,0 +1,232 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
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.core.support.AbstractContextSource;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the lookup methods of LdapTemplate.
*
* @author Mattias Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
/**
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void testLookup_Plain() {
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
}
@Test
public void testLookup_AttributesMapper() {
AttributesMapper mapper = new PersonAttributesMapper();
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
}
@Test
public void testLookup_AttributesMapper_DistinguishedName() {
AttributesMapper mapper = new PersonAttributesMapper();
Person person = (Person) tested.lookup(new DistinguishedName("cn=Some Person2, ou=company1,c=Sweden"), mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
}
/**
* An {@link AttributesMapper} that only maps a subset of the full
* attributes list. Used in tests where the return attributes list has been
* limited.
*
* @author Ulrik Sandberg
*/
private final class SubsetPersonAttributesMapper implements AttributesMapper {
/**
* Maps the <code>cn</code> attribute into a {@link Person} object.
* Also verifies that the other attributes haven't been set.
*
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
*/
public Object mapFromAttributes(Attributes attributes) throws NamingException {
Person person = new Person();
person.setFullname((String) attributes.get("cn").get());
assertNull("sn should be null", attributes.get("sn"));
assertNull("description should be null", attributes.get("description"));
return person;
}
}
/**
* Verifies that only the subset is used when specifying a subset of the
* available attributes as return attributes.
*/
@Test
public void testLookup_ReturnAttributes_AttributesMapper() {
AttributesMapper mapper = new SubsetPersonAttributesMapper();
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" }, mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
}
/**
* Verifies that only the subset is used when specifying a subset of the
* available attributes as return attributes. Uses DistinguishedName instead
* of plain string as name.
*/
@Test
public void testLookup_ReturnAttributes_AttributesMapper_DistinguishedName() {
AttributesMapper mapper = new SubsetPersonAttributesMapper();
Person person = (Person) tested.lookup(new DistinguishedName("cn=Some Person2, ou=company1,c=Sweden"),
new String[] { "cn" }, mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
}
/**
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void testLookup_ContextMapper() {
ContextMapper mapper = new PersonContextMapper();
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
}
/**
* Verifies that only the subset is used when specifying a subset of the
* available attributes as return attributes.
*/
@Test
public void testLookup_ReturnAttributes_ContextMapper() {
ContextMapper mapper = new PersonContextMapper();
Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" }, mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
}
/**
* Verifies that we can lookup an entry that has a multi-valued rdn, which
* means more than one attribute is part of the relative DN for the entry.
*/
@Test
@Ignore("Enable test when ApacheDS supports multi-valued rdns")
public void DISABLED_testLookup_MultiValuedRdn() {
AttributesMapper mapper = new PersonAttributesMapper();
Person person = (Person) tested.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway", mapper);
assertEquals("Some Person", person.getFullname());
assertEquals("Person", person.getLastname());
assertEquals("Norway, Company1, Some Person2", person.getDescription());
}
/**
* Verifies that we can lookup an entry that has a multi-valued rdn, which
* means more than one attribute is part of the relative DN for the entry.
*
*/
@Test
@Ignore("Enable test when ApacheDS supports multi-valued rdns")
public void DISABLED_testLookup_MultiValuedRdn_DirContextAdapter() {
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
assertEquals("Some Person", result.getStringAttribute("cn"));
assertEquals("Person", result.getStringAttribute("sn"));
assertEquals("Norway, Company1, Some Person", result.getStringAttribute("description"));
}
@Test
public void testLookup_GetNameInNamespace_Plain() {
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("cn=Some Person2, ou=company1, c=Sweden", result.getDn().toString());
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getNameInNamespace());
}
@Test
public void testLookup_GetNameInNamespace_MultiRdn() {
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
assertEquals("cn=Some Person+sn=Person, ou=company1, c=Norway", result.getDn().toString());
assertEquals("cn=Some Person+sn=Person, ou=company1, c=Norway, dc=jayway, dc=se", result.getNameInNamespace());
}
/**
* Tests bind and lookup with Java objects where the ContextSource already
* has a DirObjectFactory configured.
*/
@Test
public void testBindJavaObject() throws Exception {
AbstractContextSource contextSource = (AbstractContextSource) tested.getContextSource();
Class originalObjectFactory = contextSource.getDirObjectFactory();
try {
contextSource.setDirObjectFactory(null);
contextSource.afterPropertiesSet();
tested.bind("cn=myRandomInt", new Integer(54321), null);
Integer result = (Integer) tested.lookup("cn=myRandomInt");
assertEquals(54321, result.intValue());
}
finally {
// reset the DirObjectFactory so as not to disturb other tests
tested.unbind("cn=myRandomInt");
contextSource.setDirObjectFactory(originalObjectFactory);
contextSource.afterPropertiesSet();
}
}
}

View File

@@ -0,0 +1,248 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the modification methods (rebind and modifyAttributes) of LdapTemplate.
* It also illustrates the use of DirContextAdapter as a means of getting
* ModificationItems, in order to avoid doing a full rebind and use
* modifyAttributes() instead. We rely on that the bind, unbind and lookup
* methods work as they should - that should be ok, since that is verified in a
* separate test class. NOTE: if any of the tests in this class fails, it may be
* necessary to run the cleanup script as described in README.txt under
* /src/iutest/.
*
* @author Mattias Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private static String PERSON4_DN = "cn=Some Person4,ou=company1,c=Sweden";
private static String PERSON5_DN = "cn=Some Person5,ou=company1,c=Sweden";
@Before
public void prepareTestedInstance() throws Exception {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person4");
adapter.setAttributeValue("sn", "Person4");
adapter.setAttributeValue("description", "Some description");
tested.bind(PERSON4_DN, adapter, null);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person5");
adapter.setAttributeValue("sn", "Person5");
adapter.setAttributeValues("description", new String[] { "qwe", "123", "rty", "uio" });
tested.bind(PERSON5_DN, adapter, null);
}
@After
public void cleanup() throws Exception {
tested.unbind(PERSON4_DN);
tested.unbind(PERSON5_DN);
}
@Test
public void testRebind_Attributes_Plain() {
Attributes attributes = setupAttributes();
tested.rebind(PERSON4_DN, null, attributes);
verifyBoundCorrectData();
}
@Test
public void testRebind_Attributes_DistinguishedName() {
Attributes attributes = setupAttributes();
tested.rebind(new DistinguishedName(PERSON4_DN), null, attributes);
verifyBoundCorrectData();
}
@Test
public void testModifyAttributes_MultiValueReplace() {
BasicAttribute attr = new BasicAttribute("description", "Some other description");
attr.add("Another description");
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
tested.modifyAttributes(PERSON4_DN, mods);
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
String[] attributes = result.getStringAttributes("description");
assertEquals(2, attributes.length);
assertEquals("Some other description", attributes[0]);
assertEquals("Another description", attributes[1]);
}
@Test
public void testModifyAttributes_MultiValueAdd() {
BasicAttribute attr = new BasicAttribute("description", "Some other description");
attr.add("Another description");
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
tested.modifyAttributes(PERSON4_DN, mods);
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
String[] attributes = result.getStringAttributes("description");
assertEquals(3, attributes.length);
assertEquals("Some description", attributes[0]);
assertEquals("Some other description", attributes[1]);
assertEquals("Another description", attributes[2]);
}
@Test
public void testModifyAttributes_MultiValueAddDuplicateToUnordered() {
BasicAttribute attr = new BasicAttribute("description", "Some description");
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
try {
tested.modifyAttributes(PERSON4_DN, mods);
fail("AttributeInUseException expected");
}
catch (AttributeInUseException expected) {
// expected
}
}
/**
* Test written originally to verify that duplicates are allowed on ordered
* attributes, but had to be changed since Apache DS seems to disallow
* duplicates even for ordered attributes.
*/
@Test
public void testModifyAttributes_MultiValueAddDuplicateToOrdered() {
BasicAttribute attr = new BasicAttribute("description", "Some other description", true); // ordered
attr.add("Another description");
// Commented out duplicate to make test work for Apache DS
// attr.add("Some description");
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
tested.modifyAttributes(PERSON4_DN, mods);
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
String[] attributes = result.getStringAttributes("description");
assertEquals(3, attributes.length);
assertEquals("Some description", attributes[0]);
assertEquals("Some other description", attributes[1]);
assertEquals("Another description", attributes[2]);
}
@Test
public void testModifyAttributes_Plain() {
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
"Some other description"));
tested.modifyAttributes(PERSON4_DN, new ModificationItem[] { item });
verifyBoundCorrectData();
}
@Test
public void testModifyAttributes_DistinguishedName() {
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
"Some other description"));
tested.modifyAttributes(new DistinguishedName(PERSON4_DN), new ModificationItem[] { item });
verifyBoundCorrectData();
}
@Test
public void testModifyAttributes_DirContextAdapter_MultiAttributes() {
DirContextAdapter adapter = (DirContextAdapter) tested.lookup(PERSON5_DN);
adapter.setAttributeValues("description", new String[] { "qwe", "123", "klytt", "kalle" });
tested.modifyAttributes(PERSON5_DN, adapter.getModificationItems());
// Verify
adapter = (DirContextAdapter) tested.lookup(PERSON5_DN);
String[] attributes = adapter.getStringAttributes("description");
assertEquals(4, attributes.length);
assertEquals("qwe", attributes[0]);
assertEquals("123", attributes[1]);
assertEquals("klytt", attributes[2]);
assertEquals("kalle", attributes[3]);
}
/**
* Demonstrates how the DirContextAdapter can be used to automatically keep
* track of changes of the attributes and deliver ModificationItems to use
* in moifyAttributes().
*/
@Test
public void testModifyAttributes_DirContextAdapter() throws Exception {
DirContextAdapter adapter = (DirContextAdapter) tested.lookup(PERSON4_DN);
adapter.setAttributeValue("description", "Some other description");
ModificationItem[] modificationItems = adapter.getModificationItems();
tested.modifyAttributes(PERSON4_DN, modificationItems);
verifyBoundCorrectData();
}
private Attributes setupAttributes() {
Attributes attributes = new BasicAttributes();
BasicAttribute ocattr = new BasicAttribute("objectclass");
ocattr.add("top");
ocattr.add("person");
attributes.put(ocattr);
attributes.put("cn", "Some Person4");
attributes.put("sn", "Person4");
attributes.put("description", "Some other description");
return attributes;
}
private void verifyBoundCorrectData() {
DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN);
assertEquals("Some Person4", result.getStringAttribute("cn"));
assertEquals("Person4", result.getStringAttribute("sn"));
assertEquals("Some other description", result.getStringAttribute("description"));
}
}

View File

@@ -0,0 +1,98 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests to verify that not setting a base suffix on the ContextSource (as
* defined in ldapTemplateNoBaseSuffixTestContext.xml) works as expected.
*
* NOTE: This test will not work under Java 1.4.1 or earlier.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateNoBaseSuffixTestContext.xml" })
public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
@Override
protected DistinguishedName getRoot() {
return new DistinguishedName("dc=jayway,dc=se");
}
/**
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void testLookup_Plain() {
DirContextAdapter result = (DirContextAdapter) tested
.lookup("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getDn().toString());
assertEquals("cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", result.getNameInNamespace());
}
@Test
public void testSearch_Plain() {
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
tested.search("dc=jayway, dc=se", "(objectclass=person)", handler);
assertEquals(5, handler.getNoOfRows());
}
@Test
public void testBindAndUnbind_Plain() {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person4");
adapter.setAttributeValue("sn", "Person4");
tested.bind("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se", adapter, null);
DirContextAdapter result = (DirContextAdapter) tested
.lookup("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
assertEquals("Some Person4", result.getStringAttribute("cn"));
assertEquals("Person4", result.getStringAttribute("sn"));
assertEquals("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se", result.getDn().toString());
tested.unbind("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
try {
tested.lookup("cn=Some Person4, ou=company1, c=Sweden, dc=jayway, dc=se");
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
}

View File

@@ -0,0 +1,146 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import java.io.Serializable;
import java.util.LinkedList;
import javax.naming.directory.DirContext;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextSource;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests bind and lookup with Java objects where the ContextSource has a
* <code>null</code> DirObjectFactory configured.
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateObjectBindTestContext.xml" })
public class LdapTemplateObjectBindIntegrationTest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
@Test
public void testBindJavaObject() throws Exception {
String dn = "cn=myRandomInt";
tested.bind(dn, new Integer(54321), null);
Integer result = (Integer) tested.lookup(dn);
assertEquals(54321, result.intValue());
tested.unbind(dn);
}
@Test
public void testBindLinkedList() {
LinkedList list = new LinkedList();
list.add(new Integer(54321));
list.add(new Integer(67890));
String dn = "cn=myRandomList";
tested.bind(dn, list, null);
LinkedList result = (LinkedList) tested.lookup(dn);
assertEquals(2, result.size());
assertEquals(54321, ((Integer) result.get(0)).intValue());
assertEquals(67890, ((Integer) result.get(1)).intValue());
tested.unbind(dn);
}
@Test
public void testBindNonSerializableJavaObjectShouldFail() throws Exception {
NonSerializablePojo pojo = new NonSerializablePojo();
pojo.setName("A Name");
try {
tested.bind("cn=myRandomObject", pojo, null);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected) {
assertEquals("can only bind Referenceable, Serializable, DirContext", expected.getMessage());
}
}
/**
* Custom non-serializable class used for demonstrating bind and lookup of
* Java objects.
*/
public static class NonSerializablePojo {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Test
public void testBindSerializableJavaObjectShouldSucceed() throws Exception {
SerializablePojo pojo = new SerializablePojo();
pojo.setName("A Name");
tested.bind("cn=myRandomObject", pojo, null);
SerializablePojo result = (SerializablePojo) tested.lookup("cn=myRandomObject");
assertEquals("A Name", result.getName());
tested.unbind("cn=myRandomObject");
}
/**
* Custom serializable class used for demonstrating bind and lookup of Java
* objects.
*/
public static class SerializablePojo implements Serializable {
private static final long serialVersionUID = 3655768927093734908L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/**
* This test demonstrates that it's fully possible to perform plain JNDI
* operations from Spring LDAP.
*/
@Test
public void testPlainJndiBindJavaObject() throws Exception {
AbstractContextSource contextSource = (AbstractContextSource) tested.getContextSource();
DirContext ctx = contextSource.getReadWriteContext();
ctx.bind("cn=myRandomInt", new Integer(28420));
Integer result = (Integer) ctx.lookup("cn=myRandomInt");
assertEquals(28420, result.intValue());
tested.unbind("cn=myRandomInt");
}
}

View File

@@ -0,0 +1,124 @@
/*
* 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 static junit.framework.Assert.fail;
import javax.naming.Name;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the recursive modification methods (unbind and the protected delete
* methods) of LdapTemplate.
*
* @author Mattias Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private static DistinguishedName DN = new DistinguishedName("cn=Some Person5,ou=company1,c=Sweden");
private DistinguishedName firstSubDn;
private DistinguishedName secondSubDn;
private DistinguishedName leafDn;
@Before
public void prepareTestedInstance() throws Exception {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person5");
adapter.setAttributeValue("sn", "Person5");
adapter.setAttributeValue("description", "Some description");
tested.bind(DN, adapter, null);
firstSubDn = new DistinguishedName("cn=subPerson");
firstSubDn.prepend(DN);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subPerson");
adapter.setAttributeValue("sn", "subPerson");
adapter.setAttributeValue("description", "Should be recursively deleted");
tested.bind(firstSubDn, adapter, null);
secondSubDn = new DistinguishedName("cn=subPerson2");
secondSubDn.prepend(DN);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subPerson2");
adapter.setAttributeValue("sn", "subPerson2");
adapter.setAttributeValue("description", "Should be recursively deleted");
tested.bind(secondSubDn, adapter, null);
leafDn = new DistinguishedName("cn=subSubPerson");
leafDn.prepend(firstSubDn);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subSubPerson");
adapter.setAttributeValue("sn", "subSubPerson");
adapter.setAttributeValue("description", "Should be recursively deleted");
tested.bind(leafDn, adapter, null);
}
@After
public void cleanup() throws Exception {
try {
tested.unbind(DN, true);
}
catch (NameNotFoundException ignore) {
// ignore
}
}
@Test
public void testRecursiveUnbind() {
tested.unbind(DN, true);
verifyDeleted(DN);
verifyDeleted(firstSubDn);
verifyDeleted(secondSubDn);
verifyDeleted(leafDn);
}
@Test
public void testRecursiveUnbindOnLeaf() {
tested.unbind(leafDn, true);
verifyDeleted(leafDn);
}
private void verifyDeleted(Name dn) {
try {
tested.lookup(dn);
fail("Expected entry '" + dn + "' to be non-existent");
}
catch (NameNotFoundException expected) {
// expected
}
}
}

View File

@@ -0,0 +1,102 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import javax.naming.Name;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests the rename methods of LdapTemplate.
*
* We rely on that the bind, unbind and lookup methods work as they should -
* that should be ok, since that is verified in a separate test class. *
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private static String DN = "cn=Some Person6,ou=company1,c=Sweden";
private static String NEWDN = "cn=Some Person6,ou=company2,c=Sweden";
@Before
public void prepareTestedInstance() throws Exception {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "Some Person6");
adapter.setAttributeValue("sn", "Person6");
adapter.setAttributeValue("description", "Some description");
tested.bind(DN, adapter, null);
}
@After
public void cleanup() throws Exception {
tested.unbind(NEWDN);
tested.unbind(DN);
}
@Test
public void testRename() {
tested.rename(DN, NEWDN);
verifyDeleted(new DistinguishedName(DN));
verifyBoundCorrectData();
}
@Test
public void testRename_DistinguishedName() throws Exception {
Name oldDn = new DistinguishedName(DN);
Name newDn = new DistinguishedName(NEWDN);
tested.rename(oldDn, newDn);
verifyDeleted(oldDn);
verifyBoundCorrectData();
}
private void verifyDeleted(Name dn) {
try {
tested.lookup(dn);
fail("Expected entry '" + dn + "' to be non-existent");
}
catch (NameNotFoundException expected) {
// expected
}
}
private void verifyBoundCorrectData() {
DirContextAdapter result = (DirContextAdapter) tested.lookup(NEWDN);
assertEquals("Some Person6", result.getStringAttribute("cn"));
assertEquals("Person6", result.getStringAttribute("sn"));
assertEquals("Some description", result.getStringAttribute("description"));
}
}

View File

@@ -0,0 +1,207 @@
/*
* 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 static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.util.List;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests for LdapTemplate's search methods. This test class tests all the
* different versions of the search methods except the generic ones covered in
* other tests.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private AttributeCheckAttributesMapper attributesMapper;
private AttributeCheckContextMapper contextMapper;
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
private static final String[] CN_SN_ATTRS = { "cn", "sn" };
private static final String[] ABSENT_ATTRIBUTES = { "description", "telephoneNumber" };
private static final String[] CN_SN_VALUES = { "Some Person2", "Person2" };
private static final String[] ALL_VALUES = { "Some Person2", "Person2", "Sweden, Company1, Some Person2",
"+46 555-654321" };
private static final String BASE_STRING = "";
private static final String FILTER_STRING = "(&(objectclass=person)(sn=Person2))";
private static final Name BASE_NAME = new DistinguishedName(BASE_STRING);
@Before
public void prepareTestedInstance() throws Exception {
attributesMapper = new AttributeCheckAttributesMapper();
contextMapper = new AttributeCheckContextMapper();
}
@After
public void cleanup() throws Exception {
attributesMapper = null;
contextMapper = null;
}
@Test
public void testSearch_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper() {
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
attributesMapper.setExpectedValues(CN_SN_VALUES);
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
attributesMapper.setExpectedValues(CN_SN_VALUES);
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested
.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper_Name() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearchWithInvalidSearchBaseShouldByDefaultThrowException() {
try {
tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
contextMapper);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
@Test
public void testSearchWithInvalidSearchBaseCanBeConfiguredToSwallowException() {
tested.setIgnoreNameNotFoundException(true);
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
contextMapper);
assertEquals(0, list.size());
}
}

View File

@@ -0,0 +1,71 @@
/*
* 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.control;
import static junit.framework.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
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.test.context.ContextConfiguration;
/**
* Provides tests that verify that the server supports certain controls.
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = { "/conf/rootContextSourceTestContext.xml" })
public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest {
/** must use a context source that has no base set */
@Autowired
private LdapTemplate tested;
private static final String SUPPORTED_CONTROL = "supportedcontrol";
@Override
protected DistinguishedName getRoot() {
return new DistinguishedName("dc=jayway,dc=se");
}
@Test
public void testExpectedControlsSupported() throws Exception {
/**
* Maps the 'supportedcontrol' attribute to a string array.
*/
ContextMapper mapper = new ContextMapper() {
public Object mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
return adapter.getStringAttributes(SUPPORTED_CONTROL);
}
};
String[] controls = (String[]) tested.lookup("", new String[] { SUPPORTED_CONTROL }, mapper);
System.out.println(Arrays.toString(controls));
assertEquals("Persistent Search LDAPv3 control,", "2.16.840.1.113730.3.4.3", controls[0]);
assertEquals("Entry Change Notification LDAPv3 control,", "2.16.840.1.113730.3.4.7", controls[1]);
assertEquals("Subentries Control,", "1.3.6.1.4.1.4203.1.10.1", controls[2]);
assertEquals("Manage DSA IT LDAPv3 control,", "2.16.840.1.113730.3.4.2", controls[3]);
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.core;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Integration tests for {@link DistinguishedNameEditor}.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/distinguishedNameEditorTestContext.xml" })
public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTests {
@Autowired
private DummyDistinguishedNameConsumer distinguishedNameConsumer;
@Test
public void testDistinguishedNameEditor() throws Exception {
assertNotNull(distinguishedNameConsumer);
DistinguishedName name = distinguishedNameConsumer.getDistinguishedName();
assertEquals(new DistinguishedName("dc=jayway, dc=se"), name);
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.core;
import org.junit.Test;
import org.springframework.util.StopWatch;
/**
* Performance test for the {@link DistinguishedName} class.
*
* @author Ulrik Sandberg
*/
public class DnParsePerformanceITest {
/**
* Tests parsing and toString.
*/
@Test
public void testContains() {
StopWatch stopWatch = new StopWatch("Dn Parse Performance");
stopWatch.start();
for (int i = 0; i < 2000; i++) {
DistinguishedName migpath = new DistinguishedName("OU=G,OU=I,OU=M");
DistinguishedName path1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M");
DistinguishedName path2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=i,OU=M, ou=foo");
DistinguishedName path3 = new DistinguishedName("ou=G,OU=i,OU=M, ou=foo");
DistinguishedName path4 = new DistinguishedName("ou=G,OU=i,ou=m");
DistinguishedName pathE1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo");
DistinguishedName pathE2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE");
}
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.core.simple;
import static junit.framework.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(locations = { "/conf/simpleLdapTemplateTestContext.xml" })
public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private SimpleLdapTemplate ldapTemplate;
@Test
public void testLookup() {
String result = ldapTemplate.lookup("cn=Some Person,ou=company1,c=Sweden", new CnContextMapper());
assertEquals("Some Person", result);
}
@Test
public void testSearch() {
List<String> cns = ldapTemplate.search("", "(&(objectclass=person)(sn=Person3))", new CnContextMapper());
assertEquals(1, cns.size());
assertEquals("Some Person3", cns.get(0));
}
@Test
public void testModifyAttributes() {
DirContextOperations ctx = ldapTemplate.lookupContext("cn=Some Person,ou=company1,c=Sweden");
ctx.setAttributeValue("description", "updated description");
ctx.setAttributeValue("telephoneNumber", "0000001");
ldapTemplate.modifyAttributes(ctx);
// verify that the data was properly updated.
ldapTemplate.lookup("cn=Some Person,ou=company1,c=Sweden", new ParameterizedContextMapper<Object>() {
public Object mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
assertEquals("updated description", adapter.getStringAttribute("description"));
assertEquals("0000001", adapter.getStringAttribute("telephoneNumber"));
return null;
}
});
}
private static class CnContextMapper implements ParameterizedContextMapper<String> {
public String mapFromContext(Object ctx) {
DirContextAdapter adapter = (DirContextAdapter) ctx;
return adapter.getStringAttribute("cn");
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.core.support;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ldap.core.DistinguishedName;
/**
* Integration tests for {@link BaseLdapPathBeanPostProcessor}.
*
* @author Mattias Arthursson
*/
public class BaseLdapPathBeanPostprocessorITest {
@Test
public void testPostProcessBeforeInitialization() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/baseLdapPathPostProcessorTestContext.xml");
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
DistinguishedName base = tested.getBase();
assertNotNull(base);
assertEquals(new DistinguishedName("dc=jayway,dc=se"), base);
}
@Test
public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception {
try {
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorMultiContextSourceTestContext.xml");
fail("BeanCreationException expected");
}
catch (BeanCreationException expected) {
Throwable cause = expected.getCause();
assertTrue(cause instanceof NoSuchBeanDefinitionException);
}
}
@Test
public void testPostProcessBeforeInitializationMultipleContextSourcesOneSpecified() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/baseLdapPathPostProcessorMultiContextSourceOneSpecTestContext.xml");
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
DistinguishedName base = tested.getBase();
assertNotNull(base);
assertEquals(new DistinguishedName("cn=john doe,dc=jayway,dc=se"), base);
}
@Test
public void testPostProcessBeforeInitializationNoContextSource() throws Exception {
try {
new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorNoContextSourceTestContext.xml");
fail("BeanCreationException expected");
}
catch (BeanCreationException expected) {
Throwable cause = expected.getCause();
assertTrue(cause instanceof NoSuchBeanDefinitionException);
}
}
@Test
public void testPostProcessBeforeInitializationBaseSetInProperty() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/baseLdapPathPostProcessorPropertyOverrideTestContext.xml");
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
DistinguishedName base = tested.getBase();
assertNotNull(base);
assertEquals(new DistinguishedName("cn=john doe"), base);
}
@Test
public void testPostProcessBeforeInitializationTransactionProxy() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/baseLdapPathPostProcessorTransactionTestContext.xml");
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
DistinguishedName base = tested.getBase();
assertNotNull(base);
assertEquals(new DistinguishedName("dc=jayway,dc=se"), base);
}
}

View File

@@ -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.core.support;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.core.ContextSource;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration tests for ContextSourceImpl.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapContextSourcelITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private ContextSource tested;
@Test
public void testGetReadOnlyContext() throws NamingException {
DirContext ctx = null;
try {
ctx = tested.getReadOnlyContext();
assertNotNull(ctx);
Hashtable environment = ctx.getEnvironment();
assertTrue(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL));
assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS));
}
finally {
// Always clean up.
if (ctx != null) {
try {
ctx.close();
}
catch (Exception e) {
// Never mind this
}
}
}
}
@Test
public void testGetReadWriteContext() throws NamingException {
DirContext ctx = null;
try {
ctx = tested.getReadWriteContext();
assertNotNull(ctx);
// Double check to see that we are authenticated.
Hashtable environment = ctx.getEnvironment();
assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL));
assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS));
}
finally {
// Always clean up.
if (ctx != null) {
try {
ctx.close();
}
catch (Exception e) {
// Never mind this
}
}
}
}
@Test
public void testGetContext() throws NamingException {
DirContext ctx = null;
try {
String expectedPrincipal = "cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se";
String expectedCredentials = "password";
ctx = tested.getContext(expectedPrincipal, expectedCredentials);
assertNotNull(ctx);
// Double check to see that we are authenticated.
Hashtable environment = ctx.getEnvironment();
assertEquals(expectedPrincipal, environment.get(Context.SECURITY_PRINCIPAL));
assertEquals(expectedCredentials, environment.get(Context.SECURITY_CREDENTIALS));
}
finally {
// Always clean up.
if (ctx != null) {
try {
ctx.close();
}
catch (Exception e) {
// Never mind this
}
}
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.core.support;
import static junit.framework.Assert.assertEquals;
import javax.naming.NamingException;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Integration tests for ContextSourceImpl.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapContextSourceTestContext.xml" })
public class LdapContextSourcelMultiServerITest extends AbstractJUnit4SpringContextTests {
@Autowired
private LdapContextSource tested;
@Test
public void testUrls() throws NamingException {
String[] urls = tested.getUrls();
String string = tested.assembleProviderUrlString(urls);
assertEquals("ldap://127.0.0.1:389 ldap://127.0.0.2:389", string);
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2005-2008 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.filter;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = { "/conf/hardcodedFilterTestContext.xml" })
public class HardcodedFilterIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired
private DummyFilterConsumer dummyFilterConsumer;
@Test
public void verifyThatFilterEditorWorks() {
Filter filter = dummyFilterConsumer.getFilter();
assertTrue(filter instanceof HardcodedFilter);
assertEquals("(&(objectclass=person)(!(objectclass=computer))", filter.toString());
}
}

View File

@@ -0,0 +1,352 @@
/*
* 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.transaction.compensating.manager;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapAndJdbcTransactionTestContext.xml" })
public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
private static Log log = LogFactory.getLog(ContextSourceAndDataSourceTransactionManagerIntegrationTest.class);
@Autowired
@Qualifier("dummyDao")
private DummyDao dummyDao;
@Autowired
private LdapTemplate ldapTemplate;
@Autowired
private JdbcTemplate jdbcTemplate;
@Before
public void prepareTestedInstance() throws Exception {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clearSynchronization();
}
jdbcTemplate.execute("drop table PERSON if exists");
jdbcTemplate.execute("create table PERSON(fullname VARCHAR, lastname VARCHAR, description VARCHAR)");
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
"Sweden, Company1, Some Person" });
}
@After
public void cleanup() throws Exception {
jdbcTemplate.execute("drop table PERSON if exists");
}
@Test
public void testCreateWithException() {
try {
dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
// Verify that no entry was created
try {
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
try {
jdbcTemplate.queryForObject("select * from PERSON where fullname='some testperson'", new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return null;
}
});
fail("EmptyResultDataAccessException expected");
}
catch (EmptyResultDataAccessException expected) {
assertTrue(true);
}
}
@Test
public void testCreate() {
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
Object dbResult = jdbcTemplate.queryForObject("select * from PERSON where fullname='some testperson'",
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Object();
}
});
assertNotNull(ldapResult);
assertNotNull(dbResult);
ldapTemplate.unbind("cn=some testperson, ou=company1, c=Sweden");
}
@Test
public void testUpdateWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
new Object[] { "Some Person" }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
assertEquals("Person", rs.getString("lastname"));
assertEquals("Sweden, Company1, Some Person", rs.getString("description"));
return new Object();
}
});
assertNotNull(ldapResult);
assertNotNull(jdbcResult);
}
@Test
public void testUpdate() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated Person", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
new Object[] { "Some Person" }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
assertEquals("Updated Person", rs.getString("lastname"));
assertEquals("Updated description", rs.getString("description"));
return new Object();
}
});
assertNotNull(ldapResult);
assertNotNull(jdbcResult);
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
@Test
public void testUpdateAndRenameWithException() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
try {
// Perform test
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify that entry was not moved.
try {
ldapTemplate.lookup(newDn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
// Verify that original entry was not updated.
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
}
@Test
public void testUpdateAndRename() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
// Perform test
dummyDao.updateAndRename(dn, newDn, "Updated description");
// Verify that entry was moved and updated.
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}
@Test
public void testModifyAttributesWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testModifyAttributes() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
// Verify result - check that the operation was not rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated lastname", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
@Test
public void testUnbindWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.unbindWithException(dn, "Some Person");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
// Just verify that the entry still exists.
return new Object();
}
});
Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?",
new Object[] { "Some Person" }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
// Just verify that the entry still exists.
return new Object();
}
});
assertNotNull(ldapResult);
assertNotNull(jdbcResult);
}
@Test
public void testUnbind() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.unbind(dn, "Some Person");
try {
// Verify result - check that the operation was not rolled back
ldapTemplate.lookup(dn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
try {
jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" },
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return null;
}
});
fail("EmptyResultDataAccessException expected");
}
catch (EmptyResultDataAccessException expected) {
assertTrue(true);
}
}
}

View File

@@ -0,0 +1,272 @@
/*
* 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.transaction.compensating.manager;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTransactionTestContext.xml" })
public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
private static Log log = LogFactory.getLog(ContextSourceTransactionManagerIntegrationTest.class);
@Autowired
@Qualifier("dummyDao")
private DummyDao dummyDao;
@Autowired
private LdapTemplate ldapTemplate;
@Before
public void prepareTestedInstance() throws Exception {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clearSynchronization();
}
}
@Test
public void testCreateWithException() {
try {
dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
// Verify that no entry was created
try {
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
@Test
public void testCreate() {
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
log.debug("Verifying result");
String expectedDn = "cn=some testperson, ou=company1, c=Sweden";
Object ldapResult = ldapTemplate.lookup(expectedDn);
assertNotNull(ldapResult);
ldapTemplate.unbind(expectedDn);
}
@Test
public void testUpdateWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(ldapResult);
}
@Test
public void testUpdate() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated Person", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(ldapResult);
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
@Test
public void testUpdateAndRenameWithException() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
try {
// Perform test
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify that entry was not moved.
try {
ldapTemplate.lookup(newDn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
// Verify that original entry was not updated.
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
}
@Test
public void testUpdateAndRename() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
// Perform test
dummyDao.updateAndRename(dn, newDn, "Updated description");
// Verify that entry was moved and updated.
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}
@Test
public void testModifyAttributesWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testModifyAttributes() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
// Verify result - check that the operation was not rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated lastname", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testUnbindWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.unbindWithException(dn, "Some Person");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
// Just verify that the entry still exists.
return new Object();
}
});
assertNotNull(ldapResult);
}
@Test
public void testUnbind() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.unbind(dn, "Some Person");
try {
// Verify result - check that the operation was not rolled back
ldapTemplate.lookup(dn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
}

View File

@@ -0,0 +1,372 @@
/*
* 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.transaction.compensating.manager.hibernate;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager;
import org.springframework.ldap.transaction.compensating.manager.DummyException;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* Integration tests for {@link ContextSourceAndHibernateTransactionManager}.
*
* @author Hans Westerbeek
*/
@ContextConfiguration(locations = { "/conf/ldapAndHibernateTransactionTestContext.xml" })
public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
private static Log log = LogFactory.getLog(ContextSourceAndHibernateTransactionManagerIntegrationTest.class);
@Autowired
@Qualifier("dummyDao")
private OrgPersonDao dummyDao;
@Autowired
private LdapTemplate ldapTemplate;
@Autowired
private HibernateTemplate hibernateTemplate;
@Autowired
private SessionFactory sessionFactory;
@Before
public void prepareTest() throws Exception {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clearSynchronization();
}
OrgPerson person = new OrgPerson();
person.setId(new Integer(1));
person.setLastname("Person");
person.setFullname("Some Person");
person.setDescription("Sweden, Company1, Some Person");
person.setCountry("Sweden");
person.setCompany("Company1");
// "Some Person", "Person", "Sweden, Company1, Some Person"
// avoid the transaction manager we have configured, do it manually
Session session = this.sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(person);
tx.commit();
session.close();
}
@After
public void cleanup() throws Exception {
// probably the wrong idea, this will use the thing i am trying to
// test..
Session session = this.sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Query query = session.createQuery("delete from OrgPerson");
query.executeUpdate();
tx.commit();
session.close();
}
@Test
public void testCreateWithException() {
OrgPerson person = new OrgPerson();
person.setId(new Integer(2));
person.setDescription("some description");
person.setFullname("Some testperson");
person.setLastname("testperson");
person.setCountry("Sweden");
person.setCompany("company1");
try {
dummyDao.createWithException(person);
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
// Verify that no entry was created in ldap or hibernate db
try {
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
List result = hibernateTemplate.findByNamedParam("from OrgPerson person where person.lastname = :lastname",
"lastname", person.getLastname());
assertTrue(result.size() == 0);
}
@Test
public void testCreate() {
OrgPerson person = new OrgPerson();
person.setId(new Integer(2));
person.setDescription("some description");
person.setFullname("Some testperson");
person.setLastname("testperson");
person.setCountry("Sweden");
person.setCompany("company1");
// dummyDao.create("Sweden", "company1", "some testperson",
// "testperson", "some description");
this.dummyDao.create(person);
person = null;
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
OrgPerson fromDb = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(2));
assertNotNull(ldapResult);
assertNotNull(fromDb);
}
@Test
public void testUpdateWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
OrgPerson originalPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
originalPerson.setLastname("fooo");
try {
dummyDao.updateWithException(originalPerson);
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertNotNull("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
assertEquals("Person", notUpdatedPerson.getLastname());
assertEquals("Sweden, Company1, Some Person", notUpdatedPerson.getDescription());
assertNotNull(ldapResult);
// no need to assert if notUpdatedPerson exists
}
@Test
public void testUpdate() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
person.setLastname("Updated Person");
person.setDescription("Updated description");
dummyDao.update(person);
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated Person", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
assertEquals("Updated Person", updatedPerson.getLastname());
assertEquals("Updated description", updatedPerson.getDescription());
assertNotNull(ldapResult);
}
@Test
public void testUpdateAndRenameWithException() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
person.setLastname("Updated Person");
person.setDescription("Updated description");
try {
// Perform test
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify that entry was not moved.
try {
ldapTemplate.lookup(newDn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
// Verify that original entry was not updated.
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
}
@Test
public void testUpdateAndRename() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
// Perform test
dummyDao.updateAndRename(dn, newDn, "Updated description");
// Verify that entry was moved and updated.
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
}
@Test
public void testModifyAttributesWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testModifyAttributes() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
// Verify result - check that the operation was not rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated lastname", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testUnbindWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
try {
// Perform test
dummyDao.unbindWithException(person);
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
person = null;
// Verify result - check that the operation was properly rolled back
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
// Just verify that the entry still exists.
return new Object();
}
});
person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); // will
// throw
// exception
// of
// person
// does
// not
// exist
assertNotNull(ldapResult);
}
@Test
public void testUnbind() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
dummyDao.unbind(person);
try {
// Verify result - check that the operation was not rolled back
ldapTemplate.lookup(dn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
assertNull(person);
}
}

View 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

View File

@@ -0,0 +1,5 @@
ou=groups,dc=jayway,dc=se
c=Sweden,dc=jayway,dc=se
c=Norway,dc=jayway,dc=se

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="false">
<class name="org.springframework.ldap.transaction.compensating.manager.hibernate.OrgPerson" table="PERSON">
<id name="id" column="id">
<generator class="assigned"/>
</id>
<property name="fullname" column="fullname"/>
<property name="lastname" column="lastname"/>
<property name="company" column="company"/>
<property name="country" column="country"/>
<property name="description" column="description"/>
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,89 @@
<?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">
<!-- Used mainly to enable injecting base into LdapServerManager -->
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
<!-- 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>

View File

@@ -0,0 +1,40 @@
<?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.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="contextSource2"
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="cn=john doe, ${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="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor">
<property name="baseLdapPathSourceName" value="contextSource2" />
</bean>
</beans>

View File

@@ -0,0 +1,38 @@
<?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.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="contextSource2"
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="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
</beans>

View File

@@ -0,0 +1,13 @@
<?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="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
</beans>

View File

@@ -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/commonTestContext.xml"/>
<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="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor">
<property name="basePath" value="cn=john doe"/>
</bean>
</beans>

View File

@@ -0,0 +1,28 @@
<?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.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="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
</beans>

View File

@@ -0,0 +1,33 @@
<?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.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="contextSourceProxy"
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="dummyBaseContextAware"
class="org.springframework.ldap.core.support.DummyBaseLdapPathAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
</beans>

View File

@@ -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>

View File

@@ -0,0 +1,11 @@
<?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="distinguishedNameConsumer"
class="org.springframework.ldap.core.DummyDistinguishedNameConsumer">
<property name="distinguishedName" value="dc=jayway, dc=se" />
</bean>
</beans>

View File

@@ -0,0 +1,11 @@
<?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 class="org.springframework.ldap.filter.DummyFilterConsumer">
<property name="filter"
value="(&amp;(objectclass=person)(!(objectclass=computer))" />
</bean>
</beans>

View File

@@ -0,0 +1,4 @@
urls=ldap://127.0.0.1:3900
userDn=uid=admin,ou=system
password=secret
base=dc=jayway,dc=se

View File

@@ -0,0 +1,80 @@
<?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" />
<property name="pooled" value="false" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:aname" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="transactedContextSource"
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="transactedContextSource" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>conf/OrgPerson.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.hbm2ddl.auto=create
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="contextSource" ref="transactedContextSource" />
</bean>
<bean name="dummyDaoTarget"
class="org.springframework.ldap.transaction.compensating.manager.hibernate.DummyDaoLdapAndHibernateImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="dummyDao"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"
ref="transactionManager" />
<property name="target" ref="dummyDaoTarget" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,66 @@
<?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" />
<property name="pooled" value="false" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:aname" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="transactedContextSource"
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="transactedContextSource" />
</bean>
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager"
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="contextSource" ref="transactedContextSource" />
</bean>
<bean name="dummyDaoTarget"
class="org.springframework.ldap.transaction.compensating.manager.LdapAndJdbcDummyDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean name="dummyDao"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"
ref="transactionManager" />
<property name="target" ref="dummyDaoTarget" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,11 @@
<?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="contextSource2" class="org.springframework.ldap.core.support.LdapContextSource" >
<property name="urls" value="ldap://127.0.0.1:389,ldap://127.0.0.2:389" />
<property name="userDn" value="cn=dummy" />
<property name="password" value="dummy" />
</bean>
</beans>

View File

@@ -0,0 +1,66 @@
<?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" />
<property name="authenticationSource">
<bean
class="org.springframework.ldap.authentication.AcegiAuthenticationSource" />
</property>
<property name="baseOnTarget" value="false" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="initialDirContextFactory"
class="org.acegisecurity.ldap.DefaultInitialDirContextFactory">
<constructor-arg value="${urls}/${base}" />
<property name="managerDn" value="${userDn}" />
<property name="managerPassword" value="${password}" />
</bean>
<bean id="userSearch"
class="org.acegisecurity.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0">
<value></value>
</constructor-arg>
<constructor-arg index="1"
value="(&amp;(cn={0})(objectclass=person))" />
<constructor-arg index="2" ref="initialDirContextFactory" />
<property name="searchSubtree" value="true" />
</bean>
<bean id="ldapAuthProvider"
class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider">
<constructor-arg>
<bean
class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator">
<constructor-arg ref="initialDirContextFactory" />
<property name="userSearch" ref="userSearch" />
</bean>
</constructor-arg>
<constructor-arg>
<bean
class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="initialDirContextFactory" />
<constructor-arg value="c=Sweden" />
<property name="groupRoleAttribute" value="ou" />
</bean>
</constructor-arg>
</bean>
</beans>

View File

@@ -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" />
<property name="baseOnTarget" value="false" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<!--
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
-->
</beans>

View File

@@ -0,0 +1,24 @@
<?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" />
<property name="dirObjectFactory"><null/></property>
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,26 @@
<?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 id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
-->
</beans>

View File

@@ -0,0 +1,52 @@
<?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" />
<property name="pooled" value="false" />
</bean>
<bean id="transactedContextSource"
class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="transactedContextSource" />
</bean>
<bean id="transactionManager"
class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
<property name="contextSource" ref="transactedContextSource" />
</bean>
<bean name="dummyDaoTarget"
class="org.springframework.ldap.transaction.compensating.manager.LdapDummyDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<bean name="dummyDao"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"
ref="transactionManager" />
<property name="target" ref="dummyDaoTarget" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,25 @@
<?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" />
<!-- note that this has no base set, since we want to get at the root entry -->
<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" />
<property name="baseOnTarget" value="false" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,26 @@
<?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="simpleLdapTemplate"
class="org.springframework.ldap.core.simple.SimpleLdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<!--
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
-->
</beans>

View File

@@ -0,0 +1,9 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%r [%t] %-5p\: %-15c{2} - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Enable info on Spring LDAP
#log4j.logger.org.springframework.ldap=INFO
log4j.logger.org.apache.directory.server.schema.registries.DefaultSyntaxRegistry=WARN

View 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

62
test/pom.xml Normal file
View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-ldap-integration-tests-parent</artifactId>
<packaging>pom</packaging>
<name>Spring LDAP Integration Tests</name>
<modules>
<module>integration-tests</module>
</modules>
<profiles>
<profile>
<id>openldap</id>
<modules>
<module>integration-tests-openldap</module>
</modules>
</profile>
<profile>
<id>sunone</id>
<modules>
<module>integration-tests-sunone</module>
</modules>
</profile>
</profiles>
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${pom.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Logging dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>