LDAP-279: Configuration tweaks. Removed simple-odm sample.

This commit is contained in:
Mattias Hellborg Arthursson
2013-11-08 08:49:55 +01:00
parent c438764891
commit 7610961d25
28 changed files with 201 additions and 798 deletions

View File

@@ -7,37 +7,53 @@
<context:property-placeholder location="classpath:/ldap.properties" />
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:18880"
username="${userDn}"
base="dc=jayway,dc=se" />
password="${sample.ldap.password}"
url="${sample.ldap.url}"
username="${sample.ldap.userDn}"
base="${sample.ldap.base}" />
<ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>
<!--
This is for test and demo purposes only - the TestContextSourceFactoryBean starts an in-process
Apache Directory Server instance and populates it with data from the specified LDIF file.
A real-world application would use a DirContextSource instead.
-->
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
<property name="contextSource" ref="contextSource" />
<bean id="ldapTreeBuilder"
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
<constructor-arg ref="ldapTemplate" />
</bean>
<bean id="ldapTreeBuilder"
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
<constructor-arg ref="ldapTemplate" />
</bean>
<bean id="personDao"
class="org.springframework.ldap.samples.odm.dao.OdmPersonDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<bean id="personDao"
class="org.springframework.ldap.samples.odm.dao.OdmPersonDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<beans profile="default">
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
<!--
This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
LDAP server.
-->
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${sample.ldap.base}" />
<property name="port" value="18880" />
</bean>
</beans>
<beans profile="no-apacheds">
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
</beans>
</beans>

View File

@@ -1,4 +1,5 @@
urls=ldap://127.0.0.1:18880
userDn=uid=admin,ou=system
password=secret
base=dc=jayway,dc=se
sample.ldap.url=ldap://127.0.0.1:18880
sample.ldap.userDn=uid=admin,ou=system
sample.ldap.password=secret
sample.ldap.base=dc=jayway,dc=se
sample.ldap.clean=true

View File

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

View File

@@ -1,24 +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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/config/ldap.properties" />
<property name="location" value="classpath:/ldap.properties" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<property name="ldifFile" value="/setup_data.ldif" />
<property name="port" value="18880" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<ldap:context-source id="contextSource"
password="${sample.ldap.password}"
url="${sample.ldap.url}"
username="${sample.ldap.userDn}"
base="${sample.ldap.base}" />
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
<!--
This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
LDAP server.
-->
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${sample.ldap.base}" />
<property name="port" value="18880" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>

View File

@@ -8,27 +8,13 @@
<context:property-placeholder location="classpath:/ldap.properties" />
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:18880"
username="${userDn}"
base="dc=jayway,dc=se" />
password="${sample.ldap.password}"
url="${sample.ldap.url}"
username="${sample.ldap.userDn}"
base="${sample.ldap.base}" />
<ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>
<!--
This is for test and demo purposes only - the TestContextSourceFactoryBean starts an in-process
Apache Directory Server instance and populates it with data from the specified LDIF file.
A real-world application would use a DirContextSource instead.
-->
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
<property name="contextSource" ref="contextSource" />
</bean>
<bean id="ldapTreeBuilder"
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
<constructor-arg ref="ldapTemplate" />
@@ -39,4 +25,36 @@
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<beans profile="default">
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
<!--
This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
LDAP server.
-->
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${sample.ldap.base}" />
<property name="port" value="18880" />
</bean>
</beans>
<beans profile="no-apacheds">
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
</beans>
</beans>

View File

@@ -1,4 +1,5 @@
urls=ldap://127.0.0.1:18880
userDn=uid=admin,ou=system
password=secret
base=dc=jayway,dc=se
sample.ldap.url=ldap://127.0.0.1:18880
sample.ldap.userDn=uid=admin,ou=system
sample.ldap.password=secret
sample.ldap.base=dc=jayway,dc=se
sample.ldap.clean=true

View File

@@ -1,22 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/config/ldap.properties" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.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="/setup_data.ldif" />
<property name="port" value="18880" />
<property name="location" value="classpath:/ldap.properties" />
</bean>
<ldap:context-source id="contextSource"
password="${sample.ldap.password}"
url="${sample.ldap.url}"
username="${sample.ldap.userDn}"
base="${sample.ldap.base}" />
<!-- Populates the LDAP server with initial data -->
<bean class="org.springframework.ldap.test.LdifPopulator" depends-on="embeddedLdapServer">
<property name="contextSource" ref="contextSource" />
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=jayway,dc=se" />
</bean>
<!--
This is for test and demo purposes only - EmbeddedLdapServerFactoryBean launches an in-process
LDAP server.
-->
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${sample.ldap.base}" />
<property name="port" value="18880" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />

7
samples/readme.md Normal file
View File

@@ -0,0 +1,7 @@
## Spring LDAP Samples
Refer to these sample projects for some examples on using Spring LDAP
* plain - demonstrates 'plain' usage of Spring LDAP
* odm - demonstrates the Object-Directory mapping functionality
* user-admin - a fully functional user admin application implemented using Spring LDAP

View File

@@ -1,22 +0,0 @@
apply from: JAVA_SCRIPT
sonarRunner {
skipProject = true
}
dependencies {
compile project(":spring-ldap-core"),
project(":spring-ldap-odm"),
"org.springframework:spring-core:$springVersion",
"org.springframework:spring-context:$springVersion",
"commons-pool:commons-pool:$commonsPoolVersion"
runtime ("log4j:log4j:$log4jVersion") {
exclude group: 'javax.jms'
exclude group: 'com.sun.jdmk'
exclude group: 'com.sun.jmx'
}
testCompile project(":spring-ldap-test"),
"junit:junit:$junitVersion"
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2005-2013 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.odm.sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ldap.odm.core.OdmManager;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.ldap.LdapName;
import java.util.List;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
// A very simple example - just showing how little code you actually need to write
// when using Spring LDAP ODM
public class SearchForPeople {
private static final LdapName baseDn = LdapUtils.newLdapName("o=Whoniverse");
private static void print(List<SimplePerson> personList) {
for (SimplePerson person : personList) {
System.out.println(person);
}
}
public static void main(String[] argv) {
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "spring.xml" });
// Grab the OdmManager wired by Spring
OdmManager odmManager = (OdmManager)context.getBean("odmManager");
// Find people with a surname of Harvey
List<SimplePerson> searchResults = odmManager.search(SimplePerson.class, query().base(baseDn).where("sn").is("Harvey"));
// Print the results
print(searchResults);
}
}

View File

@@ -1,233 +0,0 @@
/*
* Copyright 2005-2013 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.odm.sample;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import javax.naming.Name;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import static org.springframework.ldap.odm.annotations.Attribute.Type;
/**
* Automatically generated to represent the LDAP object classes
* "person", "top".
*/
@Entry(objectClasses={"person", "top"})
public final class SimplePerson {
@Id
private Name dn;
@Attribute(name="objectClass", syntax="1.3.6.1.4.1.1466.115.121.1.38")
private List<String> objectClass=new ArrayList<String>();
@Attribute(name="cn", syntax="1.3.6.1.4.1.1466.115.121.1.15")
private List<String> cn=new ArrayList<String>();
@Attribute(name="sn", syntax="1.3.6.1.4.1.1466.115.121.1.15")
private List<String> sn=new ArrayList<String>();
@Attribute(name="description", syntax="1.3.6.1.4.1.1466.115.121.1.15")
private List<String> description=new ArrayList<String>();
@Attribute(name="userPassword", syntax="1.3.6.1.4.1.1466.115.121.1.40", type=Type.BINARY)
private List<byte[]> userPassword=new ArrayList<byte[]>();
@Attribute(name="telephoneNumber", syntax="1.3.6.1.4.1.1466.115.121.1.50")
private List<String> telephoneNumber=new ArrayList<String>();
@Attribute(name="seeAlso", syntax="1.3.6.1.4.1.1466.115.121.1.12")
private List<String> seeAlso=new ArrayList<String>();
public Name getDn() {
return dn;
}
public void setDn(Name dn) {
this.dn=dn;
}
public Iterator<String> getObjectClassIterator() {
return Collections.unmodifiableList(objectClass).iterator();
}
public void addCn(String cn) {
this.cn.add(cn);
}
public void removeCn(String cn) {
this.cn.remove(cn);
}
public Iterator<String> getCnIterator() {
return cn.iterator();
}
public void addSn(String sn) {
this.sn.add(sn);
}
public void removeSn(String sn) {
this.sn.remove(sn);
}
public Iterator<String> getSnIterator() {
return sn.iterator();
}
public void addDescription(String description) {
this.description.add(description);
}
public void removeDescription(String description) {
this.description.remove(description);
}
public Iterator<String> getDescriptionIterator() {
return description.iterator();
}
public void addUserPassword(byte[] userPassword) {
this.userPassword.add(userPassword);
}
public void removeUserPassword(byte[] userPassword) {
this.userPassword.remove(userPassword);
}
public Iterator<byte[]> getUserPasswordIterator() {
return userPassword.iterator();
}
public void addTelephoneNumber(String telephoneNumber) {
this.telephoneNumber.add(telephoneNumber);
}
public void removeTelephoneNumber(String telephoneNumber) {
this.telephoneNumber.remove(telephoneNumber);
}
public Iterator<String> getTelephoneNumberIterator() {
return telephoneNumber.iterator();
}
public void addSeeAlso(String seeAlso) {
this.seeAlso.add(seeAlso);
}
public void removeSeeAlso(String seeAlso) {
this.seeAlso.remove(seeAlso);
}
public Iterator<String> getSeeAlsoIterator() {
return seeAlso.iterator();
}
@Override
public String toString() {
StringBuilder result=new StringBuilder();
result.append(String.format("dn=%1$s", dn));
result.append(String.format(" | objectClass=%1$s", objectClass));
result.append(String.format(" | cn=%1$s", cn));
result.append(String.format(" | sn=%1$s", sn));
result.append(String.format(" | description=%1$s", description));
result.append(String.format(" | userPassword=%1$s", userPassword));
result.append(String.format(" | telephoneNumber=%1$s", telephoneNumber));
result.append(String.format(" | seeAlso=%1$s", seeAlso));
return result.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dn == null) ? 0 : dn.hashCode());
result = prime * result + ((objectClass == null) ? 0 : (new HashSet<String>(objectClass)).hashCode());
result = prime * result + ((cn == null) ? 0 : (new HashSet<String>(cn)).hashCode());
result = prime * result + ((sn == null) ? 0 : (new HashSet<String>(sn)).hashCode());
result = prime * result + ((description == null) ? 0 : (new HashSet<String>(description)).hashCode());
result = prime * result + ((userPassword == null) ? 0 : (new HashSet<byte[]>(userPassword)).hashCode());
result = prime * result + ((telephoneNumber == null) ? 0 : (new HashSet<String>(telephoneNumber)).hashCode());
result = prime * result + ((seeAlso == null) ? 0 : (new HashSet<String>(seeAlso)).hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SimplePerson other = (SimplePerson) obj;
if (dn == null) {
if (other.dn != null)
return false;
} else if (!dn.equals(other.dn))
return false;
if (objectClass == null) {
if (other.objectClass != null)
return false;
} else if (!(new HashSet<String>(objectClass)).equals(new HashSet<String>(other.objectClass)))
return false;
if (cn == null) {
if (other.cn != null)
return false;
} else if (!(new HashSet<String>(cn)).equals(new HashSet<String>(other.cn)))
return false;
if (sn == null) {
if (other.sn != null)
return false;
} else if (!(new HashSet<String>(sn)).equals(new HashSet<String>(other.sn)))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!(new HashSet<String>(description)).equals(new HashSet<String>(other.description)))
return false;
if (userPassword == null) {
if (other.userPassword != null)
return false;
} else if (!(new HashSet<byte[]>(userPassword)).equals(new HashSet<byte[]>(other.userPassword)))
return false;
if (telephoneNumber == null) {
if (other.telephoneNumber != null)
return false;
} else if (!(new HashSet<String>(telephoneNumber)).equals(new HashSet<String>(other.telephoneNumber)))
return false;
if (seeAlso == null) {
if (other.seeAlso != null)
return false;
} else if (!(new HashSet<String>(seeAlso)).equals(new HashSet<String>(other.seeAlso)))
return false;
return true;
}
}

View File

@@ -1,7 +0,0 @@
/**
* A very simple example of the use of Spring ODM.
*
* @author Paul Harvey &lt;paul.at.pauls-place.me.uk>
*/
package org.springframework.ldap.odm.sample;

View File

@@ -1,19 +0,0 @@
log4j.rootLogger=error, stdout
log4j.logger.org.springframework.ldap.odm=error
log4j.logger.org.springframework=error
# Messages to the console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
# Message to a log file
log4j.appender.log=org.apache.log4j.RollingFileAppender
log4j.appender.log.File=jndi.log
log4j.appender.log.MaxFileSize=100KB
log4j.appender.log.MaxBackupIndex=1
log4j.appender.log.layout=org.apache.log4j.PatternLayout
log4j.appender.log.layout.ConversionPattern=%p %t %c - %m%n

View File

@@ -1,96 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- An example Spring configuration for Spring LDAP ODM -->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<bean id="fromStringConverter" class="org.springframework.ldap.odm.typeconversion.impl.converters.FromStringConverter" />
<bean id="toStringConverter" class="org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter" />
<bean id="converterManager" class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean">
<property name="converterConfig">
<set>
<bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="converter" ref="fromStringConverter" />
</bean>
<bean class="org.springframework.ldap.odm.typeconversion.impl.ConverterManagerFactoryBean$ConverterConfig">
<property name="fromClasses">
<set>
<value>java.lang.Byte</value>
<value>java.lang.Short</value>
<value>java.lang.Integer</value>
<value>java.lang.Long</value>
<value>java.lang.Float</value>
<value>java.lang.Double</value>
<value>java.lang.Boolean</value>
</set>
</property>
<property name="toClasses">
<set>
<value>java.lang.String</value>
</set>
</property>
<property name="converter" ref="toStringConverter" />
</bean>
</set>
</property>
</bean>
<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://127.0.0.1:10389" />
<property name="userDn" value="uid=admin,ou=system" />
<property name="password" value="secret" />
<property name="pooled" value="false" />
</bean>
<bean id="dirContextValidator" class="org.springframework.ldap.pool.validation.DefaultDirContextValidator">
<property name="base" value="" />
<property name="filter" value="objectclass=*" />
<property name="searchControls.searchScope">
<util:constant static-field="javax.naming.directory.SearchControls.OBJECT_SCOPE" />
</property>
</bean>
<bean id="contextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="maxActive" value="10" />
<property name="maxTotal" value="10" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="1" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
</bean>
<bean id="odmManager" class="org.springframework.ldap.odm.core.impl.OdmManagerImplFactoryBean">
<property name="converterManager" ref="converterManager" />
<property name="contextSource" ref="contextSource" />
<property name="managedClasses">
<set>
<value>org.springframework.ldap.odm.sample.SimplePerson</value>
</set>
</property>
</bean>
</beans>

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2005-2013 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.odm.sample.test;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.odm.sample.SearchForPeople;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.LdapTestUtils;
import javax.naming.ldap.LdapName;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.Assert.assertEquals;
public class TestSearchForPeople {
// Base DN for test data
private static final LdapName baseName = LdapUtils.newLdapName("o=Whoniverse");
private static final String PRINCIPAL="uid=admin,ou=system";
private static final String CREDENTIALS="secret";
// This port MUST be free on local host for these unit tests to function.
private static int PORT=10389;
@BeforeClass
public static void setUpClass() throws Exception {
// Start an LDAP server and import test data
LdapTestUtils.startEmbeddedServer(PORT, baseName.toString(), "odm-test");
}
@AfterClass
public static void tearDownClass() throws Exception {
LdapTestUtils.shutdownEmbeddedServer();
}
@Before
public void setUp() throws Exception {
// Bind to the directory
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://127.0.0.1:" + PORT);
contextSource.setUserDn("");
contextSource.setPassword("");
contextSource.setPooled(false);
contextSource.afterPropertiesSet();
// Create the Sprint LDAP template
LdapTemplate template = new LdapTemplate(contextSource);
// Clear out any old data - and load the test data
LdapTestUtils.cleanAndSetup(template.getContextSource(), baseName, new ClassPathResource("testdata.ldif"));
}
@After
public void tearDown() {
}
// Very simple test - mainly just to exercise the code and to
// ensure we get representative test coverage
@Test
public void runSample() throws Exception {
PrintStream originalOut=System.out;
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output));
SearchForPeople.main(null);
assertEquals("dn=cn=Bramble Harvey,ou=Doctors,o=Whoniverse | objectClass=[person, top] | cn=[Bramble Harvey] | sn=[Harvey] | description=[Really not a Doctor] | userPassword=[] | telephoneNumber=[22] | seeAlso=[]",
output.toString().trim());
} finally {
System.setOut(originalOut);
}
}
}

View File

@@ -1,105 +0,0 @@
dn: ou=Enemies,o=Whoniverse
objectClass: organizationalUnit
objectClass: top
ou: Blizzard
dn: ou=Assistants,o=Whoniverse
objectClass: organizationalUnit
objectClass: top
ou: Blizzard
dn: ou=Doctors,o=Whoniverse
objectClass: organizationalUnit
objectClass: top
ou: NCSoft
dn: cn=William Hartnell,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: William Hartnell
description: First Doctor
description: Grumpy
sn: Hartnell
telephonenumber: 1
dn: cn=Patrick Troughton,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Patrick Troughton
description: Second Doctor
description:Clown
sn: Troughton
telephonenumber: 2
dn: cn=Jon Pertwee,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Jon Pertwee
description: Third Doctor
description: Dandy
sn: Pertwee
telephonenumber: 3
dn: cn=Tom Baker,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Tom Baker
description: Fourth Doctor
description: The one and only!
sn: Baker
telephonenumber: 4
dn: cn=Peter Davison,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Peter Davison
description: Fifth Doctor
sn: Davison
telephonenumber: 5
dn: cn=Bramble Harvey,ou=Doctors,o=Whoniverse
objectClass: person
objectClass: top
cn: Bramble Harvey
description: Really not a Doctor
sn: Harvey
telephonenumber: 22
dn: cn=Davros,ou=Enemies,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Davros
description: Creator of the Daleks
description: Kaled head scientist
sn: Unknown
dn: cn=Daleks,ou=Enemies,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Daleks
description: The Doctor's greatest foe
sn: NA
dn: cn=Master,ou=Enemies,o=Whoniverse
objectClass: person
objectClass: inetorgperson
objectclass: organizationalperson
objectClass: top
cn: Master
description: An evil Time Lord
sn: Unknown

View File

@@ -29,7 +29,7 @@ import java.util.Set;
* @author Mattias Hellborg Arthursson
*/
@Entry(objectClasses = {"groupOfNames", "top"}, base = "ou=Groups")
public class Group {
public final class Group {
@Id
private Name id;

View File

@@ -29,7 +29,7 @@ import javax.naming.Name;
* @author Mattias Hellborg Arthursson
*/
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" }, base = "ou=Departments")
public class User {
public final class User {
@Id
private Name id;

View File

@@ -62,6 +62,7 @@
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=example,dc=com" />
</bean>
<!--
@@ -82,6 +83,7 @@
<property name="resource" value="classpath:/setup_data.ldif" />
<property name="base" value="${sample.ldap.base}" />
<property name="clean" value="${sample.ldap.clean}" />
<property name="defaultBase" value="dc=example,dc=com" />
</bean>
</beans>
</beans>

View File

@@ -1,6 +0,0 @@
sample.ldap.url=ldap://127.0.0.1:18880
sample.ldap.userDn=uid=admin,ou=system
sample.ldap.password=secret
sample.ldap.base=dc=example,dc=com
sample.ldap.clean=true
sample.ldap.directory.type=NORMAL

View File

@@ -16,7 +16,6 @@ include 'test/integration-tests-sunone'
include 'test/integration-tests-ad'
include 'samples/plain'
include 'samples/odm'
include 'samples/simple-odm'
include 'samples/user-admin'

View File

@@ -31,15 +31,15 @@ import java.util.List;
/**
* @author Mattias Hellborg Arthursson
* @since 2.0
*/
public class LdifPopulator implements InitializingBean {
private final static String DEFAULT_BASE = "dc=example,dc=com";
private Resource resource;
private ContextSource contextSource;
private String base = "";
private boolean clean = false;
private String defaultBase;
public void setContextSource(ContextSource contextSource) {
this.contextSource = contextSource;
@@ -57,18 +57,22 @@ public class LdifPopulator implements InitializingBean {
this.clean = clean;
}
public void setDefaultBase(String defaultBase) {
this.defaultBase = defaultBase;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(contextSource, "ContextSource must be specified");
Assert.notNull(resource, "Resource must be specified");
if(!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(DEFAULT_BASE))) {
if(!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(defaultBase))) {
List<String> lines = IOUtils.readLines(resource.getInputStream());
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
for (String line : lines) {
writer.println(StringUtils.replace(line, DEFAULT_BASE, base));
writer.println(StringUtils.replace(line, defaultBase, base));
}
writer.flush();

View File

@@ -40,10 +40,6 @@ public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateInteg
@Autowired
private LdapTemplate tested;
protected String[] getConfigLocations() {
return new String[] {"/conf/ldapTemplateTestContext.xml"};
}
@Test
public void testSearch_AttributeMapper() throws Exception {
AttributesMapper mapper = new PersonAttributesMapper();

View File

@@ -3,27 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<beans profile="default">
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="${base}" />
<ldap:context-source url="${url}"
base="${base}"
username="${userDn}"
password="${password}"/>
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="${base}" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<beans profile="default">
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${base}" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
</bean>
</beans>
<beans profile="no-apacheds">
<ldap:context-source url="${url}"
base="${base}"
username="${userDn}"
password="${password}"/>
</beans>
</beans>

View File

@@ -3,24 +3,18 @@
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">
<beans profile="default">
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="${base}" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<property name="port" value="1888" />
<property name="pooled" value="false" />
</bean>
</beans>
<beans profile="no-apacheds">
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="base" value="${base}" />
<property name="url" value="${url}" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
</bean>
</beans>
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="base" value="${base}" />
<property name="url" value="${url}" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
</bean>
<beans profile="default">
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${base}" />
<property name="port" value="1888" />
</bean>
</beans>
</beans>

View File

@@ -1,4 +1,4 @@
url=ldap://127.0.0.1:389
url=ldap://127.0.0.1:1888
userDn=uid=admin,ou=system
password=secret
base=dc=261consulting,dc=com

View File

@@ -10,24 +10,15 @@
<constructor-arg ref="contextSource" />
</bean>
<beans profile="default">
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"/>
<ldap:context-source url="${url}"
username="${userDn}"
password="${password}"/>
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="${base}" />
<property name="defaultPartitionName" value="jayway" />
<beans profile="default">
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${base}" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
<property name="baseOnTarget" value="false" />
</bean>
</beans>
<beans profile="no-apacheds">
<ldap:context-source url="${url}"
username="${userDn}"
password="${password}"/>
</beans>
</beans>

View File

@@ -11,22 +11,16 @@
<constructor-arg ref="contextSource" />
</bean>
<ldap:context-source url="${url}"
username="${userDn}"
password="${password}"/>
<beans profile="default">
<!-- 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="${base}" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<bean id="embeddedLdapServer" class="org.springframework.ldap.test.EmbeddedLdapServerFactoryBean">
<property name="partitionName" value="example"/>
<property name="partitionSuffix" value="${base}" />
<property name="port" value="1888" />
<property name="baseOnTarget" value="false" />
</bean>
</beans>
<beans profile="no-apacheds">
<ldap:context-source url="ldap://localhost:389"
username="${userDn}"
password="${password}"/>
</beans>
</beans>