aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle4
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/ApacheDS.java234
-rw-r--r--server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/LdapServer.java1
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/logging/TestILoggingEvent.java18
-rw-r--r--sonar-testing-ldap/build.gradle6
5 files changed, 24 insertions, 239 deletions
diff --git a/build.gradle b/build.gradle
index 72c4fcd51d5..67b93714380 100644
--- a/build.gradle
+++ b/build.gradle
@@ -209,7 +209,7 @@ subprojects {
dependency 'org.sonarsource.text:sonar-text-plugin:2.0.1.611'
// please keep this list alphabetically ordered
- dependencySet(group: 'ch.qos.logback', version: '1.2.10') {
+ dependencySet(group: 'ch.qos.logback', version: '1.3.5') {
entry 'logback-access'
entry 'logback-classic'
entry 'logback-core'
@@ -332,7 +332,7 @@ subprojects {
dependency('org.mockito:mockito-inline:4.10.0')
dependency 'org.mybatis:mybatis:3.5.11'
dependency 'org.nanohttpd:nanohttpd:2.3.1'
- dependencySet(group: 'org.slf4j', version: '1.7.36') {
+ dependencySet(group: 'org.slf4j', version: '2.0.6') {
entry 'jcl-over-slf4j'
entry 'jul-to-slf4j'
entry 'log4j-over-slf4j'
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/ApacheDS.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/ApacheDS.java
deleted file mode 100644
index b0b18d75386..00000000000
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/ApacheDS.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.auth.ldap.server;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-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.DefaultModification;
-import org.apache.directory.api.ldap.model.entry.ModificationOperation;
-import org.apache.directory.api.ldap.model.exception.LdapOperationException;
-import org.apache.directory.api.ldap.model.ldif.ChangeType;
-import org.apache.directory.api.ldap.model.ldif.LdifEntry;
-import org.apache.directory.api.ldap.model.ldif.LdifReader;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.api.util.FileUtils;
-import org.apache.directory.server.core.api.CoreSession;
-import org.apache.directory.server.core.api.DirectoryService;
-import org.apache.directory.server.core.api.InstanceLayout;
-import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
-import org.apache.directory.server.core.kerberos.KeyDerivationInterceptor;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
-import org.apache.directory.server.kerberos.KerberosConfig;
-import org.apache.directory.server.kerberos.kdc.KdcServer;
-import org.apache.directory.server.ldap.handlers.sasl.MechanismHandler;
-import org.apache.directory.server.ldap.handlers.sasl.cramMD5.CramMd5MechanismHandler;
-import org.apache.directory.server.ldap.handlers.sasl.digestMD5.DigestMd5MechanismHandler;
-import org.apache.directory.server.ldap.handlers.sasl.gssapi.GssapiMechanismHandler;
-import org.apache.directory.server.ldap.handlers.sasl.plain.PlainMechanismHandler;
-import org.apache.directory.server.protocol.shared.transport.TcpTransport;
-import org.apache.directory.server.protocol.shared.transport.UdpTransport;
-import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
-import org.apache.mina.util.AvailablePortFinder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class ApacheDS {
-
- private static final Logger LOG = LoggerFactory.getLogger(ApacheDS.class);
-
- private final String realm;
- private final String baseDn;
-
- private DirectoryService directoryService;
- private org.apache.directory.server.ldap.LdapServer ldapServer;
- private KdcServer kdcServer;
-
- private ApacheDS(String realm, String baseDn) {
- this.realm = realm;
- this.baseDn = baseDn;
- ldapServer = new org.apache.directory.server.ldap.LdapServer();
- }
-
- public static ApacheDS start(String realm, String baseDn, String workDir) throws Exception {
- return start(realm, baseDn, workDir + realm, null);
- }
-
- static ApacheDS start(String realm, String baseDn) throws Exception {
- return start(realm, baseDn, "target/ldap-work/" + realm, null);
- }
-
- private static ApacheDS start(String realm, String baseDn, String workDir, Integer port) throws Exception {
- return new ApacheDS(realm, baseDn)
- .startDirectoryService(workDir)
- .startKdcServer()
- .startLdapServer(port == null ? AvailablePortFinder.getNextAvailable(1024) : port)
- .activateNis();
- }
-
- void stop() throws Exception {
- kdcServer.stop();
- kdcServer = null;
- ldapServer.stop();
- ldapServer = null;
- directoryService.shutdown();
- directoryService = null;
- }
-
- public String getUrl() {
- return "ldap://localhost:" + ldapServer.getPort();
- }
-
- /**
- * Stream will be closed automatically.
- */
- public void importLdif(InputStream is) throws Exception {
- try (LdifReader reader = new LdifReader(is)) {
- CoreSession coreSession = directoryService.getAdminSession();
- // see LdifFileLoader
- for (LdifEntry ldifEntry : reader) {
- String ldif = ldifEntry.toString();
- LOG.info(ldif);
- if (ChangeType.Add == ldifEntry.getChangeType() || /* assume "add" by default */ ChangeType.None == ldifEntry.getChangeType()) {
- coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), ldifEntry.getEntry()));
- } else if (ChangeType.Modify == ldifEntry.getChangeType()) {
- coreSession.modify(ldifEntry.getDn(), ldifEntry.getModifications());
- } else if (ChangeType.Delete == ldifEntry.getChangeType()) {
- coreSession.delete(ldifEntry.getDn());
- } else {
- throw new IllegalStateException();
- }
- }
- }
- }
-
- void disableAnonymousAccess() {
- directoryService.setAllowAnonymousAccess(false);
- }
-
- void enableAnonymousAccess() {
- directoryService.setAllowAnonymousAccess(true);
- }
-
- private ApacheDS startDirectoryService(String workDirStr) throws Exception {
- DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
- factory.init(realm);
-
- directoryService = factory.getDirectoryService();
- directoryService.getChangeLog().setEnabled(false);
- directoryService.setShutdownHookEnabled(false);
- directoryService.setAllowAnonymousAccess(true);
-
- File workDir = new File(workDirStr);
- if (workDir.exists()) {
- FileUtils.deleteDirectory(workDir);
- }
- InstanceLayout instanceLayout = new InstanceLayout(workDir);
- directoryService.setInstanceLayout(instanceLayout);
-
- AvlPartition partition = new AvlPartition(directoryService.getSchemaManager());
- partition.setId("Test");
- partition.setSuffixDn(new Dn(directoryService.getSchemaManager(), baseDn));
- partition.addIndexedAttributes(
- new AvlIndex<>("ou"),
- new AvlIndex<>("uid"),
- new AvlIndex<>("dc"),
- new AvlIndex<>("objectClass"));
- partition.initialize();
- directoryService.addPartition(partition);
- directoryService.addLast(new KeyDerivationInterceptor());
-
- directoryService.shutdown();
- directoryService.startup();
-
- return this;
- }
-
- private ApacheDS startLdapServer(int port) throws Exception {
- ldapServer.setTransports(new TcpTransport(port));
- ldapServer.setDirectoryService(directoryService);
-
- // Setup SASL mechanisms
- Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<>();
- mechanismHandlerMap.put(SupportedSaslMechanisms.PLAIN, new PlainMechanismHandler());
- mechanismHandlerMap.put(SupportedSaslMechanisms.CRAM_MD5, new CramMd5MechanismHandler());
- mechanismHandlerMap.put(SupportedSaslMechanisms.DIGEST_MD5, new DigestMd5MechanismHandler());
- mechanismHandlerMap.put(SupportedSaslMechanisms.GSSAPI, new GssapiMechanismHandler());
- ldapServer.setSaslMechanismHandlers(mechanismHandlerMap);
-
- ldapServer.setSaslHost("localhost");
- ldapServer.setSaslRealms(Collections.singletonList(realm));
- // TODO ldapServer.setSaslPrincipal();
- // The base DN containing users that can be SASL authenticated.
- ldapServer.setSearchBaseDn(baseDn);
-
- ldapServer.start();
-
- return this;
- }
-
- private ApacheDS startKdcServer() throws IOException, LdapOperationException {
- int port = AvailablePortFinder.getNextAvailable(6088);
-
- KerberosConfig kdcConfig = new KerberosConfig();
- kdcConfig.setServicePrincipal("krbtgt/EXAMPLE.ORG@EXAMPLE.ORG");
- kdcConfig.setPrimaryRealm("EXAMPLE.ORG");
- kdcConfig.setPaEncTimestampRequired(false);
-
- kdcServer = new KdcServer(kdcConfig);
- kdcServer.setSearchBaseDn("dc=example,dc=org");
- kdcServer.addTransports(new UdpTransport("localhost", port));
- kdcServer.setDirectoryService(directoryService);
- kdcServer.start();
-
- FileUtils.writeStringToFile(new File("target/krb5.conf"), ""
- + "[libdefaults]\n"
- + " default_realm = EXAMPLE.ORG\n"
- + "\n"
- + "[realms]\n"
- + " EXAMPLE.ORG = {\n"
- + " kdc = localhost:" + port + "\n"
- + " }\n"
- + "\n"
- + "[domain_realm]\n"
- + " .example.org = EXAMPLE.ORG\n"
- + " example.org = EXAMPLE.ORG\n",
- StandardCharsets.UTF_8.name());
-
- return this;
- }
-
- /**
- * This seems to be required for objectClass posixGroup.
- */
- private ApacheDS activateNis() throws Exception {
- directoryService.getAdminSession().modify(
- new Dn("cn=nis,ou=schema"),
- new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE"));
- return this;
- }
-
-}
diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/LdapServer.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/LdapServer.java
index b313aab5ddc..0f628dbc89c 100644
--- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/LdapServer.java
+++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/server/LdapServer.java
@@ -20,6 +20,7 @@
package org.sonar.auth.ldap.server;
import org.junit.rules.ExternalResource;
+import org.sonar.ldap.ApacheDS;
public class LdapServer extends ExternalResource {
diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/TestILoggingEvent.java b/server/sonar-process/src/test/java/org/sonar/process/logging/TestILoggingEvent.java
index 2c266c5a1c3..c96599797a2 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/logging/TestILoggingEvent.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/logging/TestILoggingEvent.java
@@ -23,8 +23,10 @@ import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.LoggerContextVO;
+import java.util.List;
import java.util.Map;
import org.slf4j.Marker;
+import org.slf4j.event.KeyValuePair;
public class TestILoggingEvent implements ILoggingEvent {
private String formattedMessage;
@@ -88,6 +90,10 @@ public class TestILoggingEvent implements ILoggingEvent {
return null;
}
+ @Override public List<Marker> getMarkerList() {
+ return null;
+ }
+
@Override
public Map<String, String> getMDCPropertyMap() {
return null;
@@ -103,6 +109,18 @@ public class TestILoggingEvent implements ILoggingEvent {
return 0;
}
+ @Override public int getNanoseconds() {
+ return 0;
+ }
+
+ @Override public long getSequenceNumber() {
+ return 0;
+ }
+
+ @Override public List<KeyValuePair> getKeyValuePairs() {
+ return null;
+ }
+
@Override
public void prepareForDeferredProcessing() {
diff --git a/sonar-testing-ldap/build.gradle b/sonar-testing-ldap/build.gradle
index be7655faf03..bd0d8026b1b 100644
--- a/sonar-testing-ldap/build.gradle
+++ b/sonar-testing-ldap/build.gradle
@@ -5,10 +5,10 @@ sonar {
}
dependencies {
- api 'junit:junit'
- api 'org.apache.directory.server:apacheds-all:2.0.0-M24'
- api 'org.slf4j:slf4j-api'
+ api 'org.apache.mina:mina-core:2.2.1'
+ implementation 'org.apache.directory.server:apacheds-server-integ:2.0.0.AM26'
+ testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.hamcrest:hamcrest-core'
testImplementation 'org.mockito:mockito-core'