diff --git a/auth/server/sasl/src/main/java/org/wildfly/security/auth/server/sasl/SaslAuthenticationFactory.java b/auth/server/sasl/src/main/java/org/wildfly/security/auth/server/sasl/SaslAuthenticationFactory.java index 3e15fa92d7b..1b4cfebf6e3 100644 --- a/auth/server/sasl/src/main/java/org/wildfly/security/auth/server/sasl/SaslAuthenticationFactory.java +++ b/auth/server/sasl/src/main/java/org/wildfly/security/auth/server/sasl/SaslAuthenticationFactory.java @@ -41,6 +41,7 @@ import org.wildfly.security.sasl.util.AbstractDelegatingSaslServerFactory; import org.wildfly.security.sasl.util.AuthenticationCompleteCallbackSaslServerFactory; import org.wildfly.security.sasl.util.AuthenticationTimeoutSaslServerFactory; +import org.wildfly.security.sasl.util.PropertiesSaslServerFactory; import org.wildfly.security.sasl.util.SaslMechanismInformation; import org.wildfly.security.sasl.util.SecurityIdentitySaslServerFactory; import org.wildfly.security.sasl.util.SetMechanismInformationSaslServerFactory; @@ -121,6 +122,7 @@ public static Builder builder() { public static final class Builder extends AbstractMechanismAuthenticationFactory.Builder { private ScheduledExecutorService scheduledExecutorService; + private Map properties; /** * Construct a new instance. @@ -143,6 +145,11 @@ public Builder setFactory(final SaslServerFactory factory) { return this; } + public Builder setProperties(final Map properties) { + this.properties = properties; + return this; + } + /** * Set the scheduled executor service. * @@ -174,6 +181,10 @@ public SaslAuthenticationFactory build() { } factory = new AuthenticationTimeoutSaslServerFactory(factory, this.scheduledExecutorService); + if (this.properties != null && this.properties.size() > 0) { + factory = new PropertiesSaslServerFactory(factory, properties); + } + return new SaslAuthenticationFactory(getSecurityDomain(), getMechanismConfigurationSelector(), factory); } } diff --git a/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslAuthenticationTimeoutTest.java b/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslAuthenticationTimeoutTest.java index cc6dfc01146..aff240baf5c 100644 --- a/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslAuthenticationTimeoutTest.java +++ b/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslAuthenticationTimeoutTest.java @@ -19,6 +19,7 @@ package org.wildfly.security.sasl.test; import static java.security.AccessController.doPrivileged; +import static org.wildfly.security.sasl.WildFlySasl.AUTHENTICATION_TIMEOUT; import java.net.URI; import java.net.URISyntaxException; @@ -26,7 +27,7 @@ import java.security.Provider; import java.security.Security; import java.util.Collections; -import java.util.Map; +import java.util.HashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; @@ -53,12 +54,8 @@ import org.wildfly.security.sasl.SaslMechanismSelector; import org.wildfly.security.sasl.digest.DigestServerFactory; import org.wildfly.security.sasl.digest.WildFlyElytronSaslDigestProvider; -import org.wildfly.security.sasl.util.AuthenticationTimeoutSaslServerFactory; import org.wildfly.security.sasl.util.SaslMechanismInformation; -import mockit.Mock; -import mockit.MockUp; - /** * Tests a successful authentication timeout for a custom executor service and the default executor service. * @@ -75,28 +72,8 @@ public class SaslAuthenticationTimeoutTest { WildFlyElytronPasswordProvider.getInstance() }; - /* - * Unable to set custom AUTHENTICATION_TIMEOUT using a property SaslServer factory (see ELY-1815), so using mock - * function to avoid using default timeout of 150 sec - */ - private static void mockGetTimeout() { - Class classToMock; - try { - classToMock = Class.forName("org.wildfly.security.sasl.util.AuthenticationTimeoutSaslServerFactory", true, AuthenticationTimeoutSaslServerFactory.class.getClassLoader()); - } catch (ClassNotFoundException e) { - throw new NoClassDefFoundError(e.getMessage()); - } - new MockUp(classToMock) { - @Mock - private long getTimeout(final Map props) { - return 3; - } - }; - } - @BeforeClass public static void registerPasswordProvider() { - mockGetTimeout(); for (Provider provider : providers) { Security.insertProviderAt(provider, 1); } @@ -121,12 +98,14 @@ public void testSuccessfulTimeout() throws Exception { INSTANCE.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); try { - + HashMap properties = new HashMap<>(); + properties.put(AUTHENTICATION_TIMEOUT, "3"); SaslServer server = new SaslServerBuilder(DigestServerFactory.class, DIGEST) .setUserName("George") .setPassword("gpwd".toCharArray()) .setProtocol("TestProtocol") .setServerName("TestServer") + .setProperties(properties) .setScheduledExecutorService(INSTANCE) .addMechanismRealm("TestRealm") .build(); @@ -153,12 +132,14 @@ public void testSuccessfulTimeout() throws Exception { public void testSuccessfulTimeout_DefaultExecuterService() throws Exception { try { - + HashMap properties = new HashMap<>(); + properties.put(AUTHENTICATION_TIMEOUT, "3"); SaslServer server = new SaslServerBuilder(DigestServerFactory.class, DIGEST) .setUserName("George") .setPassword("gpwd".toCharArray()) .setProtocol("TestProtocol") .setServerName("TestServer") + .setProperties(properties) .addMechanismRealm("TestRealm") .build(); diff --git a/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslServerBuilder.java b/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslServerBuilder.java index edaef80f352..003b4a94328 100644 --- a/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslServerBuilder.java +++ b/tests/base/src/test/java/org/wildfly/security/sasl/test/SaslServerBuilder.java @@ -77,7 +77,6 @@ import org.wildfly.security.sasl.util.ChannelBindingSaslServerFactory; import org.wildfly.security.sasl.util.CredentialSaslServerFactory; import org.wildfly.security.sasl.util.KeyManagerCredentialSaslServerFactory; -import org.wildfly.security.sasl.util.PropertiesSaslServerFactory; import org.wildfly.security.sasl.util.ProtocolSaslServerFactory; import org.wildfly.security.sasl.util.SecurityProviderSaslServerFactory; import org.wildfly.security.sasl.util.ServerNameSaslServerFactory; @@ -377,11 +376,8 @@ public SaslServer build() throws IOException { if (factory == null && providerSupplier != null) { factory = new SecurityProviderSaslServerFactory(providerSupplier); } - if (properties != null && properties.size() > 0) { - if (properties.containsKey(WildFlySasl.REALM_LIST)) { - factory = new AvailableRealmsSaslServerFactory(factory); - } - factory = new PropertiesSaslServerFactory(factory, properties); + if (properties != null && properties.size() > 0 && properties.containsKey(WildFlySasl.REALM_LIST)) { + factory = new AvailableRealmsSaslServerFactory(factory); } if (bindingTypeAndData != null) { factory = new ChannelBindingSaslServerFactory(factory, bindingTypeAndData.key, bindingTypeAndData.value); @@ -403,6 +399,9 @@ public SaslServer build() throws IOException { } final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder(); builder.setFactory(factory); + if (properties != null && properties.size() > 0) { + builder.setProperties(properties); + } builder.setSecurityDomain(securityDomain); if (scheduledExecutorService != null) { builder.setScheduledExecutorService(scheduledExecutorService);