You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2020/11/12 10:29:01 UTC
svn commit: r1883345 - in /jackrabbit/oak/branches/1.22: oak-auth-ldap/
oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/
oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/
oak-it-...
Author: angela
Date: Thu Nov 12 10:29:00 2020
New Revision: 1883345
URL: http://svn.apache.org/viewvc?rev=1883345&view=rev
Log:
OAK-8769 : oak-auth-ldap pom needs maintenance (merged r1876763, r1876776 into 1.22 branch):
Added:
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java (with props)
Modified:
jackrabbit/oak/branches/1.22/oak-auth-ldap/pom.xml
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/PoolableUnboundConnectionFactory.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/UnboundLdapConnectionPool.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java
jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java
jackrabbit/oak/branches/1.22/oak-it-osgi/pom.xml
jackrabbit/oak/branches/1.22/oak-it-osgi/test-bundles.xml
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/pom.xml?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/pom.xml (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/pom.xml Thu Nov 12 10:29:00 2020
@@ -35,8 +35,8 @@
<apacheds.test.version>2.0.0-M24</apacheds.test.version>
<!-- enable execution of jacoco and set minimal line coverage -->
<skip.coverage>false</skip.coverage>
- <minimum.line.coverage>0.85</minimum.line.coverage>
- <minimum.branch.coverage>0.72</minimum.branch.coverage>
+ <minimum.line.coverage>0.81</minimum.line.coverage>
+ <minimum.branch.coverage>0.67</minimum.branch.coverage>
</properties>
<build>
@@ -44,18 +44,22 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
!org.dom4j.*,
!org.xmlpull.v1,
!sun.net.util,
+ !net.sf.cglib.proxy,
+ !antlr,
+ !antlr.collections.impl,
+ !org.apache.mina.*,
*
</Import-Package>
<Embed-Dependency>
- api-all,commons-pool,commons-lang,mina-core,antlr
+ api-all,commons-pool2,mina-core,org.apache.servicemix.bundles.antlr
</Embed-Dependency>
- <Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
@@ -71,67 +75,37 @@
</plugins>
</build>
- <profiles>
- <profile>
- <!-- Disable LDAP Server Integrations Tests for jdk 1.6 -->
- <id>disable-ldap-integration</id>
- <activation>
- <!-- for JDK 1.6 (OAK-2903) -->
- <jdk>1.6</jdk>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>**/LdapProviderTest.class</exclude>
- <exclude>**/DefaultLdapLoginModuleTest.class</exclude>
- <exclude>**/GuestTokenDefaultLdapLoginModuleTest.class</exclude>
- <exclude>**/LdapDefaultLoginModuleTest.class</exclude>
- <exclude>**/LdapLoginStandaloneTest.class</exclude>
- <exclude>**/TokenDefaultLdapLoginModuleTest.class</exclude>
- <exclude>**/LargeLdapProviderTest.class</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
-
<dependencies>
<!-- embedded apache directory client and dependencies-->
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
- <version>1.0.0</version>
- <scope>provided</scope>
+ <version>2.0.1</version>
</dependency>
<dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.6</version>
- <scope>provided</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-pool2</artifactId>
+ <version>2.8.0</version>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- <scope>provided</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.4</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
- <version>2.0.16</version>
- <scope>provided</scope>
+ <version>2.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.antlr</artifactId>
+ <version>2.7.7_5</version>
</dependency>
<dependency>
- <groupId>antlr</groupId>
- <artifactId>antlr</artifactId>
- <version>2.7.7</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.9</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -241,179 +215,23 @@
<scope>test</scope>
</dependency>
- <!-- test dependencies for apache DS server. -->
- <!-- note: we don't include apacheds-all since we then have a duplicate schema ldiff in the classpath -->
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core-annotations</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core-api</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core-avl</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core-constants</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-core-jndi</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-interceptor-kerberos</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-kerberos-codec</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-ldif-partition</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-dhcp</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-dns</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-kerberos</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-ldap</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-ntp</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-protocol-shared</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-server-annotations</artifactId>
- <version>${apacheds.test.version}</version>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-server-config</artifactId>
- <version>${apacheds.test.version}</version>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-server-jndi</artifactId>
- <version>${apacheds.test.version}</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
</dependency>
+
+ <!-- test dependencies for apache DS server. -->
<dependency>
<groupId>org.apache.directory.server</groupId>
- <artifactId>apacheds-xdbm-partition</artifactId>
+ <artifactId>apacheds-all</artifactId>
<version>${apacheds.test.version}</version>
<scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.apache.directory.api</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
</project>
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProvider.java Thu Nov 12 10:29:00 2020
@@ -32,8 +32,7 @@ import javax.jcr.SimpleCredentials;
import javax.net.ssl.SSLContext;
import javax.security.auth.login.LoginException;
-import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsDecorator;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.directory.api.ldap.model.constants.SchemaConstants;
import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.cursor.SearchCursor;
@@ -51,6 +50,7 @@ import org.apache.directory.api.ldap.mod
import org.apache.directory.api.ldap.model.message.SearchResultEntry;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.message.controls.PagedResults;
+import org.apache.directory.api.ldap.model.message.controls.PagedResultsImpl;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.ldap.client.api.AbstractPoolableLdapConnectionFactory;
@@ -366,7 +366,7 @@ public class LdapIdentityProvider implem
try {
DebugTimer timer = new DebugTimer();
if (userPool == null) {
- connection = userConnectionFactory.makeObject();
+ connection = userConnectionFactory.create();
} else {
connection = userPool.getConnection();
}
@@ -538,8 +538,8 @@ public class LdapIdentityProvider implem
if (config.getAdminPoolConfig().getMaxActive() != 0) {
adminPool = new LdapConnectionPool(adminConnectionFactory);
adminPool.setTestOnBorrow(true);
- adminPool.setMaxActive(config.getAdminPoolConfig().getMaxActive());
- adminPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
+ adminPool.setMaxTotal(config.getAdminPoolConfig().getMaxActive());
+ adminPool.setBlockWhenExhausted(true);
}
// setup unbound connection pool. let's create a new version of the config
@@ -554,8 +554,8 @@ public class LdapIdentityProvider implem
if (config.getUserPoolConfig().getMaxActive() != 0) {
userPool = new UnboundLdapConnectionPool(userConnectionFactory);
userPool.setTestOnBorrow(true);
- userPool.setMaxActive(config.getUserPoolConfig().getMaxActive());
- userPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
+ userPool.setMaxTotal(config.getUserPoolConfig().getMaxActive());
+ userPool.setBlockWhenExhausted(true);
}
log.info("LdapIdentityProvider initialized: {}", config);
@@ -722,11 +722,11 @@ public class LdapIdentityProvider implem
req.setBase(new Dn(idConfig.getBaseDN()));
req.setFilter(searchFilter);
- PagedResults pagedSearchControl = new PagedResultsDecorator(connection.getCodecService());
// do paged searches (OAK-2874)
- pagedSearchControl.setSize(1000);
- pagedSearchControl.setCookie(cookie);
- req.addControl(pagedSearchControl);
+ PagedResultsImpl pagedResults = new PagedResultsImpl();
+ pagedResults.setSize(1000);
+ pagedResults.setCookie(cookie);
+ req.addControl(pagedResults);
return req;
}
@@ -758,16 +758,18 @@ public class LdapIdentityProvider implem
}
}
- SearchResultDone done = searchCursor.getSearchResultDone();
+ boolean done = searchCursor.isDone();
cookie = null;
- if (done.getLdapResult().getResultCode() != ResultCodeEnum.UNWILLING_TO_PERFORM) {
-
- PagedResults ctrl = (PagedResults) done.getControl(PagedResults.OID);
- if (ctrl != null) {
- cookie = ctrl.getCookie();
+ if (done) {
+ SearchResultDone searchResultDone = searchCursor.getSearchResultDone();
+ if (searchResultDone != null && searchResultDone.getLdapResult().getResultCode() != ResultCodeEnum.UNWILLING_TO_PERFORM) {
+ PagedResults ctrl = (PagedResults) searchResultDone.getControl(PagedResults.OID);
+ if (ctrl != null) {
+ cookie = ctrl.getCookie();
+ }
}
}
- searchComplete = cookie == null;
+ searchComplete = cookie == null || cookie.length == 0;
timer.mark("lookup");
return !page.isEmpty();
@@ -843,7 +845,7 @@ public class LdapIdentityProvider implem
// for multivalue properties, store as collection
if (attr.size() > 1) {
List<String> values = new ArrayList();
- for (Value<?> value : attr) {
+ for (Value value : attr) {
values.add(value.getString());
}
propValue = values;
@@ -859,7 +861,7 @@ public class LdapIdentityProvider implem
private LdapConnection connect() throws ExternalIdentityException {
try {
if (adminPool == null) {
- return adminConnectionFactory.makeObject();
+ return adminConnectionFactory.makeObject().getObject();
} else {
return adminPool.getConnection();
}
@@ -874,7 +876,7 @@ public class LdapIdentityProvider implem
try {
if (connection != null) {
if (adminPool == null) {
- adminConnectionFactory.destroyObject(connection);
+ adminConnectionFactory.destroyObject(new DefaultPooledObject<>(connection));
} else {
adminPool.releaseConnection(connection);
}
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapProviderConfig.java Thu Nov 12 10:29:00 2020
@@ -620,7 +620,7 @@ public class LdapProviderConfig {
/**
* Defines the configuration of a connection pool. Currently we only define the max size.
- * (documentation copied from {@link org.apache.commons.pool.impl.GenericObjectPool})
+ * (documentation copied from {@link org.apache.commons.pool2.impl.GenericObjectPool})
*/
public static class PoolConfig {
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/PoolableUnboundConnectionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/PoolableUnboundConnectionFactory.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/PoolableUnboundConnectionFactory.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/PoolableUnboundConnectionFactory.java Thu Nov 12 10:29:00 2020
@@ -18,7 +18,9 @@ package org.apache.jackrabbit.oak.securi
import java.io.IOException;
-import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool2.BasePooledObjectFactory;
+import org.apache.commons.pool2.PooledObject;
+import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
@@ -32,7 +34,7 @@ import org.slf4j.LoggerFactory;
/**
* A factory for creating unbound LdapConnection objects managed by LdapConnectionPool.
*/
-public class PoolableUnboundConnectionFactory implements PoolableObjectFactory<LdapConnection> {
+public class PoolableUnboundConnectionFactory extends BasePooledObjectFactory<LdapConnection> {
/**
* default logger
@@ -90,11 +92,10 @@ public class PoolableUnboundConnectionFa
connection.close();
}
-
/**
* {@inheritDoc}
*/
- public LdapConnection makeObject() throws LdapException {
+ public LdapConnection create() throws LdapException {
LdapNetworkConnection connection = config.isUseTls()
? new TlsGuardingConnection(config)
: new LdapNetworkConnection(config);
@@ -103,6 +104,9 @@ public class PoolableUnboundConnectionFa
return connection;
}
+ public PooledObject<LdapConnection> wrap(LdapConnection foo) {
+ return new DefaultPooledObject<>(foo);
+ }
/**
* {@inheritDoc}
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/UnboundLdapConnectionPool.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/UnboundLdapConnectionPool.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/UnboundLdapConnectionPool.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/main/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/UnboundLdapConnectionPool.java Thu Nov 12 10:29:00 2020
@@ -16,7 +16,7 @@
*/
package org.apache.jackrabbit.oak.security.authentication.ldap.impl;
-import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.directory.ldap.client.api.LdapConnection;
/**
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java Thu Nov 12 10:29:00 2020
@@ -24,9 +24,11 @@ import static org.junit.Assume.assumeFal
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.BindException;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -39,7 +41,6 @@ import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
-import org.apache.commons.io.FileUtils;
import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
@@ -114,7 +115,7 @@ public abstract class AbstractServer {
* @return a list of entries added to the server in the order they were added
* @throws NamingException of the load fails
*/
- protected List<LdifEntry> loadLdif(InputStream in) throws Exception {
+ public List<LdifEntry> loadLdif(InputStream in) throws Exception {
if (in == null) {
return EMPTY_LIST;
}
@@ -122,7 +123,7 @@ public abstract class AbstractServer {
return loadLdif(ldifReader);
}
- protected List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception {
+ public List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception {
List<LdifEntry> entries = new ArrayList<LdifEntry>();
for (LdifEntry ldifEntry : ldifReader) {
Dn dn = ldifEntry.getDn();
@@ -339,7 +340,7 @@ public abstract class AbstractServer {
protected void doDelete(File wkdir) throws IOException {
if (doDelete) {
if (wkdir.exists()) {
- FileUtils.deleteDirectory(wkdir);
+ deleteDirectory(wkdir);
}
if (wkdir.exists()) {
@@ -348,7 +349,85 @@ public abstract class AbstractServer {
}
}
+//-----------------------------------------------------------------------------
+ public static void deleteDirectory(File directory) throws IOException {
+ if (directory.exists()) {
+ if (!isSymlink(directory)) {
+ cleanDirectory(directory);
+ }
+
+ if (!directory.delete()) {
+ String message = "Unable to delete directory " + directory + ".";
+ throw new IOException(message);
+ }
+ }
+ }
+
+ public static boolean isSymlink(File file) throws IOException {
+ if (file == null) {
+ throw new NullPointerException("File must not be null");
+ } else {
+ return Files.isSymbolicLink(file.toPath());
+ }
+ }
+
+ public static void cleanDirectory(File directory) throws IOException {
+ File[] files = verifiedListFiles(directory);
+ IOException exception = null;
+ File[] var3 = files;
+ int var4 = files.length;
+
+ for(int var5 = 0; var5 < var4; ++var5) {
+ File file = var3[var5];
+
+ try {
+ forceDelete(file);
+ } catch (IOException var8) {
+ exception = var8;
+ }
+ }
+
+ if (null != exception) {
+ throw exception;
+ }
+ }
+
+ private static File[] verifiedListFiles(File directory) throws IOException {
+ String message;
+ if (!directory.exists()) {
+ message = directory + " does not exist";
+ throw new IllegalArgumentException(message);
+ } else if (!directory.isDirectory()) {
+ message = directory + " is not a directory";
+ throw new IllegalArgumentException(message);
+ } else {
+ File[] files = directory.listFiles();
+ if (files == null) {
+ throw new IOException("Failed to list contents of " + directory);
+ } else {
+ return files;
+ }
+ }
+ }
+
+ public static void forceDelete(File file) throws IOException {
+ if (file.isDirectory()) {
+ deleteDirectory(file);
+ } else {
+ boolean filePresent = file.exists();
+ if (!file.delete()) {
+ if (!filePresent) {
+ throw new FileNotFoundException("File does not exist: " + file);
+ }
+
+ String message = "Unable to delete file: " + file;
+ throw new IOException(message);
+ }
+ }
+ }
+
+//-----------------------------------------------------------------------------
/**
* Sets the contexts for this base class. Values of user and password used to
* set the respective JNDI properties. These values can be overriden by the
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java Thu Nov 12 10:29:00 2020
@@ -22,13 +22,17 @@ import javax.naming.directory.BasicAttri
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
-class InternalLdapServer extends AbstractServer {
+public class InternalLdapServer extends AbstractServer {
public static final String GROUP_MEMBER_ATTR = "member";
public static final String GROUP_CLASS_ATTR = "groupOfNames";
public static final String ADMIN_PW = "secret";
+ public InternalLdapServer() {
+ super();
+ }
+
public void setUp() throws Exception {
super.setUp();
doDelete = true;
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java Thu Nov 12 10:29:00 2020
@@ -43,69 +43,64 @@ import static org.junit.Assert.assertTru
public class LargeLdapProviderTest {
- protected static final InternalLdapServer LDAP_SERVER = new InternalLdapServer();
-
- //initialize LDAP server only once (fast, but might turn out to be not sufficiently flexible in the future)
- protected static final boolean USE_COMMON_LDAP_FIXTURE = false;
+ //loaded by a separate ClassLoader unavailable to the client (needed because the server is using old libraries)
+ protected static LdapServerClassLoader.Proxy proxy;
public static final String IDP_NAME = "ldap";
-
protected static final String GROUP_NAME = "foobargroup";
protected static String GROUP_DN;
-
protected static String[] TEST_MEMBERS;
-
protected static int NUM_USERS = 2222;
-
protected static int SIZE_LIMIT = 50;
- protected LdapIdentityProvider idp;
-
- protected LdapProviderConfig providerConfig;
+ protected static LdapIdentityProvider idp;
+ protected static LdapProviderConfig providerConfig;
@BeforeClass
public static void beforeClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- LDAP_SERVER.setMaxSizeLimit(SIZE_LIMIT);
- initLdapFixture(LDAP_SERVER);
+ LdapServerClassLoader serverClassLoader = LdapServerClassLoader.createServerClassLoader();
+ proxy = serverClassLoader.createAndSetupServer();
+ idp = createIDP();
+ proxy.setMaxSizeLimit(SIZE_LIMIT);
+ USER_DN = proxy.addUser(USER_FIRSTNAME, USER_LASTNAME, USER_ID, USER_PWD);
+ GROUP_DN = proxy.addGroup(GROUP_NAME, USER_DN);
+ ArrayList<String> members = new ArrayList<>();
+ members.add(USER_DN);
+ List<String> userDNs = new ArrayList<String>();
+ for (int i = 0; i < NUM_USERS; i++) {
+ final String userId = "user-" + i;
+ String userDN = proxy.addUser(userId, "test", userId, "test");
+ userDNs.add(userDN);
+ members.add(userDN);
}
+ proxy.addMembers(GROUP_DN, userDNs);
+ TEST_MEMBERS = members.toArray(new String[members.size()]);
}
@AfterClass
public static void afterClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
+ proxy.tearDown();
}
@Before
public void before() throws Exception {
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- LDAP_SERVER.setMaxSizeLimit(SIZE_LIMIT);
- initLdapFixture(LDAP_SERVER);
- }
idp = createIDP();
}
@After
public void after() throws Exception {
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
if (idp != null) {
idp.close();
idp = null;
}
}
- protected LdapIdentityProvider createIDP() {
+ protected static LdapIdentityProvider createIDP() {
providerConfig = new LdapProviderConfig()
.setName(IDP_NAME)
.setHostname("127.0.0.1")
- .setPort(LDAP_SERVER.getPort())
+ .setPort(proxy.port)
.setBindDN(USER_DN)
.setBindPassword(USER_PWD)
.setGroupMemberAttribute("member");
@@ -130,25 +125,6 @@ public class LargeLdapProviderTest {
protected static String USER_DN;
- protected static void initLdapFixture(InternalLdapServer server) throws Exception {
- ArrayList<String> members = new ArrayList<String>();
-
- USER_DN = LDAP_SERVER.addUser(USER_FIRSTNAME, USER_LASTNAME, USER_ID, USER_PWD);
- GROUP_DN = server.addGroup(GROUP_NAME, USER_DN);
- members.add(USER_DN);
-
- List<String> userDNs = new ArrayList<String>();
- for (int i = 0; i < NUM_USERS; i++) {
- final String userId = "user-" + i;
- String userDN = server.addUser(userId, "test", userId, "test");
- userDNs.add(userDN);
- members.add(userDN);
- }
- LDAP_SERVER.addMembers(GROUP_DN, userDNs);
- TEST_MEMBERS = members.toArray(new String[members.size()]);
- }
-
-
@Test
public void testGetMembers() throws Exception {
ExternalIdentityRef ref = new ExternalIdentityRef(GROUP_DN, IDP_NAME);
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java Thu Nov 12 10:29:00 2020
@@ -58,7 +58,8 @@ import static org.junit.Assert.fail;
public abstract class LdapLoginTestBase extends ExternalLoginTestBase {
- protected static final InternalLdapServer LDAP_SERVER = new InternalLdapServer();
+ //loaded by a separate ClassLoader unavailable to the client (needed because the server is using old libraries)
+ protected static LdapServerClassLoader.Proxy proxy;
protected static final String USER_ID = "foobar";
protected static final String USER_PWD = "foobar";
@@ -74,46 +75,40 @@ public abstract class LdapLoginTestBase
private static String[] CONCURRENT_TEST_USERS = new String[NUM_CONCURRENT_LOGINS];
private static String[] CONCURRENT_GROUP_TEST_USERS = new String[NUM_CONCURRENT_LOGINS];
- //initialize LDAP server only once (fast, but might turn out to be not sufficiently flexible in the future)
- protected static final boolean USE_COMMON_LDAP_FIXTURE = true;
-
protected UserManager userManager;
@BeforeClass
public static void beforeClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- createLdapFixture();
+ LdapServerClassLoader serverClassLoader = LdapServerClassLoader.createServerClassLoader();
+ proxy = serverClassLoader.createAndSetupServer();
+ String userDN = proxy.addUser(USER_FIRSTNAME, USER_LASTNAME, USER_ID, USER_PWD);
+ GROUP_DN = proxy.addGroup(GROUP_NAME, userDN);
+ for (int i = 0; i < NUM_CONCURRENT_LOGINS * 2; i++) {
+ final String userId = "user-" + i;
+ userDN = proxy.addUser(userId, "test", userId, USER_PWD);
+ if (i%2 == 0) {
+ CONCURRENT_GROUP_TEST_USERS[i/2] = userId;
+ proxy.addMember(GROUP_DN, userDN);
+ } else {
+ CONCURRENT_TEST_USERS[i/2] = userId;
+ }
}
- }
+ }
@AfterClass
public static void afterClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
+ proxy.tearDown();
}
@Before
public void before() throws Exception {
super.before();
-
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- createLdapFixture();
- }
-
UserConfiguration uc = securityProvider.getConfiguration(UserConfiguration.class);
userManager = uc.getUserManager(root, NamePathMapper.DEFAULT);
}
@After
public void after() throws Exception {
-
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
-
try {
Authorizable a = userManager.getAuthorizable(USER_ID);
if (a != null) {
@@ -146,7 +141,7 @@ public abstract class LdapLoginTestBase
LdapProviderConfig cfg = new LdapProviderConfig()
.setName("ldap")
.setHostname("127.0.0.1")
- .setPort(LDAP_SERVER.getPort())
+ .setPort(proxy.port)
.setBindDN(ServerDNConstants.ADMIN_SYSTEM_DN)
.setBindPassword(InternalLdapServer.ADMIN_PW)
.setGroupMemberAttribute(InternalLdapServer.GROUP_MEMBER_ATTR);
@@ -392,19 +387,4 @@ public abstract class LdapLoginTestBase
throw exceptions.get(0);
}
}
-
- protected static void createLdapFixture() throws Exception {
- String userDN = LDAP_SERVER.addUser(USER_FIRSTNAME, USER_LASTNAME, USER_ID, USER_PWD);
- GROUP_DN = LDAP_SERVER.addGroup(GROUP_NAME, userDN);
- for (int i = 0; i < NUM_CONCURRENT_LOGINS * 2; i++) {
- final String userId = "user-" + i;
- userDN = LDAP_SERVER.addUser(userId, "test", userId, USER_PWD);
- if (i%2 == 0) {
- CONCURRENT_GROUP_TEST_USERS[i/2] = userId;
- LDAP_SERVER.addMember(GROUP_DN, userDN);
- } else {
- CONCURRENT_TEST_USERS[i/2] = userId;
- }
- }
- }
}
Modified: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java (original)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapProviderTest.java Thu Nov 12 10:29:00 2020
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertTha
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -51,57 +50,32 @@ import org.apache.jackrabbit.oak.spi.sec
import org.apache.jackrabbit.util.Text;
import org.hamcrest.Matchers;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
public class LdapProviderTest {
- protected static final InternalLdapServer LDAP_SERVER = new InternalLdapServer();
-
- //initialize LDAP server only once (fast, but might turn out to be not sufficiently flexible in the future)
- protected static final boolean USE_COMMON_LDAP_FIXTURE = false;
+ //loaded by a separate ClassLoader unavailable to the client (needed because the server is using old libraries)
+ protected LdapServerClassLoader.Proxy proxy;
private static final String TUTORIAL_LDIF = "apache-ds-tutorial.ldif";
-
private static final String ERRONEOUS_LDIF = "erroneous.ldif";
-
public static final String IDP_NAME = "ldap";
protected LdapIdentityProvider idp;
-
protected LdapProviderConfig providerConfig;
- @BeforeClass
- public static void beforeClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- initLdapFixture(LDAP_SERVER);
- }
- }
-
- @AfterClass
- public static void afterClass() throws Exception {
- if (USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
- }
-
@Before
public void before() throws Exception {
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.setUp();
- initLdapFixture(LDAP_SERVER);
- }
+ LdapServerClassLoader serverClassLoader = LdapServerClassLoader.createServerClassLoader();
+ proxy = serverClassLoader.createAndSetupServer();
+ proxy.loadLdif(getClass().getResourceAsStream(TUTORIAL_LDIF));
idp = createIDP();
}
@After
public void after() throws Exception {
- if (!USE_COMMON_LDAP_FIXTURE) {
- LDAP_SERVER.tearDown();
- }
+ proxy.tearDown();
if (idp != null) {
idp.close();
idp = null;
@@ -117,7 +91,7 @@ public class LdapProviderTest {
providerConfig = new LdapProviderConfig()
.setName(IDP_NAME)
.setHostname("127.0.0.1")
- .setPort(LDAP_SERVER.getPort())
+ .setPort(proxy.port)
.setBindDN(ServerDNConstants.ADMIN_SYSTEM_DN)
.setBindPassword(InternalLdapServer.ADMIN_PW)
.setGroupMemberAttribute("uniquemember")
@@ -135,11 +109,6 @@ public class LdapProviderTest {
return new LdapIdentityProvider(providerConfig);
}
- protected static void initLdapFixture(InternalLdapServer server) throws Exception {
- InputStream tutorialLDIF = LdapProviderTest.class.getResourceAsStream(TUTORIAL_LDIF);
- server.loadLdif(tutorialLDIF);
- }
-
public static final String TEST_USER0_DN = "cn=Rat Ratterson,ou=users,ou=system";
public static final String TEST_USER0_UID = "ratty";
@@ -192,9 +161,10 @@ public class LdapProviderTest {
@Test
public void testListUsersWithMissingUid() throws Exception {
// the ERRONEOUS_LDIF contains an entry without uid
- InputStream erroneousDIF = LdapProviderTest.class.getResourceAsStream(ERRONEOUS_LDIF);
- LDAP_SERVER.loadLdif(erroneousDIF);
+ proxy.loadLdif(getClass().getResourceAsStream(ERRONEOUS_LDIF));
Iterator<ExternalUser> users = idp.listUsers();
+ // make sure we got a result
+ assertTrue(users.hasNext());
// without the LdapInvalidAttributeValueException a NPE would result here:
while(users.hasNext()) {
ExternalUser user = users.next();
Added: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java?rev=1883345&view=auto
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java (added)
+++ jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java Thu Nov 12 10:29:00 2020
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.oak.security.authentication.ldap;
+
+import com.google.common.io.ByteStreams;
+import org.apache.directory.server.ldap.LdapServer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.ProtectionDomain;
+
+public class LdapServerClassLoader extends URLClassLoader {
+
+ private final byte[] serverClassResource;
+ private final byte[] serverBaseClassResource;
+
+ private LdapServerClassLoader(URL[] urls, Class serverClass, Class serverBaseClass) throws IOException {
+ super(urls, ClassLoader.getSystemClassLoader().getParent());
+ this.serverClassResource = ByteStreams.toByteArray(
+ serverClass.getResourceAsStream("/".concat(serverClass.getCanonicalName()).replace('.', '/').concat(".class")));
+ this.serverBaseClassResource = ByteStreams.toByteArray(
+ serverBaseClass.getResourceAsStream("/".concat(serverBaseClass.getCanonicalName()).replace('.', '/').concat(".class")));
+ }
+
+ public static LdapServerClassLoader createServerClassLoader() throws URISyntaxException, ClassNotFoundException, IOException {
+ ClassLoader appClassLoader = LdapServerClassLoader.class.getClassLoader();
+ String apacheDsUrl = appClassLoader.getResource(
+ LdapServer.class.getCanonicalName().replace(".", "/").concat(".class"))
+ .toURI()
+ .getRawSchemeSpecificPart();
+ apacheDsUrl = apacheDsUrl.substring(0, apacheDsUrl.lastIndexOf('!'));
+
+ Class<?> sc = appClassLoader.loadClass(InternalLdapServer.class.getCanonicalName());
+ Class<?> sbc = appClassLoader.loadClass(AbstractServer.class.getCanonicalName());
+ return new LdapServerClassLoader(new URL[] { new URI(apacheDsUrl).toURL() }, sc, sbc);
+ }
+
+ public Proxy createAndSetupServer() throws Exception {
+ final Proxy proxy = new Proxy();
+ final Exception[] ex = new Exception[] { null };
+ Runnable r = () -> {
+ try {
+ proxy.serverClass = loadClass(InternalLdapServer.class.getCanonicalName());
+ Constructor<?> constructor = proxy.serverClass.getConstructor(new Class[0]);
+ proxy.server = constructor.newInstance(new Object[0]);
+ proxy.serverClass.getMethod("setUp", new Class[0]).invoke(proxy.server);
+ proxy.port = (int) proxy.serverClass.getMethod("getPort", new Class[0]).invoke(proxy.server);
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+ ex[0] = e;
+ }
+ };
+ Thread t = new Thread(r);
+ t.setContextClassLoader(this);
+ t.start();
+ t.join();
+ if (ex[0] != null) {
+ throw ex[0];
+ }
+ return proxy;
+ }
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ if (InternalLdapServer.class.getCanonicalName().equals(name)) {
+ return defineClass(name, serverClassResource, 0, serverClassResource.length, (ProtectionDomain) null);
+ }
+ if (AbstractServer.class.getCanonicalName().equals(name)) {
+ return defineClass(name, serverBaseClassResource, 0, serverBaseClassResource.length, (ProtectionDomain) null);
+ }
+ return super.findClass(name);
+ }
+
+ public static class Proxy {
+
+ //Proxy class for InternalLdapServer, using the correct ClassLoader. If marshalling of complex types is
+ //involved in a method call, a new thread with the correct context ClassLoader will execute the call to
+ //avoid casting issues (objects of identical types might not be castable across ClassLoaders).
+
+ public static Class serverClass;
+ public Object server;
+ public int port;
+
+ public void tearDown() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ serverClass.getMethod("tearDown", new Class[0]).invoke(server);
+ }
+
+ public void setMaxSizeLimit(long limit) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ serverClass.getMethod("setMaxSizeLimit", new Class[] { Long.TYPE }).invoke(server, limit);
+ }
+
+ public void loadLdif(InputStream in) throws Exception {
+ final Exception[] ex = new Exception[] { null };
+ Runnable r = () -> {
+ try {
+ serverClass.getMethod("loadLdif", new Class[] {InputStream.class}).invoke(server, in);
+ } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+ ex[0] = e;
+ }
+
+ };
+ Thread t = new Thread(r);
+ t.setContextClassLoader(serverClass.getClassLoader());
+ t.start();
+ t.join();
+ if (ex[0] != null) {
+ throw ex[0];
+ }
+ }
+
+ public String addUser(String firstName, String lastName, String userId, String password) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ return (String) serverClass.getMethod("addUser", new Class[] {String.class, String.class, String.class, String.class}).invoke(server, firstName, lastName, userId, password);
+ }
+
+ public String addGroup(String name, String member) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ return (String) serverClass.getMethod("addGroup", new Class[] {String.class, String.class}).invoke(server, name, member);
+ }
+
+ public void addMember(String groupDN, String memberDN) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ serverClass.getMethod("addMember", new Class[] {String.class, String.class}).invoke(server, groupDN, memberDN);
+ }
+
+ public void addMembers(String name, Iterable<String> members) throws Exception {
+ final Exception[] ex = new Exception[] { null };
+ Runnable r = () -> {
+ try {
+ serverClass.getMethod("addMembers", new Class[] {String.class, Iterable.class}).invoke(server, name, members);
+ } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+ ex[0] = e;
+ }
+
+ };
+ Thread t = new Thread(r);
+ t.setContextClassLoader(serverClass.getClassLoader());
+ t.start();
+ t.join();
+ if (ex[0] != null) {
+ throw ex[0];
+ }
+ }
+ }
+}
Propchange: jackrabbit/oak/branches/1.22/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/branches/1.22/oak-it-osgi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-it-osgi/pom.xml?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-it-osgi/pom.xml (original)
+++ jackrabbit/oak/branches/1.22/oak-it-osgi/pom.xml Thu Nov 12 10:29:00 2020
@@ -188,6 +188,17 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
Modified: jackrabbit/oak/branches/1.22/oak-it-osgi/test-bundles.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.22/oak-it-osgi/test-bundles.xml?rev=1883345&r1=1883344&r2=1883345&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.22/oak-it-osgi/test-bundles.xml (original)
+++ jackrabbit/oak/branches/1.22/oak-it-osgi/test-bundles.xml Thu Nov 12 10:29:00 2020
@@ -39,6 +39,8 @@
<include>commons-collections:commons-collections</include>
<include>commons-fileupload:commons-fileupload</include>
<include>commons-logging:commons-logging</include>
+ <include>org.apache.commons:commons-lang3</include>
+ <include>org.apache.commons:commons-collections4</include>
<include>org.apache.jackrabbit:jackrabbit-jcr-commons</include>
<include>org.apache.jackrabbit:jackrabbit-data</include>
<include>org.apache.jackrabbit:oak-api</include>