[java-identity-provider] branch main updated: IDP-2488 - LDAP authentication factory defaults
Codeberg
noreply at shibboleth.net
Fri Nov 20 01:56:32 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
https://codeberg.org/Shibboleth/java-identity-provider/commit/01343f5ca637284be89c103e6ddba475690333fc
The following commit(s) were added to refs/heads/main by this push:
new 01343f5ca IDP-2488 - LDAP authentication factory defaults
01343f5ca is described below
commit 01343f5ca637284be89c103e6ddba475690333fc
Author: Daniel Fisher <dfisher at vt.edu>
AuthorDate: Thu Nov 19 20:26:37 2026 -0500
IDP-2488 - LDAP authentication factory defaults
https://shibboleth.atlassian.net/browse/IDP-2488
Provide defaults where possible to align settings with the defaults in password-authn-beans.xml.
Use library defaults if a property is set to null and would produce an NPE.
Update LDAPAuthenticationFactoryBeanTest.
---
.../config/LDAPAuthenticationFactoryBean.java | 80 +++++++++++++--------
.../config/LDAPAuthenticationFactoryBeanTest.java | 82 ++++++++++++++++++++++
2 files changed, 134 insertions(+), 28 deletions(-)
diff --git a/idp-authn-api/src/main/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBean.java b/idp-authn-api/src/main/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBean.java
index 19f9390c0..4425a06bd 100644
--- a/idp-authn-api/src/main/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBean.java
+++ b/idp-authn-api/src/main/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBean.java
@@ -300,37 +300,37 @@ public class LDAPAuthenticationFactoryBean extends AbstractFactoryBean<Authentic
/** Type of authenticator to configure. */
- private AuthenticatorType authenticatorType;
+ private AuthenticatorType authenticatorType = AuthenticatorType.ANON_SEARCH;
/** Type of trust model to configure. */
- private TrustType trustType;
+ private TrustType trustType = TrustType.CERTIFICATE;
/** Type of connection strategy to configure. */
- private ConnectionStrategyType connectionStrategyType;
+ private ConnectionStrategyType connectionStrategyType = ConnectionStrategyType.ACTIVE_PASSIVE;
/** LDAP URL. */
- private String ldapUrl;
+ private String ldapUrl = "ldap://localhost:10389";
/** Whether to use startTLS for connections. */
- private boolean useStartTLS;
+ private boolean useStartTLS = true;
/** Wait time for startTLS responses. */
- private Duration startTLSTimeout;
+ private Duration startTLSTimeout = Duration.ofSeconds(3);
/** Whether to use the allow-all hostname verifier. */
private boolean disableHostnameVerification;
/** Wait time for connects. */
- private Duration connectTimeout;
+ private Duration connectTimeout = Duration.ofSeconds(3);
/** Wait time for operation responses. */
- private Duration responseTimeout;
+ private Duration responseTimeout = Duration.ofSeconds(3);
/** Whether to automatically reconnect to the server when a connection is lost. */
- private boolean autoReconnect;
+ private boolean autoReconnect = true;
/** Wait time for reconnects. */
- private Duration reconnectTimeout;
+ private Duration reconnectTimeout = Duration.ofSeconds(10);
/** Trust configuration when using certificate based trust. */
private CredentialConfig trustCertificatesCredentialConfig;
@@ -342,39 +342,39 @@ public class LDAPAuthenticationFactoryBean extends AbstractFactoryBean<Authentic
private boolean disablePooling;
/** Wait time for getting a connection from the pool. */
- private Duration blockWaitTime;
+ private Duration blockWaitTime = Duration.ofSeconds(3);
/** Minimum pool size. */
- private int minPoolSize;
+ private int minPoolSize = 3;
/** Maximum pool size. */
- private int maxPoolSize;
+ private int maxPoolSize = 10;
/** Whether to validate connections when checked out from the pool. */
private boolean validateOnCheckout;
/** Whether to validate connections periodically on a background thread. */
- private boolean validatePeriodically;
+ private boolean validatePeriodically = true;
/** Period at which to validate periodically. */
- private Duration validatePeriod;
+ private Duration validatePeriod = Duration.ofMinutes(5);
/** DN to perform connection pool validation against. */
private String validateDn;
/** Filter to execute against {@link #validateDn}. */
- private String validateFilter;
+ private String validateFilter = "(objectClass=*)";
/** Type of passivator to configure for the bind pool. */
- private PassivatorType bindPoolPassivatorType;
+ private PassivatorType bindPoolPassivatorType = PassivatorType.NONE;
/** Period at which to check and enforce the idle time. */
- private Duration prunePeriod;
+ private Duration prunePeriod = Duration.ofMinutes(5);
/**
* Time at which a connection has been idle and should be removed from the pool.
*/
- private Duration idleTime;
+ private Duration idleTime = Duration.ofMinutes(10);
/**
* Java format string used to construct an LDAP DN. See
@@ -817,11 +817,19 @@ public class LDAPAuthenticationFactoryBean extends AbstractFactoryBean<Authentic
final ConnectionConfig config = new ConnectionConfig();
config.setLdapUrl(ldapUrl);
config.setUseStartTLS(useStartTLS);
- config.setStartTLSTimeout(startTLSTimeout);
- config.setConnectTimeout(connectTimeout);
- config.setResponseTimeout(responseTimeout);
+ if (startTLSTimeout != null) {
+ config.setStartTLSTimeout(startTLSTimeout);
+ }
+ if (connectTimeout != null) {
+ config.setConnectTimeout(connectTimeout);
+ }
+ if (responseTimeout != null) {
+ config.setResponseTimeout(responseTimeout);
+ }
config.setAutoReconnect(autoReconnect);
- config.setReconnectTimeout(reconnectTimeout);
+ if (reconnectTimeout != null) {
+ config.setReconnectTimeout(reconnectTimeout);
+ }
switch (connectionStrategyType) {
case ROUND_ROBIN:
config.setConnectionStrategy(new RoundRobinConnectionStrategy());
@@ -898,10 +906,22 @@ public class LDAPAuthenticationFactoryBean extends AbstractFactoryBean<Authentic
factory.setMaxPoolSize(maxPoolSize);
factory.setValidateOnCheckOut(validateOnCheckout);
factory.setValidatePeriodically(validatePeriodically);
- factory.setName(name);
- factory.setBlockWaitTime(blockWaitTime);
- factory.setPruneStrategy(new IdlePruneStrategy(prunePeriod, idleTime));
- factory.setValidator(validator);
+ if (name != null) {
+ factory.setName(name);
+ }
+ if (blockWaitTime != null) {
+ factory.setBlockWaitTime(blockWaitTime);
+ }
+ if (idleTime != null) {
+ if (prunePeriod != null) {
+ factory.setPruneStrategy(new IdlePruneStrategy(prunePeriod, idleTime));
+ } else {
+ factory.setPruneStrategy(new IdlePruneStrategy(idleTime));
+ }
+ }
+ if (validator != null) {
+ factory.setValidator(validator);
+ }
if (passivator != null) {
factory.setPassivator(passivator);
}
@@ -936,7 +956,11 @@ public class LDAPAuthenticationFactoryBean extends AbstractFactoryBean<Authentic
searchFilter.setFilter("(objectClass=*)");
}
searchRequest.setFilter(searchFilter);
- return SearchConnectionValidator.builder().request(searchRequest).period(validatePeriod).build();
+ final SearchConnectionValidator validator = new SearchConnectionValidator(searchRequest);
+ if (validatePeriod != null) {
+ validator.setValidatePeriod(validatePeriod);
+ }
+ return validator;
}
/**
diff --git a/idp-authn-api/src/test/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBeanTest.java b/idp-authn-api/src/test/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBeanTest.java
index 744902a5f..bda294569 100644
--- a/idp-authn-api/src/test/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBeanTest.java
+++ b/idp-authn-api/src/test/java/net/shibboleth/idp/authn/config/LDAPAuthenticationFactoryBeanTest.java
@@ -17,6 +17,7 @@ package net.shibboleth.idp.authn.config;
import java.time.Duration;
import java.util.Map;
+import net.shibboleth.shared.logic.ConstraintViolationException;
import org.apache.velocity.VelocityContext;
import org.ldaptive.Credential;
import org.ldaptive.auth.AuthenticationRequest;
@@ -136,6 +137,87 @@ public class LDAPAuthenticationFactoryBeanTest {
}
}
+ @Test public void testNullPropertiesIllegalArgument() throws Exception {
+ final LDAPAuthenticationFactoryBean bean = new LDAPAuthenticationFactoryBean();
+ // these properties map to enums and will produce illegal argument exception
+ try {
+ bean.setAuthenticatorType(null);
+ Assert.fail("Should have thrown exception");
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
+ }
+ try {
+ bean.setTrustType(null);
+ Assert.fail("Should have thrown exception");
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
+ }
+ try {
+ bean.setConnectionStrategyType(null);
+ Assert.fail("Should have thrown exception");
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
+ }
+ try {
+ bean.setBindPoolPassivatorType(null);
+ Assert.fail("Should have thrown exception");
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), IllegalArgumentException.class);
+ }
+ }
+
+ @Test public void testNullPropertiesConstraintViolation() throws Exception {
+ final LDAPAuthenticationFactoryBean bean = new LDAPAuthenticationFactoryBean();
+ bean.setVelocityEngine(VelocityEngine.newVelocityEngine());
+ // these properties won't produce an NPE, but will produce a constraint violation when the instance is created
+ bean.setLdapUrl(null);
+ try {
+ bean.createInstance();
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), ConstraintViolationException.class);
+ }
+ bean.setLdapUrl("ldap://localhost:389");
+
+ bean.setBaseDn(null);
+ try {
+ bean.createInstance();
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), ConstraintViolationException.class);
+ }
+ bean.setLdapUrl("dc=shibboleth,dc=net");
+
+ bean.setUserFilter(null);
+ try {
+ bean.createInstance();
+ } catch (Exception e) {
+ Assert.assertEquals(e.getClass(), ConstraintViolationException.class);
+ }
+ bean.setUserFilter("(uid={user})");
+
+ Assert.assertNotNull(bean.createInstance());
+ }
+
+ @Test public void testNullProperties() throws Exception {
+ final LDAPAuthenticationFactoryBean bean = new LDAPAuthenticationFactoryBean();
+ bean.setVelocityEngine(VelocityEngine.newVelocityEngine());
+ bean.setUserFilter("(uid={user})");
+ // setting durations to null are ignored in favor of the library defaults
+ bean.setStartTLSTimeout(null);
+ bean.setConnectTimeout(null);
+ bean.setResponseTimeout(null);
+ bean.setReconnectTimeout(null);
+ bean.setBlockWaitTime(null);
+ bean.setPrunePeriod(null);
+ bean.setIdleTime(null);
+ bean.setValidatePeriod(null);
+ // rootDSE is used if null is provided
+ bean.setValidateDn(null);
+ // objectclass=* is used if null is provided
+ bean.setValidateFilter(null);
+
+ Assert.assertNotNull(bean.createInstance());
+ }
+
private AuthenticationRequest createAuthenticationRequest(final String username, final String password) {
final UsernamePasswordContext upc = new UsernamePasswordContext();
upc.setUsername(username);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list