Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [ 8, 11 ]
java-version: [ 11, 17 ]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -46,11 +46,11 @@ jobs:
needs: build
steps:
- uses: actions/checkout@v2
- name: Set up Java 8
- name: Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 8
java-version: 11
server-id: sonatype-nexus-snapshots
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
33 changes: 33 additions & 0 deletions embedded-ldap-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-junit-parent</artifactId>
<version>0.9.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>embedded-ldap-core</artifactId>

<dependencies>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
91 changes: 36 additions & 55 deletions ...t/junit/ldap/EmbeddedLdapRuleBuilder.java → ...p/AbstractEmbeddedLdapSupportBuilder.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.unboundid.ldap.sdk.schema.Schema;
import com.unboundid.ldif.LDIFException;
import org.zapodot.junit.ldap.internal.AuthenticationConfiguration;
import org.zapodot.junit.ldap.internal.EmbeddedLdapRuleImpl;

import javax.net.ssl.SSLSocketFactory;
import java.io.File;
Expand All @@ -22,61 +21,46 @@
import java.util.List;
import java.util.Objects;

/**
* A builder providing a fluent way of defining EmbeddedLdapRule instances
*/
public class EmbeddedLdapRuleBuilder {

public abstract class AbstractEmbeddedLdapSupportBuilder<T> {
public static final String DEFAULT_DOMAIN = "dc=example,dc=com";
public static final String DEFAULT_BIND_DSN = "cn=Directory manager";
public static final String DEFAULT_BIND_CREDENTIALS = "password";
public static final String LDAP_SERVER_LISTENER_NAME = "test-listener";
public static final int MIN_PORT_EXCLUSIVE = 0;
public static final int MAX_PORT_EXCLUSIVE = 65535;
private List<String> domainDsn = new LinkedList<>();

private String bindDSN = DEFAULT_BIND_DSN;
protected List<String> domainDsn = new LinkedList<>();

private String bindCredentials = DEFAULT_BIND_CREDENTIALS;
protected String bindDSN = DEFAULT_BIND_DSN;

private List<String> ldifsToImport = new LinkedList<>();
protected String bindCredentials = DEFAULT_BIND_CREDENTIALS;

private List<String> schemaLdifs = new LinkedList<>();
protected List<String> ldifsToImport = new LinkedList<>();

private boolean addDefaultSchema = true;
protected List<String> schemaLdifs = new LinkedList<>();

private Integer bindPort = 0;
protected boolean addDefaultSchema = true;

private InetAddress bindAddress = InetAddress.getLoopbackAddress();
protected Integer bindPort = 0;

private AuthenticationConfiguration authenticationConfiguration;
protected InetAddress bindAddress = InetAddress.getLoopbackAddress();

private InMemoryListenerConfig listenerConfig = null;
protected AuthenticationConfiguration authenticationConfiguration;

private boolean useTls = false;
private SSLSocketFactory socketFactory = null;
protected InMemoryListenerConfig listenerConfig = null;

private Integer maxSizeLimit = null;
protected boolean useTls = false;
protected SSLSocketFactory socketFactory = null;

public EmbeddedLdapRuleBuilder() {
}
protected Integer maxSizeLimit = null;

/**
* Creates a new builder
*
* @return a new EmbeddedLdapRuleBuilder instance
*/
public static EmbeddedLdapRuleBuilder newInstance() {
return new EmbeddedLdapRuleBuilder();
}

/**
* Sets a domainDsn to be used. May be multiple values. If not set, it will default to the value of the {@link #DEFAULT_DOMAIN DEFAULT_DOMAIN} field
*
* @param domainDsn a valid DSN string
* @return same EmbeddedLdapRuleBuilder instance with the domainDsn field set
*/
public EmbeddedLdapRuleBuilder usingDomainDsn(final String domainDsn) {
public AbstractEmbeddedLdapSupportBuilder<T> usingDomainDsn(final String domainDsn) {
this.domainDsn.add(domainDsn);
return this;
}
Expand All @@ -87,7 +71,7 @@ public EmbeddedLdapRuleBuilder usingDomainDsn(final String domainDsn) {
* @param bindDSN a valid DSN string
* @return same EmbeddedLdapRuleBuilder instance with the bindDSN field set
*/
public EmbeddedLdapRuleBuilder usingBindDSN(final String bindDSN) {
public AbstractEmbeddedLdapSupportBuilder<T> usingBindDSN(final String bindDSN) {
this.bindDSN = bindDSN;
return this;
}
Expand All @@ -98,7 +82,7 @@ public EmbeddedLdapRuleBuilder usingBindDSN(final String bindDSN) {
* @param bindCredentials a password string
* @return same EmbeddedLdapRuleBuilder instance with the bindCredentials field set
*/
public EmbeddedLdapRuleBuilder usingBindCredentials(final String bindCredentials) {
public AbstractEmbeddedLdapSupportBuilder<T> usingBindCredentials(final String bindCredentials) {
this.bindCredentials = bindCredentials;
return this;
}
Expand All @@ -111,7 +95,7 @@ public EmbeddedLdapRuleBuilder usingBindCredentials(final String bindCredentials
* @throws IllegalArgumentException if the provided value for port is not between @{link MIN_PORT_EXCLUSIVE}
* and @{MAX_PORT_EXCLUSIVE} (exclusive)
*/
public EmbeddedLdapRuleBuilder bindingToPort(final int port) {
public AbstractEmbeddedLdapSupportBuilder<T> bindingToPort(final int port) {
if ((port < MIN_PORT_EXCLUSIVE) || (port > MAX_PORT_EXCLUSIVE)) {
throw new IllegalArgumentException(String.format("Value \"%s\" is not a valid port number", port));
}
Expand All @@ -126,7 +110,7 @@ public EmbeddedLdapRuleBuilder bindingToPort(final int port) {
* @return same EmbeddedLdapRuleBuilder instance with the bindAddress field set
* @throws IllegalArgumentException if the value provided for \"address\" is invalid
*/
public EmbeddedLdapRuleBuilder bindingToAddress(final String address) {
public AbstractEmbeddedLdapSupportBuilder<T> bindingToAddress(final String address) {
Objects.requireNonNull(address);
try {
final InetAddress addressByName = InetAddress.getByName(address);
Expand All @@ -137,7 +121,7 @@ public EmbeddedLdapRuleBuilder bindingToAddress(final String address) {
return this;
}

public EmbeddedLdapRuleBuilder withMaxSizeLimit(final int maxSizeLimit) {
public AbstractEmbeddedLdapSupportBuilder<T> withMaxSizeLimit(final int maxSizeLimit) {
this.maxSizeLimit = Integer.valueOf(maxSizeLimit);
return this;
}
Expand All @@ -147,7 +131,7 @@ public EmbeddedLdapRuleBuilder withMaxSizeLimit(final int maxSizeLimit) {
*
* @return same EmbeddedLdapRuleBuilder instance with the withoutDefaultSchema field set to FALSE
*/
public EmbeddedLdapRuleBuilder withoutDefaultSchema() {
public AbstractEmbeddedLdapSupportBuilder<T> withoutDefaultSchema() {
this.addDefaultSchema = false;
return this;
}
Expand All @@ -158,7 +142,7 @@ public EmbeddedLdapRuleBuilder withoutDefaultSchema() {
* @param ldifSchemaFiles LDIF-files containing schema element definitions
* @return same EmbeddedLdapRuleBuilder with the given LDIF-files added to the internal schema file collection.
*/
public EmbeddedLdapRuleBuilder withSchema(final String... ldifSchemaFiles) {
public AbstractEmbeddedLdapSupportBuilder<T> withSchema(final String... ldifSchemaFiles) {
this.schemaLdifs.addAll(Arrays.asList(ldifSchemaFiles));
return this;
}
Expand All @@ -169,19 +153,19 @@ public EmbeddedLdapRuleBuilder withSchema(final String... ldifSchemaFiles) {
* @param ldifFiles LDIF-files to import
* @return same EmbeddedLdapRuleBuilder instance with the provided ldifFiles added to the list of LDIF files to import
*/
public EmbeddedLdapRuleBuilder importingLdifs(final String... ldifFiles) {
public AbstractEmbeddedLdapSupportBuilder<T> importingLdifs(final String... ldifFiles) {
if (ldifFiles != null) {
ldifsToImport.addAll(Arrays.asList(ldifFiles));
}
return this;
}

public EmbeddedLdapRuleBuilder withListener(InMemoryListenerConfig listenerConfig) {
public AbstractEmbeddedLdapSupportBuilder<T> withListener(InMemoryListenerConfig listenerConfig) {
this.listenerConfig = listenerConfig;
return this;
}

public EmbeddedLdapRuleBuilder useTls(boolean useTls) {
public AbstractEmbeddedLdapSupportBuilder<T> useTls(boolean useTls) {
this.useTls = useTls;
return this;
}
Expand All @@ -191,14 +175,10 @@ public EmbeddedLdapRuleBuilder useTls(boolean useTls) {
*
* @return a new EmbeddedLdapRule instance
*/
public EmbeddedLdapRule build() {
Objects.requireNonNull(bindDSN, "\"bindDSN\" can not be null");
return EmbeddedLdapRuleImpl.createForConfiguration(createInMemoryServerConfiguration(),
authenticationConfiguration,
ldifsToImport, useTls, socketFactory);
}
abstract public T build();

private InMemoryDirectoryServerConfig createInMemoryServerConfiguration() {

protected InMemoryDirectoryServerConfig createInMemoryServerConfiguration() {
try {
final InMemoryDirectoryServerConfig inMemoryDirectoryServerConfig =
new InMemoryDirectoryServerConfig(domainDsnArray());
Expand All @@ -210,10 +190,10 @@ private InMemoryDirectoryServerConfig createInMemoryServerConfiguration() {

if (listenerConfig == null) {
listenerConfig = InMemoryListenerConfig.createLDAPConfig(
LDAP_SERVER_LISTENER_NAME,
bindAddress,
bindPort,
null);
LDAP_SERVER_LISTENER_NAME,
bindAddress,
bindPort,
null);
}
inMemoryDirectoryServerConfig.setListenerConfigs(listenerConfig);
inMemoryDirectoryServerConfig.setSchema(customSchema());
Expand Down Expand Up @@ -243,8 +223,8 @@ private Schema customSchema() {
final Schema initialSchema = (addDefaultSchema ? Schema.getDefaultStandardSchema() : null);
if (!schemaFiles.isEmpty()) {
final Schema customSchema = initialSchema == null
? Schema.getSchema(schemaFiles)
: Schema.mergeSchemas(initialSchema, Schema.getSchema(schemaFiles));
? Schema.getSchema(schemaFiles)
: Schema.mergeSchemas(initialSchema, Schema.getSchema(schemaFiles));
return customSchema;
} else {
return null;
Expand Down Expand Up @@ -278,8 +258,9 @@ public File apply(final String input) {
}));
}

public EmbeddedLdapRuleBuilder withSocketFactory(SSLSocketFactory socketFactory) {
public AbstractEmbeddedLdapSupportBuilder<T> withSocketFactory(SSLSocketFactory socketFactory) {
this.socketFactory = socketFactory;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ private static Constructor<? extends Context> getDeclaredConstructor() {

public static DirContext asDelegatingDirContext(final InitialDirContext initialDirContext) {
try {
final DirContext dirContext = DIR_CONTEXT_PROXY_TYPE.newInstance();
final DirContext dirContext = DIR_CONTEXT_PROXY_TYPE.getDeclaredConstructor().newInstance();
((DirContextProxy) dirContext).setDelegatedDirContext(initialDirContext);
return dirContext;
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new IllegalStateException("Could not wrap DirContext", e);
}
}
Expand Down
42 changes: 42 additions & 0 deletions embedded-ldap-junit-jupiter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>embedded-ldap-junit-parent</artifactId>
<groupId>org.zapodot</groupId>
<version>0.9.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>embedded-ldap-junit-jupiter</artifactId>

<dependencies>
<dependency>
<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>

</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit-jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.zapodot.ldap.jupiter;

import org.junit.jupiter.api.extension.*;

/**
* Extension for JUnit 5 Jupiter
*/
public interface EmbeddedLdapExtension extends Extension, BeforeEachCallback, AfterEachCallback, BeforeAllCallback, AfterAllCallback {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.zapodot.ldap.jupiter;

import org.zapodot.junit.ldap.AbstractEmbeddedLdapSupportBuilder;

public class EmbeddedLdapExtensionBuilder extends AbstractEmbeddedLdapSupportBuilder<EmbeddedLdapExtension> {

public static EmbeddedLdapExtensionBuilder newInstance() {
return new EmbeddedLdapExtensionBuilder();
}

@Override
public EmbeddedLdapExtension build() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.zapodot.ldap.jupiter.internal;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.zapodot.ldap.jupiter.EmbeddedLdapExtension;

public class EmbeddedLdapExtensionImpl implements EmbeddedLdapExtension {
@Override
public void afterAll(final ExtensionContext extensionContext) throws Exception {

}

@Override
public void afterEach(final ExtensionContext extensionContext) throws Exception {

}

@Override
public void beforeAll(final ExtensionContext extensionContext) throws Exception {

}

@Override
public void beforeEach(final ExtensionContext extensionContext) throws Exception {

}
}
Loading