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,4 @@
urls=ldap://127.0.0.1
userDn=cn=manager,dc=jayway,dc=se
password=secret
base=dc=jayway,dc=se

View File

@@ -0,0 +1,28 @@
#
# LDAP Defaults
#
# See ldap.conf(5) for details
# This file should be world readable but not world writable.
#BASE dc=example, dc=com
#URI ldap://ldap.example.com ldap://ldap-master.example.com:666
#SIZELIMIT 12
#TIMELIMIT 15
#DEREF never
include "c:/Program/OpenLDAP/schema/core.schema"
include "c:/Program/OpenLDAP/schema/cosine.schema"
include "c:/Program/OpenLDAP/schema/inetorgperson.schema"
database bdb
suffix "dc=jayway,dc=se"
rootdn "cn=Manager,dc=jayway,dc=se"
rootpw secret
directory "c:/Program/OpenLDAP/data"
TLSCipherSuite HIGH:MEDIUM:+SSLv2
TLSCACertificateFile /tmp/cacert.pem
TLSCertificateFile /tmp/servercrt.pem
TLSCertificateKeyFile /tmp/serverkey.pem
TLSVerifyClient never

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">
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/conf/ldap-openldap.properties" />
</bean>
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource" >
<property name="urls" value="${urls}" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
<property name="base" value="${base}" />
<property name="anonymousReadOnly" value="true" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,220 @@
/*
* 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;
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.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the lookup methods of LdapTemplate on OpenLdap.
*
* @author Mattias Arthursson
* @author Ulrik Sandberg
*/
public class LdapTemplateLookupOpenLdapITest extends
AbstractDependencyInjectionSpringContextTests {
private LdapTemplate tested;
protected String[] getConfigLocations() {
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
}
/**
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
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"));
}
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());
}
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
public void 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 Person+Person", 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.
*/
public void 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+Person", result
.getStringAttribute("description"));
}
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());
}
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());
}
public void setTested(LdapTemplate tested) {
this.tested = tested;
}
}

View File

@@ -0,0 +1,157 @@
/*
* 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 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.springframework.ldap.Person;
import org.springframework.ldap.PersonAttributesMapper;
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.SearchExecutor;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* 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
*/
public class LdapTemplatePagedSearchITest extends
AbstractDependencyInjectionSpringContextTests {
private static final Name BASE = DistinguishedName.EMPTY_PATH;
private static final String FILTER_STRING = "(&(objectclass=person))";
private LdapTemplate tested;
private CollectingNameClassPairCallbackHandler callbackHandler;
private SearchControls searchControls;
protected String[] getConfigLocations() {
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
}
protected void onSetUp() throws Exception {
super.onSetUp();
PersonAttributesMapper mapper = new PersonAttributesMapper();
callbackHandler = new AttributesMapperCallbackHandler(mapper);
searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
protected void onTearDown() throws Exception {
super.onTearDown();
callbackHandler = null;
tested = null;
searchControls = null;
}
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());
}
public void setTested(LdapTemplate tested) {
this.tested = tested;
}
}

View File

@@ -0,0 +1,143 @@
/*
* 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 java.util.List;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import org.springframework.ldap.Person;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.AttributesMapperCallbackHandler;
import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.SearchExecutor;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the still experimental sorted search result capability of LdapTemplate.
*
* @author Ulrik Sandberg
*/
public class LdapTemplateSortedSearchITest extends
AbstractDependencyInjectionSpringContextTests {
private static final Name BASE = DistinguishedName.EMPTY_PATH;
private static final String FILTER_STRING = "(&(objectclass=ikeaperson)(cn=gor*))";
private LdapTemplate tested;
private CollectingNameClassPairCallbackHandler callbackHandler;
private SearchControls searchControls;
protected String[] getConfigLocations() {
return new String[] { "/conf/ldapTemplateTestContext-openldap.xml" };
}
protected void onSetUp() throws Exception {
super.onSetUp();
PersonAttributesMapper mapper = new PersonAttributesMapper();
callbackHandler = new AttributesMapperCallbackHandler(mapper);
searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
protected void onTearDown() throws Exception {
super.onTearDown();
callbackHandler = null;
tested = null;
searchControls = null;
}
public void testSearch_SortControl() {
SearchExecutor searchExecutor = new SearchExecutor() {
public NamingEnumeration executeSearch(DirContext ctx)
throws NamingException {
return ctx.search(BASE, FILTER_STRING, searchControls);
}
};
SortControlDirContextProcessor requestControl;
// Prepare for first search
requestControl = new SortControlDirContextProcessor("cn");
tested.search(searchExecutor, callbackHandler, requestControl);
int resultCode = requestControl.getResultCode();
boolean sorted = requestControl.isSorted();
assertTrue("Search result should have been sorted: " + resultCode, sorted);
List list = callbackHandler.getList();
assertSortedList(list);
}
public void testSearch_SortControl_ConvenienceMethod() {
SortControlDirContextProcessor requestControl;
// Prepare for first search
requestControl = new SortControlDirContextProcessor("cn");
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler,
requestControl);
int resultCode = requestControl.getResultCode();
boolean sorted = requestControl.isSorted();
assertTrue("Search result should have been sorted: " + resultCode, sorted);
List list = callbackHandler.getList();
assertSortedList(list);
}
private void assertSortedList(List list) {
Person person;
assertEquals(6, list.size());
person = (Person) list.get(0);
assertEquals("Goran Milenkovic", person.getFullname());
person = (Person) list.get(1);
assertEquals("Goran Sundberg", person.getFullname());
person = (Person) list.get(2);
assertEquals("Goran Westerberg", person.getFullname());
person = (Person) list.get(3);
assertEquals("Gorana Milicevic", person.getFullname());
person = (Person) list.get(4);
assertEquals("Gordana Canic", person.getFullname());
person = (Person) list.get(5);
assertEquals("Gordana Russ", person.getFullname());
}
public void setTested(LdapTemplate tested) {
this.tested = tested;
}
private 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.setDescription((String) attributes.get("givenName").get());
return person;
}
}
}