Polish Unbounded Support

* Remove copied deprecated methods
* Close ClasspathXmlApplicationContext
* Change apacheDsDependencies to test vs optional
* Formatting

Issue: gh-399
This commit is contained in:
Rob Winch
2016-09-30 15:17:45 -05:00
parent 594c361658
commit 1a5bead76d
12 changed files with 123 additions and 148 deletions

View File

@@ -10,8 +10,6 @@ dependencies {
"commons-logging:commons-logging:$commonsLoggingVersion",
"commons-cli:commons-cli:1.2"
optional apachedsDependencies
runtime "org.springframework:spring-context:$springVersion"
provided "commons-pool:commons-pool:$commonsPoolVersion",
@@ -24,5 +22,6 @@ dependencies {
testCompile project(":spring-ldap-test"),
"junit:junit:$junitVersion",
"jdepend:jdepend:2.9.1",
"commons-io:commons-io:$commonsIoVersion"
"commons-io:commons-io:$commonsIoVersion",
apachedsDependencies
}

View File

@@ -5,9 +5,8 @@ dependencies {
'javax.servlet:jstl:1.2',
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-webmvc:$springVersion",
"org.springframework.data:spring-data-commons:$springDataVersion"
optional apachedsDependencies
"org.springframework.data:spring-data-commons:$springDataVersion",
"commons-lang:commons-lang:$commonsLangVersion"
provided "javax.servlet:servlet-api:2.5"
@@ -15,5 +14,6 @@ dependencies {
testCompile "org.springframework:spring-test:$springVersion",
"junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
}

View File

@@ -30,34 +30,34 @@ import com.unboundid.ldap.sdk.Entry;
*/
public final class EmbeddedLdapServer {
private InMemoryDirectoryServer directoryServer;
private InMemoryDirectoryServer directoryServer;
private EmbeddedLdapServer(InMemoryDirectoryServer directoryServer) {
this.directoryServer = directoryServer;
}
private EmbeddedLdapServer(InMemoryDirectoryServer directoryServer) {
this.directoryServer = directoryServer;
}
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
String defaultPartitionSuffix, int port) throws Exception {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(
defaultPartitionSuffix);
config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
String defaultPartitionSuffix, int port) throws Exception {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(
defaultPartitionSuffix);
config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port));
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port));
config.setEnforceSingleStructuralObjectClass(false);
config.setEnforceAttributeSyntaxCompliance(true);
config.setEnforceSingleStructuralObjectClass(false);
config.setEnforceAttributeSyntaxCompliance(true);
Entry entry = new Entry(new DN(defaultPartitionSuffix));
entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
entry.addAttribute("dc", defaultPartitionName);
Entry entry = new Entry(new DN(defaultPartitionSuffix));
entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
entry.addAttribute("dc", defaultPartitionName);
InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
directoryServer.add(entry);
directoryServer.startListening();
return new EmbeddedLdapServer(directoryServer);
}
InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
directoryServer.add(entry);
directoryServer.startListening();
return new EmbeddedLdapServer(directoryServer);
}
public void shutdown() throws Exception {
this.directoryServer.shutDown(true);
}
public void shutdown() throws Exception {
this.directoryServer.shutDown(true);
}
}

View File

@@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import javax.naming.Binding;
import javax.naming.ContextNotEmptyException;
@@ -42,7 +41,6 @@ import org.springframework.ldap.core.LdapAttributes;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
import org.springframework.ldap.ldif.parser.LdifParser;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.DummyDirContext;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.sdk.LDAPException;
@@ -64,31 +62,6 @@ public final class LdapTestUtils {
private LdapTestUtils() {
}
/**
* Start an in-process Apache Directory Server.
*
* @param port the port on which the server will be listening.
* @param defaultPartitionSuffix The default base suffix that will be used
* for the LDAP server.
* @param defaultPartitionName The name to use in the directory server
* configuration for the default base suffix.
* @param principal The principal to use when starting the directory server.
* @param credentials The credentials to use when starting the directory
* server.
* @param extraSchemas Set of extra schemas to add to the bootstrap schemas
* of ApacheDS. May be <code>null</code>.
* @return An unusable DirContext instance.
* @throws NamingException If anything goes wrong when starting the server.
* @deprecated use {@link #startEmbeddedServer(int, String, String)} instead.
*/
public static DirContext startApacheDirectoryServer(int port, String defaultPartitionSuffix,
String defaultPartitionName, String principal, String credentials, Set extraSchemas) throws NamingException {
startEmbeddedServer(port, defaultPartitionSuffix, defaultPartitionName);
return new DummyDirContext();
}
/**
* Start an embedded Apache Directory Server. Only one embedded server will be permitted in the same JVM.
*
@@ -99,7 +72,6 @@ public final class LdapTestUtils {
* configuration for the default base suffix.
*
* @throws IllegalStateException if an embedded server is already started.
* @since 1.3.2
*/
public static void startEmbeddedServer(int port, String defaultPartitionSuffix, String defaultPartitionName) {
if(embeddedServer != null) {
@@ -118,7 +90,6 @@ public final class LdapTestUtils {
* this is silently ignored.
*
* @throws Exception
* @since 1.3.2
*/
public static void shutdownEmbeddedServer() throws Exception {
if(embeddedServer != null) {
@@ -127,18 +98,6 @@ public final class LdapTestUtils {
}
}
/**
* Shut down the in-process Apache Directory Server.
*
* @param principal the principal to be used for authentication.
* @param credentials the credentials to be used for authentication.
* @throws Exception If anything goes wrong when shutting down the server.
* @deprecated use {@link #shutdownEmbeddedServer()} instead.
*/
public static void destroyApacheDirectoryServer(String principal, String credentials) throws Exception {
shutdownEmbeddedServer();
}
/**
* Clear the directory sub-tree starting with the node represented by the
* supplied distinguished name.
@@ -171,7 +130,7 @@ public final class LdapTestUtils {
*/
public static void clearSubContexts(DirContext ctx, Name name) throws NamingException {
NamingEnumeration enumeration = null;
NamingEnumeration<?> enumeration = null;
try {
enumeration = ctx.listBindings(name);
while (enumeration.hasMore()) {
@@ -229,7 +188,8 @@ public final class LdapTestUtils {
loadLdif(context, LdapUtils.emptyLdapName(), ldifFile);
}
private static void loadLdif(DirContext context, Name rootNode, Resource ldifFile) {
@SuppressWarnings("deprecation")
private static void loadLdif(DirContext context, Name rootNode, Resource ldifFile) {
try {
LdapName baseDn = (LdapName)
context.getEnvironment().get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY);

View File

@@ -16,6 +16,8 @@
package org.springframework.ldap.test.unboundid;
import javax.naming.spi.DirObjectFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.core.io.Resource;
import org.springframework.ldap.core.AuthenticationSource;
@@ -27,79 +29,79 @@ import org.springframework.ldap.support.LdapUtils;
/**
* @author Mattias Hellborg Arthursson
*/
public class TestContextSourceFactoryBean extends AbstractFactoryBean {
public class TestContextSourceFactoryBean extends AbstractFactoryBean<ContextSource> {
private int port;
private String defaultPartitionSuffix;
private String defaultPartitionSuffix;
private String defaultPartitionName;
private String defaultPartitionName;
private String principal;
private String principal;
private String password;
private String password;
private boolean baseOnTarget = true;
private boolean baseOnTarget = true;
private Resource ldifFile;
private Resource ldifFile;
private Class dirObjectFactory = DefaultDirObjectFactory.class;
private Class<? extends DirObjectFactory> dirObjectFactory = DefaultDirObjectFactory.class;
private boolean pooled = true;
private boolean pooled = true;
private AuthenticationSource authenticationSource;
private AuthenticationSource authenticationSource;
private ContextSource contextSource;
public void setAuthenticationSource(AuthenticationSource authenticationSource) {
this.authenticationSource = authenticationSource;
}
this.authenticationSource = authenticationSource;
}
public void setPooled(boolean pooled) {
this.pooled = pooled;
}
public void setPooled(boolean pooled) {
this.pooled = pooled;
}
public void setDirObjectFactory(Class dirObjectFactory) {
this.dirObjectFactory = dirObjectFactory;
}
public void setDirObjectFactory(Class<? extends DirObjectFactory> dirObjectFactory) {
this.dirObjectFactory = dirObjectFactory;
}
public void setLdifFile(Resource ldifFile) {
this.ldifFile = ldifFile;
}
public void setLdifFile(Resource ldifFile) {
this.ldifFile = ldifFile;
}
public void setBaseOnTarget(boolean baseOnTarget) {
this.baseOnTarget = baseOnTarget;
}
public void setBaseOnTarget(boolean baseOnTarget) {
this.baseOnTarget = baseOnTarget;
}
public void setDefaultPartitionSuffix(String defaultPartitionSuffix) {
this.defaultPartitionSuffix = defaultPartitionSuffix;
}
public void setDefaultPartitionSuffix(String defaultPartitionSuffix) {
this.defaultPartitionSuffix = defaultPartitionSuffix;
}
public void setPrincipal(String principal) {
this.principal = principal;
}
public void setPrincipal(String principal) {
this.principal = principal;
}
public void setPassword(String password) {
this.password = password;
}
public void setPassword(String password) {
this.password = password;
}
public void setDefaultPartitionName(String defaultPartitionName) {
this.defaultPartitionName = defaultPartitionName;
}
public void setDefaultPartitionName(String defaultPartitionName) {
this.defaultPartitionName = defaultPartitionName;
}
public void setPort(int port) {
this.port = port;
}
public void setPort(int port) {
this.port = port;
}
public void setContextSource(ContextSource contextSource) {
this.contextSource = contextSource;
}
protected Object createInstance() throws Exception {
LdapTestUtils.startEmbeddedServer(port,
defaultPartitionSuffix, defaultPartitionName);
protected ContextSource createInstance() throws Exception {
LdapTestUtils.startEmbeddedServer(port,
defaultPartitionSuffix, defaultPartitionName);
if (contextSource == null) {
if (contextSource == null) {
// If not explicitly configured, create a new instance.
LdapContextSource targetContextSource = new LdapContextSource();
if (baseOnTarget) {
@@ -123,25 +125,25 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean {
Thread.sleep(1000);
if (baseOnTarget) {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
}
else {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
}
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
}
else {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
}
if (ldifFile != null) {
if (ldifFile != null) {
LdapTestUtils.loadLdif(contextSource, ldifFile);
}
}
return contextSource;
}
return contextSource;
}
public Class getObjectType() {
return ContextSource.class;
}
public Class<ContextSource> getObjectType() {
return ContextSource.class;
}
protected void destroyInstance(Object instance) throws Exception {
super.destroyInstance(instance);
protected void destroyInstance(ContextSource instance) throws Exception {
super.destroyInstance(instance);
LdapTestUtils.shutdownEmbeddedServer();
}
}
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -31,10 +32,18 @@ import org.springframework.ldap.query.LdapQueryBuilder;
import static org.assertj.core.api.Assertions.assertThat;
public class EmbeddedLdapServerFactoryBeanTest {
ClassPathXmlApplicationContext ctx;
@After
public void setup() {
if(ctx != null) {
ctx.close();
}
}
@Test
public void testServerStartup() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext-ldifPopulator.xml");
ctx = new ClassPathXmlApplicationContext("/applicationContext-ldifPopulator.xml");
LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
assertThat(ldapTemplate).isNotNull();

View File

@@ -21,6 +21,7 @@ import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -31,10 +32,18 @@ import org.springframework.ldap.query.LdapQueryBuilder;
import static org.assertj.core.api.Assertions.assertThat;
public class TestContextSourceFactoryBeanTest {
ClassPathXmlApplicationContext ctx;
@After
public void setup() {
if(ctx != null) {
ctx.close();
}
}
@Test
public void testServerStartup() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext-testContextSource.xml");
ctx = new ClassPathXmlApplicationContext("/applicationContext-testContextSource.xml");
LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
assertThat(ldapTemplate).isNotNull();

View File

@@ -7,8 +7,6 @@ apply from: JAVA_SCRIPT
ext.spring20Version = '2.0.8'
dependencies {
optional apachedsDependencies
testCompile (project(":spring-ldap-test")) {
exclude group: "org.springframework", module:"spring-core"
exclude group: "org.springframework", module:"spring-beans"
@@ -23,6 +21,7 @@ dependencies {
"org.springframework:spring-dao:$spring20Version",
"org.springframework:spring-beans:$spring20Version",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
}

View File

@@ -7,8 +7,6 @@ apply from: JAVA_SCRIPT
ext.spring25Version = '2.5.6.SEC03'
dependencies {
optional apachedsDependencies
testCompile (project(":spring-ldap-test")) {
exclude group: "org.springframework", module:"spring-core"
exclude group: "org.springframework", module:"spring-beans"
@@ -33,6 +31,7 @@ dependencies {
"org.springframework:spring-beans:$spring25Version",
"junit:junit:$junitVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
}

View File

@@ -7,8 +7,6 @@ apply from: JAVA_SCRIPT
ext.spring30Version = '3.0.7.RELEASE'
dependencies {
optional apachedsDependencies
testCompile (project(":spring-ldap-test")) {
exclude group: "org.springframework", module:"spring-core"
exclude group: "org.springframework", module:"spring-beans"
@@ -28,7 +26,8 @@ dependencies {
"org.springframework:spring-beans:$spring30Version",
"junit:junit:$junitVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
testCompile("org.springframework.data:spring-data-commons:$springDataVersion") {
exclude group: "org.springframework"

View File

@@ -7,8 +7,6 @@ dependencies {
project(":spring-ldap-core-tiger"),
"commons-pool:commons-pool:1.4"
optional apachedsDependencies
provided "org.springframework:spring-jdbc:$springVersion",
"com.sun:ldapbp:1.0"
@@ -17,7 +15,8 @@ dependencies {
"org.springframework:spring-aop:$springVersion",
"gsbase:gsbase:$gsbaseVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
}

View File

@@ -27,6 +27,7 @@ dependencies {
project(":spring-ldap-core-tiger")
compile "com.querydsl:querydsl-apt:$queryDslVersion",
"commons-lang:commons-lang:$commonsLangVersion"
compile("org.springframework.data:spring-data-commons:$springDataVersion") {
exclude group: "org.springframework", module: "spring-beans"
@@ -41,8 +42,6 @@ dependencies {
exclude group: "org.springframework", module: "spring-aop"
}
optional apachedsDependencies
provided "commons-pool:commons-pool:$commonsPoolVersion",
"org.springframework:spring-jdbc:$springVersion",
"org.springframework:spring-orm:$springVersion"
@@ -57,7 +56,8 @@ dependencies {
"junit:junit:$junitVersion",
"org.springframework.security:spring-security-config:$springSecurityVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
"org.assertj:assertj-core:$assertjVersion",
apachedsDependencies
testCompile("org.springframework.security:spring-security-ldap:$springSecurityVersion") {