From 5ae443f06b4c5ca76e9e76bcd36040080699b135 Mon Sep 17 00:00:00 2001 From: Ivo Studensky Date: Mon, 30 Oct 2023 10:04:39 +0100 Subject: [PATCH] [WFCORE-5169] upgraded to Apache Directory Server AM27 and Kerby --- elytron/pom.xml | 16 +- .../extension/elytron/LdapService.java | 1 - .../extension/elytron/TestEnvironment.java | 1 - .../org/wildfly/extension/elytron/ldap.xml | 6 +- pom.xml | 9 +- .../InMemoryDirectoryServiceFactory.java | 462 +------------- .../suites/InMemorySchemaPartition.java | 41 +- testsuite/elytron/pom.xml | 7 +- .../AbstractKerberosMgmtSaslTestBase.java | 62 +- .../AbstractKrb5ConfServerSetupTask.java | 12 +- .../InMemoryDirectoryServiceFactory.java | 591 ------------------ .../kerberos/InMemorySchemaPartition.java | 82 --- .../KDCServerAnnotationProcessor.java | 236 ------- .../kerberos/ManagedCreateLdapServer.java | 8 + .../kerberos/ManagedCreateTransport.java | 7 + .../ldap/InMemoryDirectoryServiceFactory.java | 462 +------------- .../access/ldap/InMemorySchemaPartition.java | 41 +- 17 files changed, 129 insertions(+), 1915 deletions(-) delete mode 100644 testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemoryDirectoryServiceFactory.java delete mode 100644 testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemorySchemaPartition.java delete mode 100644 testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/KDCServerAnnotationProcessor.java diff --git a/elytron/pom.xml b/elytron/pom.xml index 8977ba6838d..d28409e273c 100644 --- a/elytron/pom.xml +++ b/elytron/pom.xml @@ -124,7 +124,7 @@ org.apache.directory.api api-ldap-codec-core - 1.0.0 + ${version.org.apache.directory.api} test @@ -137,7 +137,7 @@ org.apache.directory.api api-ldap-codec-standalone - 1.0.3 + ${version.org.apache.directory.api} test @@ -150,7 +150,7 @@ org.apache.directory.api api-ldap-net-mina - 1.0.3 + ${version.org.apache.directory.api} test @@ -163,7 +163,7 @@ org.apache.directory.server apacheds-core-annotations - 2.0.0-M24 + ${version.org.apache.ds} test @@ -178,13 +178,17 @@ org.bouncycastle bcprov-jdk15on + + org.bouncycastle + bcpkix-jdk15on + org.apache.directory.server apacheds-core-api - 2.0.0-M24 + ${version.org.apache.ds} test @@ -197,7 +201,7 @@ org.apache.directory.server apacheds-protocol-ldap - 2.0.0-M24 + ${version.org.apache.ds} test diff --git a/elytron/src/test/java/org/wildfly/extension/elytron/LdapService.java b/elytron/src/test/java/org/wildfly/extension/elytron/LdapService.java index c1f4f9f13ce..256584a91b0 100644 --- a/elytron/src/test/java/org/wildfly/extension/elytron/LdapService.java +++ b/elytron/src/test/java/org/wildfly/extension/elytron/LdapService.java @@ -130,7 +130,6 @@ public Builder addPartition(final String id, final String partitionName, final i for (String current : indexes) { partitionFactory.addIndex(partition, current, indexSize); } - partition.setCacheService(directoryService.getCacheService()); partition.initialize(); directoryService.addPartition(partition); diff --git a/elytron/src/test/java/org/wildfly/extension/elytron/TestEnvironment.java b/elytron/src/test/java/org/wildfly/extension/elytron/TestEnvironment.java index 9c4cebd4391..a9f34fa6b2e 100644 --- a/elytron/src/test/java/org/wildfly/extension/elytron/TestEnvironment.java +++ b/elytron/src/test/java/org/wildfly/extension/elytron/TestEnvironment.java @@ -77,7 +77,6 @@ private static KeyStore createLocalhostKeyStore(SelfSignedX509CertificateAndSign KeyStore localhostKeyStore = loadKeyStore(); X509Certificate issuerCertificate = issuerSelfSignedX509CertificateAndSigningKey.getSelfSignedCertificate(); - localhostKeyStore.setCertificateEntry("ca", issuerCertificate); X509Certificate localhostCertificate = new X509CertificateBuilder() .setIssuerDn(ISSUER_DN) diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/ldap.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/ldap.xml index 2b78deb5014..c546a5bee3b 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/ldap.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/ldap.xml @@ -26,9 +26,9 @@ - + - + @@ -87,7 +87,7 @@ - diff --git a/pom.xml b/pom.xml index d0a4a6d67d4..1970685d529 100644 --- a/pom.xml +++ b/pom.xml @@ -185,12 +185,9 @@ 2.4 1.8 2.2 - 2.0.0-M15 - + 2.0.0.AM27 + 2.1.5 + 2.0.3 4.5.14 4.4.16 2.22.1 diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemoryDirectoryServiceFactory.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemoryDirectoryServiceFactory.java index 6dc530204d2..fdecb96ca41 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemoryDirectoryServiceFactory.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemoryDirectoryServiceFactory.java @@ -7,53 +7,23 @@ import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Set; - -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.config.CacheConfiguration; -import net.sf.ehcache.config.Configuration; import org.apache.commons.io.FileUtils; -import org.apache.directory.api.ldap.codec.api.LdapApiService; import org.apache.directory.api.ldap.model.constants.SchemaConstants; -import org.apache.directory.api.ldap.model.csn.Csn; -import org.apache.directory.api.ldap.model.entry.Entry; -import org.apache.directory.api.ldap.model.exception.LdapException; -import org.apache.directory.api.ldap.model.ldif.LdifEntry; -import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.schema.LdapComparator; import org.apache.directory.api.ldap.model.schema.SchemaManager; import org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator; import org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry; import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader; -import org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader; -import org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager; -import org.apache.directory.api.ldap.util.tree.DnNode; +import org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader; +import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager; import org.apache.directory.api.util.exception.Exceptions; import org.apache.directory.server.constants.ServerDNConstants; import org.apache.directory.server.core.DefaultDirectoryService; -import org.apache.directory.server.core.api.CacheService; -import org.apache.directory.server.core.api.CoreSession; import org.apache.directory.server.core.api.DirectoryService; -import org.apache.directory.server.core.api.DnFactory; import org.apache.directory.server.core.api.InstanceLayout; -import org.apache.directory.server.core.api.LdapPrincipal; -import org.apache.directory.server.core.api.OperationEnum; -import org.apache.directory.server.core.api.OperationManager; -import org.apache.directory.server.core.api.ReferralManager; -import org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint; -import org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint; -import org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint; -import org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint; -import org.apache.directory.server.core.api.changelog.ChangeLog; -import org.apache.directory.server.core.api.event.EventService; -import org.apache.directory.server.core.api.interceptor.Interceptor; -import org.apache.directory.server.core.api.journal.Journal; import org.apache.directory.server.core.api.partition.Partition; -import org.apache.directory.server.core.api.partition.PartitionNexus; import org.apache.directory.server.core.api.schema.SchemaPartition; -import org.apache.directory.server.core.api.subtree.SubentryCache; -import org.apache.directory.server.core.api.subtree.SubtreeEvaluator; import org.apache.directory.server.core.factory.AvlPartitionFactory; import org.apache.directory.server.core.factory.DirectoryServiceFactory; import org.apache.directory.server.core.factory.PartitionFactory; @@ -72,7 +42,6 @@ public class InMemoryDirectoryServiceFactory implements DirectoryServiceFactory private final DirectoryService directoryService; private final PartitionFactory partitionFactory; - private CacheManager cacheManager; /** * Default constructor which creates {@link DefaultDirectoryService} instance and configures {@link AvlPartitionFactory} as @@ -121,15 +90,6 @@ public void init(String name) throws Exception { } directoryService.setInstanceLayout(instanceLayout); - // EhCache in disabled-like-mode - Configuration ehCacheConfig = new Configuration(); - CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 1).eternal(false).timeToIdleSeconds(30) - .timeToLiveSeconds(30).overflowToDisk(false); - ehCacheConfig.addDefaultCache(defaultCache); - cacheManager = new CacheManager(ehCacheConfig); - CacheService cacheService = new CacheService(cacheManager); - directoryService.setCacheService(cacheService); - // Init the schema // SchemaLoader loader = new SingleLdifSchemaLoader(); SchemaLoader loader = new JarLdifSchemaLoader(); @@ -153,9 +113,9 @@ public void init(String name) throws Exception { } // Init system partition - Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "system", - ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), - "system")); + Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), + directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, + new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system")); systemPartition.setSchemaManager(directoryService.getSchemaManager()); partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100); directoryService.setSystemPartition(systemPartition); @@ -168,7 +128,7 @@ public void init(String name) throws Exception { */ @Override public DirectoryService getDirectoryService() throws Exception { - return cacheManager != null ? new WrapperDirectoryService(directoryService, cacheManager) : directoryService; + return directoryService; } /** @@ -178,414 +138,4 @@ public DirectoryService getDirectoryService() throws Exception { public PartitionFactory getPartitionFactory() throws Exception { return partitionFactory; } - - private class WrapperDirectoryService implements DirectoryService { - - private final DirectoryService wrapped; - private final CacheManager cacheManager; - - private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) { - this.wrapped = wrapped; - this.cacheManager = cacheManager; - } - - @Override - public Entry newEntry(Dn dn) throws LdapException { - return wrapped.newEntry(dn); - } - - @Override - public long revert(long revision) throws LdapException { - return wrapped.revert(revision); - } - - @Override - public long revert() throws LdapException { - return wrapped.revert(); - } - - @Override - public PartitionNexus getPartitionNexus() { - return wrapped.getPartitionNexus(); - } - - @Override - public void addPartition(Partition partition) throws Exception { - wrapped.addPartition(partition); - } - - @Override - public void removePartition(Partition partition) throws Exception { - wrapped.removePartition(partition); - } - - @Override - public SchemaManager getSchemaManager() { - return wrapped.getSchemaManager(); - } - - @Override - public LdapApiService getLdapCodecService() { - return wrapped.getLdapCodecService(); - } - - @Override - public ReferralManager getReferralManager() { - return wrapped.getReferralManager(); - } - - @Override - public void setReferralManager(ReferralManager referralManager) { - wrapped.setReferralManager(referralManager); - } - - @Override - public SchemaPartition getSchemaPartition() { - return wrapped.getSchemaPartition(); - } - - @Override - public void setSchemaPartition(SchemaPartition schemaPartition) { - wrapped.setSchemaPartition(schemaPartition); - } - - @Override - public EventService getEventService() { - return wrapped.getEventService(); - } - - @Override - public void setEventService(EventService eventService) { - wrapped.setEventService(eventService); - } - - @Override - public void startup() throws Exception { - wrapped.startup(); - } - - @Override - public void shutdown() throws Exception { - wrapped.shutdown(); - cacheManager.shutdown(); - } - - @Override - public void sync() throws Exception { - wrapped.sync(); - } - - @Override - public boolean isStarted() { - return wrapped.isStarted(); - } - - @Override - public CoreSession getAdminSession() { - return wrapped.getAdminSession(); - } - - @Override - public SubentryCache getSubentryCache() { - return wrapped.getSubentryCache(); - } - - @Override - public SubtreeEvaluator getEvaluator() { - return wrapped.getEvaluator(); - } - - @Override - public CoreSession getSession() throws Exception { - return wrapped.getSession(); - } - - @Override - public CoreSession getSession(LdapPrincipal principal) throws Exception { - return wrapped.getSession(principal); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials) throws LdapException { - return wrapped.getSession(principalDn, credentials); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials, String saslMechanism, String saslAuthId) throws Exception { - return wrapped.getSession(principalDn, credentials, saslMechanism, saslAuthId); - } - - @Override - public void setInstanceId(String instanceId) { - wrapped.setInstanceId(instanceId); - } - - @Override - public String getInstanceId() { - return wrapped.getInstanceId(); - } - - @Override - public Set getPartitions() { - return wrapped.getPartitions(); - } - - @Override - public void setPartitions(Set partitions) { - wrapped.setPartitions(partitions); - } - - @Override - public boolean isAccessControlEnabled() { - return wrapped.isAccessControlEnabled(); - } - - @Override - public void setAccessControlEnabled(boolean accessControlEnabled) { - wrapped.setAccessControlEnabled(accessControlEnabled); - } - - @Override - public boolean isAllowAnonymousAccess() { - return wrapped.isAllowAnonymousAccess(); - } - - @Override - public boolean isPasswordHidden() { - return wrapped.isPasswordHidden(); - } - - @Override - public void setPasswordHidden(boolean passwordHidden) { - wrapped.setPasswordHidden(passwordHidden); - } - - @Override - public void setAllowAnonymousAccess(boolean enableAnonymousAccess) { - wrapped.setAllowAnonymousAccess(enableAnonymousAccess); - } - - @Override - public List getInterceptors() { - return wrapped.getInterceptors(); - } - - @Override - public List getInterceptors(OperationEnum operation) { - return wrapped.getInterceptors(operation); - } - - @Override - public void setInterceptors(List interceptors) { - wrapped.setInterceptors(interceptors); - } - - @Override - public void addFirst(Interceptor interceptor) throws LdapException { - wrapped.addFirst(interceptor); - } - - @Override - public void addLast(Interceptor interceptor) throws LdapException { - wrapped.addLast(interceptor); - } - - @Override - public void addAfter(String interceptorName, Interceptor interceptor) { - wrapped.addAfter(interceptorName, interceptor); - } - - @Override - public void remove(String interceptorName) { - wrapped.remove(interceptorName); - } - - @Override - public void setJournal(Journal journal) { - wrapped.setJournal(journal); - } - - @Override - public List getTestEntries() { - return wrapped.getTestEntries(); - } - - @Override - public void setTestEntries(List testEntries) { - wrapped.setTestEntries(testEntries); - } - - @Override - public InstanceLayout getInstanceLayout() { - return wrapped.getInstanceLayout(); - } - - @Override - public void setInstanceLayout(InstanceLayout instanceLayout) throws IOException { - wrapped.setInstanceLayout(instanceLayout); - } - - @Override - public void setShutdownHookEnabled(boolean shutdownHookEnabled) { - wrapped.setShutdownHookEnabled(shutdownHookEnabled); - } - - @Override - public boolean isShutdownHookEnabled() { - return wrapped.isShutdownHookEnabled(); - } - - @Override - public void setExitVmOnShutdown(boolean exitVmOnShutdown) { - wrapped.setExitVmOnShutdown(exitVmOnShutdown); - } - - @Override - public boolean isExitVmOnShutdown() { - return wrapped.isExitVmOnShutdown(); - } - - - @Override - public void setSystemPartition(Partition systemPartition) { - wrapped.setSystemPartition(systemPartition); - } - - @Override - public Partition getSystemPartition() { - return wrapped.getSystemPartition(); - } - - @Override - public boolean isDenormalizeOpAttrsEnabled() { - return wrapped.isDenormalizeOpAttrsEnabled(); - } - - @Override - public void setDenormalizeOpAttrsEnabled(boolean denormalizeOpAttrsEnabled) { - wrapped.setDenormalizeOpAttrsEnabled(denormalizeOpAttrsEnabled); - } - - @Override - public ChangeLog getChangeLog() { - return wrapped.getChangeLog(); - } - - @Override - public Journal getJournal() { - return wrapped.getJournal(); - } - - @Override - public void setChangeLog(ChangeLog changeLog) { - wrapped.setChangeLog(changeLog); - } - - @Override - public Entry newEntry(String ldif, String dn) { - return wrapped.newEntry(ldif, dn); - } - - @Override - public OperationManager getOperationManager() { - return wrapped.getOperationManager(); - } - - @Override - public int getMaxPDUSize() { - return wrapped.getMaxPDUSize(); - } - - @Override - public void setMaxPDUSize(int maxPDUSize) { - wrapped.setMaxPDUSize(maxPDUSize); - } - - @Override - public Interceptor getInterceptor(String interceptorName) { - return wrapped.getInterceptor(interceptorName); - } - - @Override - public Csn getCSN() { - return wrapped.getCSN(); - } - - @Override - public int getReplicaId() { - return wrapped.getReplicaId(); - } - - @Override - public void setReplicaId(int replicaId) { - wrapped.setReplicaId(replicaId); - } - - @Override - public void setSchemaManager(SchemaManager schemaManager) { - wrapped.setSchemaManager(schemaManager); - } - - @Override - public void setContextCsn(String lastCommittedCsnVal) { - wrapped.setContextCsn(lastCommittedCsnVal); - } - - @Override - public String getContextCsn() { - return wrapped.getContextCsn(); - } - - @Override - public void setSyncPeriodMillis(long syncPeriodMillis) { - wrapped.setSyncPeriodMillis(syncPeriodMillis); - } - - @Override - public long getSyncPeriodMillis() { - return wrapped.getSyncPeriodMillis(); - } - - @Override - public CacheService getCacheService() { - return wrapped.getCacheService(); - } - - @Override - public DnNode getAccessControlAPCache() { - return wrapped.getAccessControlAPCache(); - } - - @Override - public DnNode getCollectiveAttributeAPCache() { - return wrapped.getCollectiveAttributeAPCache(); - } - - @Override - public DnNode getSubschemaAPCache() { - return wrapped.getSubschemaAPCache(); - } - - @Override - public DnNode getTriggerExecutionAPCache() { - return wrapped.getTriggerExecutionAPCache(); - } - - @Override - public boolean isPwdPolicyEnabled() { - return wrapped.isPwdPolicyEnabled(); - } - - @Override - public DnFactory getDnFactory() { - return wrapped.getDnFactory(); - } - - @Override - public void setCacheService(CacheService cacheService) { - wrapped.setCacheService(cacheService); - } - - } - } diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemorySchemaPartition.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemorySchemaPartition.java index 4a11da92fd0..c262d50cee2 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemorySchemaPartition.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/suites/InMemorySchemaPartition.java @@ -4,6 +4,7 @@ */ package org.jboss.as.test.integration.domain.suites; +import java.io.IOException; import java.net.URL; import java.util.Map; import java.util.TreeSet; @@ -13,11 +14,12 @@ import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.entry.DefaultEntry; import org.apache.directory.api.ldap.model.entry.Entry; +import org.apache.directory.api.ldap.model.exception.LdapException; 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.schema.SchemaManager; -import org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor; -import org.apache.directory.api.ldap.schemaextractor.impl.ResourceMap; +import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor; +import org.apache.directory.api.ldap.schema.extractor.impl.ResourceMap; import org.apache.directory.server.core.api.interceptor.context.AddOperationContext; import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition; import org.slf4j.Logger; @@ -25,7 +27,7 @@ /** * In-memory schema-only partition which loads the data in the similar way as the - * {@link org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader}. + * {@link org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader}. * * @author Josef Cacek */ @@ -48,33 +50,36 @@ public InMemorySchemaPartition(SchemaManager schemaManager) { * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override - protected void doInit() throws Exception { + protected void doInit() throws LdapException { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); - suffixDn.apply(schemaManager); super.doInit(); // load schema final Map resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { - URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); - LdifReader reader = new LdifReader(resource.openStream()); - LdifEntry ldifEntry = reader.next(); - reader.close(); + try { + URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); + LdifReader reader = new LdifReader(resource.openStream()); + LdifEntry ldifEntry = reader.next(); + reader.close(); - Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); - // add mandatory attributes - if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { - entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); + Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); + // add mandatory attributes + if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { + entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); + } + if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { + entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); + } + AddOperationContext addContext = new AddOperationContext(null, entry); + super.add(addContext); + } catch (IOException e) { + throw new LdapException(e); } - if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { - entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); - } - AddOperationContext addContext = new AddOperationContext(null, entry); - super.add(addContext); } } } diff --git a/testsuite/elytron/pom.xml b/testsuite/elytron/pom.xml index 0bb82aebcad..2987266c721 100644 --- a/testsuite/elytron/pom.xml +++ b/testsuite/elytron/pom.xml @@ -157,12 +157,17 @@ org.wildfly.security wildfly-elytron-ssl - org.apache.directory.server apacheds-all test + + org.apache.kerby + kerb-simplekdc + ${version.org.apache.kerby} + test + diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java b/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java index 38daef43c28..4d3fe08cc47 100644 --- a/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java +++ b/testsuite/elytron/src/test/java/org/wildfly/test/integration/elytron/sasl/mgmt/AbstractKerberosMgmtSaslTestBase.java @@ -50,7 +50,6 @@ 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.schema.SchemaManager; -import org.apache.directory.server.annotations.CreateKdcServer; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; import org.apache.directory.server.annotations.SaslMechanism; @@ -61,13 +60,14 @@ import org.apache.directory.server.core.factory.DSAnnotationProcessor; import org.apache.directory.server.core.kerberos.KeyDerivationInterceptor; import org.apache.directory.server.factory.ServerAnnotationProcessor; -import org.apache.directory.server.kerberos.kdc.KdcServer; import org.apache.directory.server.ldap.LdapServer; 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.ntlm.NtlmMechanismHandler; import org.apache.directory.server.ldap.handlers.sasl.plain.PlainMechanismHandler; +import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer; +import org.apache.kerby.kerberos.kerb.server.impl.DefaultInternalKdcServerImpl; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.ietf.jgss.GSSCredential; import org.ietf.jgss.GSSManager; @@ -90,12 +90,9 @@ import org.wildfly.security.sasl.SaslMechanismSelector; import org.wildfly.security.ssl.SSLContextBuilder; import org.wildfly.test.security.common.kerberos.AbstractKrb5ConfServerSetupTask; -import org.wildfly.test.security.common.kerberos.InMemoryDirectoryServiceFactory; -import org.wildfly.test.security.common.kerberos.KDCServerAnnotationProcessor; import org.wildfly.test.security.common.kerberos.KerberosTestUtils; import org.wildfly.test.security.common.kerberos.Krb5LoginConfiguration; import org.wildfly.test.security.common.kerberos.ManagedCreateLdapServer; -import org.wildfly.test.security.common.kerberos.ManagedCreateTransport; import org.xnio.http.RedirectException; /** @@ -412,10 +409,8 @@ protected List kerberosUsers() { } // @formatter:off - @CreateDS(name = "WildFlyDS", factory = InMemoryDirectoryServiceFactory.class, partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"), additionalInterceptors = { + @CreateDS(name = "WildFlyDS", partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"), additionalInterceptors = { KeyDerivationInterceptor.class }, allowAnonAccess = true) - @CreateKdcServer(primaryRealm = "JBOSS.ORG", kdcPrincipal = "krbtgt/JBOSS.ORG@JBOSS.ORG", searchBaseDn = "dc=wildfly,dc=org", transports = { - @CreateTransport(protocol = "UDP", port = 6088) }) @CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT) }, saslHost = "localhost", saslPrincipal = "ldap/localhost@JBOSS.ORG", saslMechanisms = { @SaslMechanism(name = SupportedSaslMechanisms.PLAIN, implClass = PlainMechanismHandler.class), @@ -428,7 +423,7 @@ protected List kerberosUsers() { static class DirectoryServerSetupTask implements ServerSetupTask { private DirectoryService directoryService; - private KdcServer kdcServer; + private SimpleKdcServer kdcServer; private LdapServer ldapServer; private boolean removeBouncyCastle = false; @@ -436,10 +431,8 @@ static class DirectoryServerSetupTask implements ServerSetupTask { * Creates directory services, starts LDAP server and KDCServer * * @param managementClient - * @param containerId * @throws Exception - * @see org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient, - * java.lang.String) + * @see org.wildfly.core.testrunner.ServerSetupTask#setup(org.wildfly.core.testrunner.ManagementClient) */ @Override public void setup(ManagementClient managementClient) throws Exception { @@ -452,9 +445,9 @@ public void setup(ManagementClient managementClient) throws Exception { LOGGER.warn("Cannot register BouncyCastleProvider", ex); } directoryService = DSAnnotationProcessor.getDirectoryService(); - final String hostname = CoreUtils.getCannonicalHost(TestSuiteEnvironment.getHttpAddress()); + final String hostname = NetworkUtils.formatPossibleIpv6Address(CoreUtils.getCannonicalHost(TestSuiteEnvironment.getHttpAddress())); final Map map = new HashMap(); - map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname)); + map.put("hostname", hostname); final String secondaryTestAddress = NetworkUtils .canonize(CoreUtils.getCannonicalHost(TestSuiteEnvironment.getSecondaryTestAddress(false))); map.put("ldaphost", secondaryTestAddress); @@ -470,7 +463,24 @@ public void setup(ManagementClient managementClient) throws Exception { LOGGER.warn("Importing LDIF to a directoryService failed.", e); throw e; } - kdcServer = KDCServerAnnotationProcessor.getKdcServer(directoryService, 1024, hostname); + + // KDC server + kdcServer = new SimpleKdcServer(); + kdcServer.setKdcRealm("JBOSS.ORG"); + kdcServer.setKdcHost(hostname); + kdcServer.setInnerKdcImpl(new DefaultInternalKdcServerImpl(kdcServer.getKdcSetting())); + kdcServer.setAllowUdp(true); + kdcServer.setKdcUdpPort(6088); + + kdcServer.init(); + + kdcServer.createPrincipal("ldap/" + secondaryTestAddress + "@JBOSS.ORG","randall"); + kdcServer.createPrincipal("remote/" + hostname + "@JBOSS.ORG","zelvicka"); + kdcServer.createPrincipal("hnelson@JBOSS.ORG","secret"); + kdcServer.createPrincipal("jduke@JBOSS.ORG","theduke"); + + kdcServer.start(); + final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer( (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class)); createLdapServer.setSaslHost(secondaryTestAddress); @@ -484,17 +494,14 @@ public void setup(ManagementClient managementClient) throws Exception { KRB5_CONFIGURATION = new Krb5LoginConfiguration(CoreUtils.getLoginConfiguration()); // Use our custom configuration to avoid reliance on external config Configuration.setConfiguration(KRB5_CONFIGURATION); - } /** * Stops LDAP server and KDCServer and shuts down the directory service. * * @param managementClient - * @param containerId * @throws Exception - * @see org.jboss.as.arquillian.api.ServerSetupTask#tearDown(org.jboss.as.arquillian.container.ManagementClient, - * java.lang.String) + * @see org.wildfly.core.testrunner.ServerSetupTask#tearDown(org.wildfly.core.testrunner.ManagementClient) */ @Override public void tearDown(ManagementClient managementClient) throws Exception { @@ -512,22 +519,5 @@ public void tearDown(ManagementClient managementClient) throws Exception { } } - - /** - * Fixes/replaces LDAP bind address in the CreateTransport annotation of ApacheDS. - * - * @param createLdapServer - * @param address - */ - public static void fixApacheDSTransportAddress(ManagedCreateLdapServer createLdapServer, String address) { - final CreateTransport[] createTransports = createLdapServer.transports(); - for (int i = 0; i < createTransports.length; i++) { - final ManagedCreateTransport mgCreateTransport = new ManagedCreateTransport(createTransports[i]); - // localhost is a default used in original CreateTransport annotation. We use it as a fallback. - mgCreateTransport.setAddress(address != null ? address : "localhost"); - createTransports[i] = mgCreateTransport; - } - } } - } diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/AbstractKrb5ConfServerSetupTask.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/AbstractKrb5ConfServerSetupTask.java index e1455779561..843f8235c48 100644 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/AbstractKrb5ConfServerSetupTask.java +++ b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/AbstractKrb5ConfServerSetupTask.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.StrSubstitutor; import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory; -import org.apache.directory.server.kerberos.shared.keytab.Keytab; import org.apache.directory.shared.kerberos.KerberosTime; import org.apache.directory.shared.kerberos.codec.types.EncryptionType; import org.apache.directory.shared.kerberos.components.EncryptionKey; @@ -59,6 +58,10 @@ public abstract class AbstractKrb5ConfServerSetupTask implements ServerSetupTask public static final File HTTP_KEYTAB_FILE = new File(WORK_DIR, "http.keytab"); + private static final byte[] VERSION_0X502_BYTES = new byte[] + { ( byte ) 0x05, ( byte ) 0x02 }; + + private String origKrb5Conf; private String origKrbDebug; private String origIbmJGSSDebug; @@ -187,12 +190,13 @@ private String getSupportedEncTypes() { */ protected void createKeytab(final String principalName, final String passPhrase, final File keytabFile) throws IOException { LOGGER.trace("Principal name: " + principalName); - final KerberosTime timeStamp = new KerberosTime(); + long currentTime = System.currentTimeMillis(); + final KerberosTime timeStamp = new KerberosTime(currentTime); DataOutputStream dos = null; try { dos = new DataOutputStream(new FileOutputStream(keytabFile)); - dos.write(Keytab.VERSION_0X502_BYTES); + dos.write(VERSION_0X502_BYTES); for (Map.Entry keyEntry : KerberosKeyFactory.getKerberosKeys(principalName, passPhrase).entrySet()) { @@ -218,7 +222,7 @@ protected void createKeytab(final String principalName, final String passPhrase, } entryDos.writeInt(1); // principal type: KRB5_NT_PRINCIPAL - entryDos.writeInt((int) (timeStamp.getTime() / 1000)); + entryDos.writeInt((int) (currentTime / 1000)); entryDos.write(keyVersion); entryDos.writeShort((short) key.getKeyType().getValue()); diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemoryDirectoryServiceFactory.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemoryDirectoryServiceFactory.java deleted file mode 100644 index c2450cd77ba..00000000000 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemoryDirectoryServiceFactory.java +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.test.security.common.kerberos; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Set; - -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.config.CacheConfiguration; -import net.sf.ehcache.config.Configuration; - -import org.apache.commons.io.FileUtils; -import org.apache.directory.api.ldap.codec.api.LdapApiService; -import org.apache.directory.api.ldap.model.constants.SchemaConstants; -import org.apache.directory.api.ldap.model.csn.Csn; -import org.apache.directory.api.ldap.model.entry.Entry; -import org.apache.directory.api.ldap.model.exception.LdapException; -import org.apache.directory.api.ldap.model.ldif.LdifEntry; -import org.apache.directory.api.ldap.model.name.Dn; -import org.apache.directory.api.ldap.model.schema.LdapComparator; -import org.apache.directory.api.ldap.model.schema.SchemaManager; -import org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator; -import org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry; -import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader; -import org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader; -import org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager; -import org.apache.directory.api.ldap.util.tree.DnNode; -import org.apache.directory.api.util.exception.Exceptions; -import org.apache.directory.server.constants.ServerDNConstants; -import org.apache.directory.server.core.DefaultDirectoryService; -import org.apache.directory.server.core.api.CacheService; -import org.apache.directory.server.core.api.CoreSession; -import org.apache.directory.server.core.api.DirectoryService; -import org.apache.directory.server.core.api.DnFactory; -import org.apache.directory.server.core.api.InstanceLayout; -import org.apache.directory.server.core.api.LdapPrincipal; -import org.apache.directory.server.core.api.OperationEnum; -import org.apache.directory.server.core.api.OperationManager; -import org.apache.directory.server.core.api.ReferralManager; -import org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint; -import org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint; -import org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint; -import org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint; -import org.apache.directory.server.core.api.changelog.ChangeLog; -import org.apache.directory.server.core.api.event.EventService; -import org.apache.directory.server.core.api.interceptor.Interceptor; -import org.apache.directory.server.core.api.journal.Journal; -import org.apache.directory.server.core.api.partition.Partition; -import org.apache.directory.server.core.api.partition.PartitionNexus; -import org.apache.directory.server.core.api.schema.SchemaPartition; -import org.apache.directory.server.core.api.subtree.SubentryCache; -import org.apache.directory.server.core.api.subtree.SubtreeEvaluator; -import org.apache.directory.server.core.factory.AvlPartitionFactory; -import org.apache.directory.server.core.factory.DirectoryServiceFactory; -import org.apache.directory.server.core.factory.PartitionFactory; -import org.apache.directory.server.i18n.I18n; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory for a fast (mostly in-memory-only) ApacheDS DirectoryService. Use only for tests!! - * - * @author Josef Cacek - */ -public class InMemoryDirectoryServiceFactory implements DirectoryServiceFactory { - - private static Logger LOG = LoggerFactory.getLogger(InMemoryDirectoryServiceFactory.class); - - private final DirectoryService directoryService; - private final PartitionFactory partitionFactory; - private CacheManager cacheManager; - - /** - * Default constructor which creates {@link DefaultDirectoryService} instance and configures {@link AvlPartitionFactory} as - * the {@link PartitionFactory} implementation. - */ - public InMemoryDirectoryServiceFactory() { - try { - directoryService = new DefaultDirectoryService(); - } catch (Exception e) { - throw new RuntimeException(e); - } - directoryService.setShutdownHookEnabled(false); - partitionFactory = new AvlPartitionFactory(); - } - - /** - * Constructor which uses provided {@link DirectoryService} and {@link PartitionFactory} implementations. - * - * @param directoryService must be not-null - * @param partitionFactory must be not-null - */ - public InMemoryDirectoryServiceFactory(DirectoryService directoryService, PartitionFactory partitionFactory) { - this.directoryService = directoryService; - this.partitionFactory = partitionFactory; - } - - /** - * {@inheritDoc} - */ - @Override - public void init(String name) throws Exception { - if ((directoryService != null) && directoryService.isStarted()) { - return; - } - - directoryService.setInstanceId(name); - - // instance layout - InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name); - if (instanceLayout.getInstanceDirectory().exists()) { - try { - FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory()); - } catch (IOException e) { - LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e); - } - } - directoryService.setInstanceLayout(instanceLayout); - - // EhCache in disabled-like-mode - Configuration ehCacheConfig = new Configuration(); - CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 1).eternal(false).timeToIdleSeconds(30) - .timeToLiveSeconds(30).overflowToDisk(false); - ehCacheConfig.addDefaultCache(defaultCache); - cacheManager = new CacheManager(ehCacheConfig); - CacheService cacheService = new CacheService(cacheManager); - directoryService.setCacheService(cacheService); - - // Init the schema - // SchemaLoader loader = new SingleLdifSchemaLoader(); - SchemaLoader loader = new JarLdifSchemaLoader(); - SchemaManager schemaManager = new DefaultSchemaManager(loader); - schemaManager.loadAllEnabled(); - ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry(); - for (LdapComparator comparator : comparatorRegistry) { - if (comparator instanceof NormalizingComparator) { - ((NormalizingComparator) comparator).setOnServer(); - } - } - directoryService.setSchemaManager(schemaManager); - InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager); - - SchemaPartition schemaPartition = new SchemaPartition(schemaManager); - schemaPartition.setWrappedPartition(inMemorySchemaPartition); - directoryService.setSchemaPartition(schemaPartition); - List errors = schemaManager.getErrors(); - if (errors.size() != 0) { - throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors))); - } - - // Init system partition - Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "system", - ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), - "system")); - systemPartition.setSchemaManager(directoryService.getSchemaManager()); - partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100); - directoryService.setSystemPartition(systemPartition); - - directoryService.startup(); - } - - /** - * {@inheritDoc} - */ - @Override - public DirectoryService getDirectoryService() throws Exception { - return cacheManager != null ? new WrapperDirectoryService(directoryService, cacheManager) : directoryService; - } - - /** - * {@inheritDoc} - */ - @Override - public PartitionFactory getPartitionFactory() throws Exception { - return partitionFactory; - } - - private class WrapperDirectoryService implements DirectoryService { - - private final DirectoryService wrapped; - private final CacheManager cacheManager; - - private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) { - this.wrapped = wrapped; - this.cacheManager = cacheManager; - } - - @Override - public Entry newEntry(Dn dn) throws LdapException { - return wrapped.newEntry(dn); - } - - @Override - public long revert(long revision) throws LdapException { - return wrapped.revert(revision); - } - - @Override - public long revert() throws LdapException { - return wrapped.revert(); - } - - @Override - public PartitionNexus getPartitionNexus() { - return wrapped.getPartitionNexus(); - } - - @Override - public void addPartition(Partition partition) throws Exception { - wrapped.addPartition(partition); - } - - @Override - public void removePartition(Partition partition) throws Exception { - wrapped.removePartition(partition); - } - - @Override - public SchemaManager getSchemaManager() { - return wrapped.getSchemaManager(); - } - - @Override - public LdapApiService getLdapCodecService() { - return wrapped.getLdapCodecService(); - } - - @Override - public ReferralManager getReferralManager() { - return wrapped.getReferralManager(); - } - - @Override - public void setReferralManager(ReferralManager referralManager) { - wrapped.setReferralManager(referralManager); - } - - @Override - public SchemaPartition getSchemaPartition() { - return wrapped.getSchemaPartition(); - } - - @Override - public void setSchemaPartition(SchemaPartition schemaPartition) { - wrapped.setSchemaPartition(schemaPartition); - } - - @Override - public EventService getEventService() { - return wrapped.getEventService(); - } - - @Override - public void setEventService(EventService eventService) { - wrapped.setEventService(eventService); - } - - @Override - public void startup() throws Exception { - wrapped.startup(); - } - - @Override - public void shutdown() throws Exception { - wrapped.shutdown(); - cacheManager.shutdown(); - } - - @Override - public void sync() throws Exception { - wrapped.sync(); - } - - @Override - public boolean isStarted() { - return wrapped.isStarted(); - } - - @Override - public CoreSession getAdminSession() { - return wrapped.getAdminSession(); - } - - @Override - public SubentryCache getSubentryCache() { - return wrapped.getSubentryCache(); - } - - @Override - public SubtreeEvaluator getEvaluator() { - return wrapped.getEvaluator(); - } - - @Override - public CoreSession getSession() throws Exception { - return wrapped.getSession(); - } - - @Override - public CoreSession getSession(LdapPrincipal principal) throws Exception { - return wrapped.getSession(principal); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials) throws LdapException { - return wrapped.getSession(principalDn, credentials); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials, String saslMechanism, String saslAuthId) throws Exception { - return wrapped.getSession(principalDn, credentials, saslMechanism, saslAuthId); - } - - @Override - public void setInstanceId(String instanceId) { - wrapped.setInstanceId(instanceId); - } - - @Override - public String getInstanceId() { - return wrapped.getInstanceId(); - } - - @Override - public Set getPartitions() { - return wrapped.getPartitions(); - } - - @Override - public void setPartitions(Set partitions) { - wrapped.setPartitions(partitions); - } - - @Override - public boolean isAccessControlEnabled() { - return wrapped.isAccessControlEnabled(); - } - - @Override - public void setAccessControlEnabled(boolean accessControlEnabled) { - wrapped.setAccessControlEnabled(accessControlEnabled); - } - - @Override - public boolean isAllowAnonymousAccess() { - return wrapped.isAllowAnonymousAccess(); - } - - @Override - public boolean isPasswordHidden() { - return wrapped.isPasswordHidden(); - } - - @Override - public void setPasswordHidden(boolean passwordHidden) { - wrapped.setPasswordHidden(passwordHidden); - } - - @Override - public void setAllowAnonymousAccess(boolean enableAnonymousAccess) { - wrapped.setAllowAnonymousAccess(enableAnonymousAccess); - } - - @Override - public List getInterceptors() { - return wrapped.getInterceptors(); - } - - @Override - public List getInterceptors(OperationEnum operation) { - return wrapped.getInterceptors(operation); - } - - @Override - public void setInterceptors(List interceptors) { - wrapped.setInterceptors(interceptors); - } - - @Override - public void addFirst(Interceptor interceptor) throws LdapException { - wrapped.addFirst(interceptor); - } - - @Override - public void addLast(Interceptor interceptor) throws LdapException { - wrapped.addLast(interceptor); - } - - @Override - public void addAfter(String interceptorName, Interceptor interceptor) { - wrapped.addAfter(interceptorName, interceptor); - } - - @Override - public void remove(String interceptorName) { - wrapped.remove(interceptorName); - } - - @Override - public void setJournal(Journal journal) { - wrapped.setJournal(journal); - } - - @Override - public List getTestEntries() { - return wrapped.getTestEntries(); - } - - @Override - public void setTestEntries(List testEntries) { - wrapped.setTestEntries(testEntries); - } - - @Override - public InstanceLayout getInstanceLayout() { - return wrapped.getInstanceLayout(); - } - - @Override - public void setInstanceLayout(InstanceLayout instanceLayout) throws IOException { - wrapped.setInstanceLayout(instanceLayout); - } - - @Override - public void setShutdownHookEnabled(boolean shutdownHookEnabled) { - wrapped.setShutdownHookEnabled(shutdownHookEnabled); - } - - @Override - public boolean isShutdownHookEnabled() { - return wrapped.isShutdownHookEnabled(); - } - - @Override - public void setExitVmOnShutdown(boolean exitVmOnShutdown) { - wrapped.setExitVmOnShutdown(exitVmOnShutdown); - } - - @Override - public boolean isExitVmOnShutdown() { - return wrapped.isExitVmOnShutdown(); - } - - - @Override - public void setSystemPartition(Partition systemPartition) { - wrapped.setSystemPartition(systemPartition); - } - - @Override - public Partition getSystemPartition() { - return wrapped.getSystemPartition(); - } - - @Override - public boolean isDenormalizeOpAttrsEnabled() { - return wrapped.isDenormalizeOpAttrsEnabled(); - } - - @Override - public void setDenormalizeOpAttrsEnabled(boolean denormalizeOpAttrsEnabled) { - wrapped.setDenormalizeOpAttrsEnabled(denormalizeOpAttrsEnabled); - } - - @Override - public ChangeLog getChangeLog() { - return wrapped.getChangeLog(); - } - - @Override - public Journal getJournal() { - return wrapped.getJournal(); - } - - @Override - public void setChangeLog(ChangeLog changeLog) { - wrapped.setChangeLog(changeLog); - } - - @Override - public Entry newEntry(String ldif, String dn) { - return wrapped.newEntry(ldif, dn); - } - - @Override - public OperationManager getOperationManager() { - return wrapped.getOperationManager(); - } - - @Override - public int getMaxPDUSize() { - return wrapped.getMaxPDUSize(); - } - - @Override - public void setMaxPDUSize(int maxPDUSize) { - wrapped.setMaxPDUSize(maxPDUSize); - } - - @Override - public Interceptor getInterceptor(String interceptorName) { - return wrapped.getInterceptor(interceptorName); - } - - @Override - public Csn getCSN() { - return wrapped.getCSN(); - } - - @Override - public int getReplicaId() { - return wrapped.getReplicaId(); - } - - @Override - public void setReplicaId(int replicaId) { - wrapped.setReplicaId(replicaId); - } - - @Override - public void setSchemaManager(SchemaManager schemaManager) { - wrapped.setSchemaManager(schemaManager); - } - - @Override - public void setContextCsn(String lastCommittedCsnVal) { - wrapped.setContextCsn(lastCommittedCsnVal); - } - - @Override - public String getContextCsn() { - return wrapped.getContextCsn(); - } - - @Override - public void setSyncPeriodMillis(long syncPeriodMillis) { - wrapped.setSyncPeriodMillis(syncPeriodMillis); - } - - @Override - public long getSyncPeriodMillis() { - return wrapped.getSyncPeriodMillis(); - } - - @Override - public CacheService getCacheService() { - return wrapped.getCacheService(); - } - - @Override - public DnNode getAccessControlAPCache() { - return wrapped.getAccessControlAPCache(); - } - - @Override - public DnNode getCollectiveAttributeAPCache() { - return wrapped.getCollectiveAttributeAPCache(); - } - - @Override - public DnNode getSubschemaAPCache() { - return wrapped.getSubschemaAPCache(); - } - - @Override - public DnNode getTriggerExecutionAPCache() { - return wrapped.getTriggerExecutionAPCache(); - } - - @Override - public boolean isPwdPolicyEnabled() { - return wrapped.isPwdPolicyEnabled(); - } - - @Override - public DnFactory getDnFactory() { - return wrapped.getDnFactory(); - } - - @Override - public void setCacheService(CacheService cacheService) { - wrapped.setCacheService(cacheService); - } - - } - -} diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemorySchemaPartition.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemorySchemaPartition.java deleted file mode 100644 index f580f693f99..00000000000 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/InMemorySchemaPartition.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.test.security.common.kerberos; - -import java.net.URL; -import java.util.Map; -import java.util.TreeSet; -import java.util.UUID; -import java.util.regex.Pattern; - -import org.apache.directory.api.ldap.model.constants.SchemaConstants; -import org.apache.directory.api.ldap.model.entry.DefaultEntry; -import org.apache.directory.api.ldap.model.entry.Entry; -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.schema.SchemaManager; -import org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor; -import org.apache.directory.api.ldap.schemaextractor.impl.ResourceMap; -import org.apache.directory.server.core.api.interceptor.context.AddOperationContext; -import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * In-memory schema-only partition which loads the data in the similar way as the - * {@link org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader}. - * - * @author Josef Cacek - */ -public class InMemorySchemaPartition extends AbstractLdifPartition { - - private static Logger LOG = LoggerFactory.getLogger(InMemorySchemaPartition.class); - - /** - * Filesystem path separator pattern, either forward slash or backslash. java.util.regex.Pattern is immutable so only one - * instance is needed for all uses. - */ - - public InMemorySchemaPartition(SchemaManager schemaManager) { - super(schemaManager); - } - - /** - * Partition initialization - loads schema entries from the files on classpath. - * - * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() - */ - @Override - protected void doInit() throws Exception { - if (initialized) - return; - - LOG.debug("Initializing schema partition " + getId()); - suffixDn.apply(schemaManager); - super.doInit(); - - // load schema - final Map resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); - for (String resourcePath : new TreeSet(resMap.keySet())) { - if (resourcePath.endsWith(".ldif")) { - URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); - LdifReader reader = new LdifReader(resource.openStream()); - LdifEntry ldifEntry = reader.next(); - reader.close(); - - Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); - // add mandatory attributes - if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { - entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); - } - if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { - entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); - } - AddOperationContext addContext = new AddOperationContext(null, entry); - super.add(addContext); - } - } - } - -} diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/KDCServerAnnotationProcessor.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/KDCServerAnnotationProcessor.java deleted file mode 100644 index 0527172661d..00000000000 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/KDCServerAnnotationProcessor.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.test.security.common.kerberos; - -import java.io.IOException; -import java.lang.reflect.Field; -import javax.security.auth.kerberos.KerberosPrincipal; -import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; -import org.apache.directory.server.annotations.CreateChngPwdServer; -import org.apache.directory.server.annotations.CreateKdcServer; -import org.apache.directory.server.annotations.CreateTransport; -import org.apache.directory.server.core.annotations.AnnotationUtils; -import org.apache.directory.server.core.api.DirectoryService; -import org.apache.directory.server.i18n.I18n; -import org.apache.directory.server.kerberos.ChangePasswordConfig; -import org.apache.directory.server.kerberos.KerberosConfig; -import org.apache.directory.server.kerberos.changepwd.ChangePasswordServer; -import org.apache.directory.server.kerberos.kdc.KdcServer; -import org.apache.directory.server.kerberos.shared.replay.ReplayCache; -import org.apache.directory.server.protocol.shared.transport.TcpTransport; -import org.apache.directory.server.protocol.shared.transport.Transport; -import org.apache.directory.server.protocol.shared.transport.UdpTransport; -import org.apache.directory.shared.kerberos.KerberosTime; -import org.apache.mina.util.AvailablePortFinder; -import org.jboss.logging.Logger; - -/** - * Annotation processor for creating Kerberos servers - based on original implementation in - * {@link org.apache.directory.server.factory.ServerAnnotationProcessor}. This implementation only adds a workaround for - * https://issues.apache.org/jira/browse/DIRKRB-85
- * Use this class together with {@link ExtCreateKdcServer} annotation. - * - * @author Josef Cacek - * @see ExtCreateKdcServer - */ -public class KDCServerAnnotationProcessor { - - // Public methods -------------------------------------------------------- - /** - * Creates and starts KdcServer based on configuration from {@link ExtCreateKdcServer} annotation. - * - * @param directoryService - * @param startPort start port number used for searching free ports in case the transport has no port number preconfigured. - * @return - * @throws Exception - */ - public static KdcServer getKdcServer(DirectoryService directoryService, int startPort, String address) throws Exception { - final CreateKdcServer createKdcServer = (CreateKdcServer) AnnotationUtils.getInstance(CreateKdcServer.class); - return createKdcServer(createKdcServer, directoryService, startPort, address); - } - - // Private methods ------------------------------------------------------- - /** - * Creates and starts {@link KdcServer} instance based on given configuration. - * - * @param createKdcServer - * @param directoryService - * @param startPort - * @return - */ - private static KdcServer createKdcServer(CreateKdcServer createKdcServer, DirectoryService directoryService, - int startPort, String bindAddress) { - if (createKdcServer == null) { - return null; - } - - KerberosConfig kdcConfig = new KerberosConfig(); - kdcConfig.setServicePrincipal(createKdcServer.kdcPrincipal()); - kdcConfig.setPrimaryRealm(createKdcServer.primaryRealm()); - kdcConfig.setMaximumTicketLifetime(createKdcServer.maxTicketLifetime()); - kdcConfig.setMaximumRenewableLifetime(createKdcServer.maxRenewableLifetime()); - kdcConfig.setPaEncTimestampRequired(false); - - KdcServer kdcServer = new NoReplayKdcServer(kdcConfig); - - kdcServer.setSearchBaseDn(createKdcServer.searchBaseDn()); - - CreateTransport[] transportBuilders = createKdcServer.transports(); - - if (transportBuilders == null) { - // create only UDP transport if none specified - UdpTransport defaultTransport = new UdpTransport(bindAddress, AvailablePortFinder.getNextAvailable(startPort)); - kdcServer.addTransports(defaultTransport); - } else if (transportBuilders.length > 0) { - for (CreateTransport transportBuilder : transportBuilders) { - String protocol = transportBuilder.protocol(); - int port = transportBuilder.port(); - int nbThreads = transportBuilder.nbThreads(); - int backlog = transportBuilder.backlog(); - final String address = bindAddress != null ? bindAddress : transportBuilder.address(); - - if (port == -1) { - port = AvailablePortFinder.getNextAvailable(startPort); - startPort = port + 1; - } - - if (protocol.equalsIgnoreCase("TCP")) { - Transport tcp = new TcpTransport(address, port, nbThreads, backlog); - kdcServer.addTransports(tcp); - } else if (protocol.equalsIgnoreCase("UDP")) { - UdpTransport udp = new UdpTransport(address, port); - kdcServer.addTransports(udp); - } else { - throw new IllegalArgumentException(I18n.err(I18n.ERR_689, protocol)); - } - } - } - - CreateChngPwdServer[] createChngPwdServers = createKdcServer.chngPwdServer(); - - if (createChngPwdServers.length > 0) { - - CreateChngPwdServer createChngPwdServer = createChngPwdServers[0]; - ChangePasswordConfig config = new ChangePasswordConfig(kdcConfig); - config.setServicePrincipal(createChngPwdServer.srvPrincipal()); - - ChangePasswordServer chngPwdServer = new ChangePasswordServer(config); - - for (CreateTransport transportBuilder : createChngPwdServer.transports()) { - Transport t = createTransport(transportBuilder, startPort); - startPort = t.getPort() + 1; - chngPwdServer.addTransports(t); - } - - chngPwdServer.setDirectoryService(directoryService); - - kdcServer.setChangePwdServer(chngPwdServer); - } - - kdcServer.setDirectoryService(directoryService); - - // Launch the server - try { - kdcServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - - return kdcServer; - - } - - private static Transport createTransport( CreateTransport transportBuilder, int startPort ) { - String protocol = transportBuilder.protocol(); - int port = transportBuilder.port(); - int nbThreads = transportBuilder.nbThreads(); - int backlog = transportBuilder.backlog(); - String address = transportBuilder.address(); - - if ( port == -1 ) - { - port = AvailablePortFinder.getNextAvailable( startPort ); - startPort = port + 1; - } - - if ( protocol.equalsIgnoreCase( "TCP" ) ) - { - Transport tcp = new TcpTransport( address, port, nbThreads, backlog ); - return tcp; - } - else if ( protocol.equalsIgnoreCase( "UDP" ) ) - { - UdpTransport udp = new UdpTransport( address, port ); - return udp; - } - else - { - throw new IllegalArgumentException( I18n.err( I18n.ERR_689, protocol ) ); - } - } - -} - - -/** - * - * Replacement of apacheDS KdcServer class with disabled ticket replay cache. - * - * @author Dominik Pospisil - */ -class NoReplayKdcServer extends KdcServer { - - NoReplayKdcServer(KerberosConfig kdcConfig) { - super(kdcConfig); - } - - private static Logger LOGGER = Logger.getLogger(NoReplayKdcServer.class); - - /** - * - * Dummy implementation of the ApacheDS kerberos replay cache. Essentially disables kerbores ticket replay checks. - * https://issues.jboss.org/browse/JBPAPP-10974 - * - * @author Dominik Pospisil - */ - private class DummyReplayCache implements ReplayCache { - - @Override - public boolean isReplay(KerberosPrincipal serverPrincipal, KerberosPrincipal clientPrincipal, KerberosTime clientTime, - int clientMicroSeconds) { - return false; - } - - @Override - public void save(KerberosPrincipal serverPrincipal, KerberosPrincipal clientPrincipal, KerberosTime clientTime, - int clientMicroSeconds) { - return; - } - - @Override - public void clear() { - return; - } - - } - - /** - * @throws IOException if we cannot bind to the sockets - */ - public void start() throws IOException, LdapInvalidDnException { - super.start(); - - try { - - // override initialized replay cache with a dummy implementation - Field replayCacheField = KdcServer.class.getDeclaredField("replayCache"); - replayCacheField.setAccessible(true); - replayCacheField.set(this, new DummyReplayCache()); - } catch (Exception e) { - LOGGER.warn("Unable to override replay cache.", e); - } - - } -} diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateLdapServer.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateLdapServer.java index 0cf5a183fee..4f695108857 100644 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateLdapServer.java +++ b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateLdapServer.java @@ -47,6 +47,8 @@ public class ManagedCreateLdapServer extends AnnotationLiteral /** The service principal, used by GSSAPI. */ private String[] saslRealms; + private Class[] trustManagers; + // Constructors ---------------------------------------------------------- /** @@ -69,6 +71,7 @@ public ManagedCreateLdapServer(CreateLdapServer createLdapServer) { saslHost = createLdapServer.saslHost(); saslPrincipal = createLdapServer.saslPrincipal(); saslRealms = createLdapServer.saslRealms(); + trustManagers = createLdapServer.trustManagers(); } // Public methods -------------------------------------------------------- @@ -190,6 +193,11 @@ public String saslPrincipal() { return saslPrincipal; } + @Override + public Class[] trustManagers() { + return trustManagers; + } + @Override public String[] saslRealms() { return saslRealms; diff --git a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateTransport.java b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateTransport.java index 51dfdd3b76c..215a08390f6 100644 --- a/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateTransport.java +++ b/testsuite/elytron/src/test/java/org/wildfly/test/security/common/kerberos/ManagedCreateTransport.java @@ -30,6 +30,7 @@ public class ManagedCreateTransport extends AnnotationLiteral i private boolean ssl; /** The number of threads to use. Default to 3 */ private int nbThreads; + private boolean clientAuth; // Constructors ---------------------------------------------------------- @@ -46,6 +47,7 @@ public ManagedCreateTransport(final CreateTransport original) { backlog = original.backlog(); ssl = original.ssl(); nbThreads = original.nbThreads(); + clientAuth = original.clientAuth(); } // Public methods -------------------------------------------------------- @@ -113,6 +115,11 @@ public int nbThreads() { return nbThreads; } + @Override + public boolean clientAuth() { + return clientAuth; + } + /** * Set the protocol. * diff --git a/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemoryDirectoryServiceFactory.java b/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemoryDirectoryServiceFactory.java index 69ad320062f..a0dfdc33768 100644 --- a/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemoryDirectoryServiceFactory.java +++ b/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemoryDirectoryServiceFactory.java @@ -7,53 +7,23 @@ import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Set; - -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.config.CacheConfiguration; -import net.sf.ehcache.config.Configuration; import org.apache.commons.io.FileUtils; -import org.apache.directory.api.ldap.codec.api.LdapApiService; import org.apache.directory.api.ldap.model.constants.SchemaConstants; -import org.apache.directory.api.ldap.model.csn.Csn; -import org.apache.directory.api.ldap.model.entry.Entry; -import org.apache.directory.api.ldap.model.exception.LdapException; -import org.apache.directory.api.ldap.model.ldif.LdifEntry; -import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.schema.LdapComparator; import org.apache.directory.api.ldap.model.schema.SchemaManager; import org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator; import org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry; import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader; -import org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader; -import org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager; -import org.apache.directory.api.ldap.util.tree.DnNode; +import org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader; +import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager; import org.apache.directory.api.util.exception.Exceptions; import org.apache.directory.server.constants.ServerDNConstants; import org.apache.directory.server.core.DefaultDirectoryService; -import org.apache.directory.server.core.api.CacheService; -import org.apache.directory.server.core.api.CoreSession; import org.apache.directory.server.core.api.DirectoryService; -import org.apache.directory.server.core.api.DnFactory; import org.apache.directory.server.core.api.InstanceLayout; -import org.apache.directory.server.core.api.LdapPrincipal; -import org.apache.directory.server.core.api.OperationEnum; -import org.apache.directory.server.core.api.OperationManager; -import org.apache.directory.server.core.api.ReferralManager; -import org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint; -import org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint; -import org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint; -import org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint; -import org.apache.directory.server.core.api.changelog.ChangeLog; -import org.apache.directory.server.core.api.event.EventService; -import org.apache.directory.server.core.api.interceptor.Interceptor; -import org.apache.directory.server.core.api.journal.Journal; import org.apache.directory.server.core.api.partition.Partition; -import org.apache.directory.server.core.api.partition.PartitionNexus; import org.apache.directory.server.core.api.schema.SchemaPartition; -import org.apache.directory.server.core.api.subtree.SubentryCache; -import org.apache.directory.server.core.api.subtree.SubtreeEvaluator; import org.apache.directory.server.core.factory.AvlPartitionFactory; import org.apache.directory.server.core.factory.DirectoryServiceFactory; import org.apache.directory.server.core.factory.PartitionFactory; @@ -72,7 +42,6 @@ public class InMemoryDirectoryServiceFactory implements DirectoryServiceFactory private final DirectoryService directoryService; private final PartitionFactory partitionFactory; - private CacheManager cacheManager; /** * Default constructor which creates {@link DefaultDirectoryService} instance and configures {@link AvlPartitionFactory} as @@ -121,15 +90,6 @@ public void init(String name) throws Exception { } directoryService.setInstanceLayout(instanceLayout); - // EhCache in disabled-like-mode - Configuration ehCacheConfig = new Configuration(); - CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 1).eternal(false).timeToIdleSeconds(30) - .timeToLiveSeconds(30).overflowToDisk(false); - ehCacheConfig.addDefaultCache(defaultCache); - cacheManager = new CacheManager(ehCacheConfig); - CacheService cacheService = new CacheService(cacheManager); - directoryService.setCacheService(cacheService); - // Init the schema // SchemaLoader loader = new SingleLdifSchemaLoader(); SchemaLoader loader = new JarLdifSchemaLoader(); @@ -153,9 +113,9 @@ public void init(String name) throws Exception { } // Init system partition - Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "system", - ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), - "system")); + Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), + directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, + new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system")); systemPartition.setSchemaManager(directoryService.getSchemaManager()); partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100); directoryService.setSystemPartition(systemPartition); @@ -168,7 +128,7 @@ public void init(String name) throws Exception { */ @Override public DirectoryService getDirectoryService() throws Exception { - return cacheManager != null ? new WrapperDirectoryService(directoryService, cacheManager) : directoryService; + return directoryService; } /** @@ -178,414 +138,4 @@ public DirectoryService getDirectoryService() throws Exception { public PartitionFactory getPartitionFactory() throws Exception { return partitionFactory; } - - private class WrapperDirectoryService implements DirectoryService { - - private final DirectoryService wrapped; - private final CacheManager cacheManager; - - private WrapperDirectoryService(DirectoryService wrapped, CacheManager cacheManager) { - this.wrapped = wrapped; - this.cacheManager = cacheManager; - } - - @Override - public Entry newEntry(Dn dn) throws LdapException { - return wrapped.newEntry(dn); - } - - @Override - public long revert(long revision) throws LdapException { - return wrapped.revert(revision); - } - - @Override - public long revert() throws LdapException { - return wrapped.revert(); - } - - @Override - public PartitionNexus getPartitionNexus() { - return wrapped.getPartitionNexus(); - } - - @Override - public void addPartition(Partition partition) throws Exception { - wrapped.addPartition(partition); - } - - @Override - public void removePartition(Partition partition) throws Exception { - wrapped.removePartition(partition); - } - - @Override - public SchemaManager getSchemaManager() { - return wrapped.getSchemaManager(); - } - - @Override - public LdapApiService getLdapCodecService() { - return wrapped.getLdapCodecService(); - } - - @Override - public ReferralManager getReferralManager() { - return wrapped.getReferralManager(); - } - - @Override - public void setReferralManager(ReferralManager referralManager) { - wrapped.setReferralManager(referralManager); - } - - @Override - public SchemaPartition getSchemaPartition() { - return wrapped.getSchemaPartition(); - } - - @Override - public void setSchemaPartition(SchemaPartition schemaPartition) { - wrapped.setSchemaPartition(schemaPartition); - } - - @Override - public EventService getEventService() { - return wrapped.getEventService(); - } - - @Override - public void setEventService(EventService eventService) { - wrapped.setEventService(eventService); - } - - @Override - public void startup() throws Exception { - wrapped.startup(); - } - - @Override - public void shutdown() throws Exception { - wrapped.shutdown(); - cacheManager.shutdown(); - } - - @Override - public void sync() throws Exception { - wrapped.sync(); - } - - @Override - public boolean isStarted() { - return wrapped.isStarted(); - } - - @Override - public CoreSession getAdminSession() { - return wrapped.getAdminSession(); - } - - @Override - public SubentryCache getSubentryCache() { - return wrapped.getSubentryCache(); - } - - @Override - public SubtreeEvaluator getEvaluator() { - return wrapped.getEvaluator(); - } - - @Override - public CoreSession getSession() throws Exception { - return wrapped.getSession(); - } - - @Override - public CoreSession getSession(LdapPrincipal principal) throws Exception { - return wrapped.getSession(principal); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials) throws LdapException { - return wrapped.getSession(principalDn, credentials); - } - - @Override - public CoreSession getSession(Dn principalDn, byte[] credentials, String saslMechanism, String saslAuthId) throws Exception { - return wrapped.getSession(principalDn, credentials, saslMechanism, saslAuthId); - } - - @Override - public void setInstanceId(String instanceId) { - wrapped.setInstanceId(instanceId); - } - - @Override - public String getInstanceId() { - return wrapped.getInstanceId(); - } - - @Override - public Set getPartitions() { - return wrapped.getPartitions(); - } - - @Override - public void setPartitions(Set partitions) { - wrapped.setPartitions(partitions); - } - - @Override - public boolean isAccessControlEnabled() { - return wrapped.isAccessControlEnabled(); - } - - @Override - public void setAccessControlEnabled(boolean accessControlEnabled) { - wrapped.setAccessControlEnabled(accessControlEnabled); - } - - @Override - public boolean isAllowAnonymousAccess() { - return wrapped.isAllowAnonymousAccess(); - } - - @Override - public boolean isPasswordHidden() { - return wrapped.isPasswordHidden(); - } - - @Override - public void setPasswordHidden(boolean passwordHidden) { - wrapped.setPasswordHidden(passwordHidden); - } - - @Override - public void setAllowAnonymousAccess(boolean enableAnonymousAccess) { - wrapped.setAllowAnonymousAccess(enableAnonymousAccess); - } - - @Override - public List getInterceptors() { - return wrapped.getInterceptors(); - } - - @Override - public List getInterceptors(OperationEnum operation) { - return wrapped.getInterceptors(operation); - } - - @Override - public void setInterceptors(List interceptors) { - wrapped.setInterceptors(interceptors); - } - - @Override - public void addFirst(Interceptor interceptor) throws LdapException { - wrapped.addFirst(interceptor); - } - - @Override - public void addLast(Interceptor interceptor) throws LdapException { - wrapped.addLast(interceptor); - } - - @Override - public void addAfter(String interceptorName, Interceptor interceptor) { - wrapped.addAfter(interceptorName, interceptor); - } - - @Override - public void remove(String interceptorName) { - wrapped.remove(interceptorName); - } - - @Override - public void setJournal(Journal journal) { - wrapped.setJournal(journal); - } - - @Override - public List getTestEntries() { - return wrapped.getTestEntries(); - } - - @Override - public void setTestEntries(List testEntries) { - wrapped.setTestEntries(testEntries); - } - - @Override - public InstanceLayout getInstanceLayout() { - return wrapped.getInstanceLayout(); - } - - @Override - public void setInstanceLayout(InstanceLayout instanceLayout) throws IOException { - wrapped.setInstanceLayout(instanceLayout); - } - - @Override - public void setShutdownHookEnabled(boolean shutdownHookEnabled) { - wrapped.setShutdownHookEnabled(shutdownHookEnabled); - } - - @Override - public boolean isShutdownHookEnabled() { - return wrapped.isShutdownHookEnabled(); - } - - @Override - public void setExitVmOnShutdown(boolean exitVmOnShutdown) { - wrapped.setExitVmOnShutdown(exitVmOnShutdown); - } - - @Override - public boolean isExitVmOnShutdown() { - return wrapped.isExitVmOnShutdown(); - } - - - @Override - public void setSystemPartition(Partition systemPartition) { - wrapped.setSystemPartition(systemPartition); - } - - @Override - public Partition getSystemPartition() { - return wrapped.getSystemPartition(); - } - - @Override - public boolean isDenormalizeOpAttrsEnabled() { - return wrapped.isDenormalizeOpAttrsEnabled(); - } - - @Override - public void setDenormalizeOpAttrsEnabled(boolean denormalizeOpAttrsEnabled) { - wrapped.setDenormalizeOpAttrsEnabled(denormalizeOpAttrsEnabled); - } - - @Override - public ChangeLog getChangeLog() { - return wrapped.getChangeLog(); - } - - @Override - public Journal getJournal() { - return wrapped.getJournal(); - } - - @Override - public void setChangeLog(ChangeLog changeLog) { - wrapped.setChangeLog(changeLog); - } - - @Override - public Entry newEntry(String ldif, String dn) { - return wrapped.newEntry(ldif, dn); - } - - @Override - public OperationManager getOperationManager() { - return wrapped.getOperationManager(); - } - - @Override - public int getMaxPDUSize() { - return wrapped.getMaxPDUSize(); - } - - @Override - public void setMaxPDUSize(int maxPDUSize) { - wrapped.setMaxPDUSize(maxPDUSize); - } - - @Override - public Interceptor getInterceptor(String interceptorName) { - return wrapped.getInterceptor(interceptorName); - } - - @Override - public Csn getCSN() { - return wrapped.getCSN(); - } - - @Override - public int getReplicaId() { - return wrapped.getReplicaId(); - } - - @Override - public void setReplicaId(int replicaId) { - wrapped.setReplicaId(replicaId); - } - - @Override - public void setSchemaManager(SchemaManager schemaManager) { - wrapped.setSchemaManager(schemaManager); - } - - @Override - public void setContextCsn(String lastCommittedCsnVal) { - wrapped.setContextCsn(lastCommittedCsnVal); - } - - @Override - public String getContextCsn() { - return wrapped.getContextCsn(); - } - - @Override - public void setSyncPeriodMillis(long syncPeriodMillis) { - wrapped.setSyncPeriodMillis(syncPeriodMillis); - } - - @Override - public long getSyncPeriodMillis() { - return wrapped.getSyncPeriodMillis(); - } - - @Override - public CacheService getCacheService() { - return wrapped.getCacheService(); - } - - @Override - public DnNode getAccessControlAPCache() { - return wrapped.getAccessControlAPCache(); - } - - @Override - public DnNode getCollectiveAttributeAPCache() { - return wrapped.getCollectiveAttributeAPCache(); - } - - @Override - public DnNode getSubschemaAPCache() { - return wrapped.getSubschemaAPCache(); - } - - @Override - public DnNode getTriggerExecutionAPCache() { - return wrapped.getTriggerExecutionAPCache(); - } - - @Override - public boolean isPwdPolicyEnabled() { - return wrapped.isPwdPolicyEnabled(); - } - - @Override - public DnFactory getDnFactory() { - return wrapped.getDnFactory(); - } - - @Override - public void setCacheService(CacheService cacheService) { - wrapped.setCacheService(cacheService); - } - - } - } diff --git a/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemorySchemaPartition.java b/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemorySchemaPartition.java index 21aaecd3e99..ccab997c1ff 100644 --- a/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemorySchemaPartition.java +++ b/testsuite/rbac/src/test/java/org/jboss/as/test/integration/mgmt/access/ldap/InMemorySchemaPartition.java @@ -4,6 +4,7 @@ */ package org.jboss.as.test.integration.mgmt.access.ldap; +import java.io.IOException; import java.net.URL; import java.util.Map; import java.util.TreeSet; @@ -13,11 +14,12 @@ import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.entry.DefaultEntry; import org.apache.directory.api.ldap.model.entry.Entry; +import org.apache.directory.api.ldap.model.exception.LdapException; 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.schema.SchemaManager; -import org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor; -import org.apache.directory.api.ldap.schemaextractor.impl.ResourceMap; +import org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor; +import org.apache.directory.api.ldap.schema.extractor.impl.ResourceMap; import org.apache.directory.server.core.api.interceptor.context.AddOperationContext; import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition; import org.slf4j.Logger; @@ -25,7 +27,7 @@ /** * In-memory schema-only partition which loads the data in the similar way as the - * {@link org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader}. + * {@link org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader}. * * @author Josef Cacek */ @@ -48,33 +50,36 @@ public InMemorySchemaPartition(SchemaManager schemaManager) { * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override - protected void doInit() throws Exception { + protected void doInit() throws LdapException { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); - suffixDn.apply(schemaManager); super.doInit(); // load schema final Map resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { - URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); - LdifReader reader = new LdifReader(resource.openStream()); - LdifEntry ldifEntry = reader.next(); - reader.close(); + try { + URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); + LdifReader reader = new LdifReader(resource.openStream()); + LdifEntry ldifEntry = reader.next(); + reader.close(); - Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); - // add mandatory attributes - if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { - entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); + Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); + // add mandatory attributes + if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { + entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); + } + if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { + entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); + } + AddOperationContext addContext = new AddOperationContext(null, entry); + super.add(addContext); + } catch (IOException e) { + throw new LdapException(e); } - if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { - entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); - } - AddOperationContext addContext = new AddOperationContext(null, entry); - super.add(addContext); } } }