From cf056b346469b1010893b1220bfd8140242ce779 Mon Sep 17 00:00:00 2001 From: Douglas Palmer Date: Wed, 28 Feb 2018 08:23:11 -0800 Subject: [PATCH] [KEYCLOAK-6069] Allow configuration of LDAP connection pooling --- .../org/keycloak/storage/ldap/LDAPConfig.java | 28 ++++++++++ .../ldap/LDAPIdentityStoreRegistry.java | 25 +++++---- .../ldap/LDAPStorageProviderFactory.java | 21 +++++++ .../org/keycloak/models/LDAPConstants.java | 7 +++ .../page/federation/LdapUserProviderForm.java | 56 +++++++++++++++++++ .../federation/LdapUserFederationTest.java | 41 ++++++++++++++ .../messages/admin-messages_en.properties | 22 ++++++++ .../resources/partials/user-storage-ldap.html | 52 +++++++++++++++++ 8 files changed, 242 insertions(+), 10 deletions(-) diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPConfig.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPConfig.java index c2b3eb2620..eec80ee0f1 100644 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPConfig.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPConfig.java @@ -114,6 +114,34 @@ public class LDAPConfig { return config.getFirst(LDAPConstants.CONNECTION_POOLING); } + public String getConnectionPoolingAuthentication() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_AUTHENTICATION); + } + + public String getConnectionPoolingDebug() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_DEBUG); + } + + public String getConnectionPoolingInitSize() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_INITSIZE); + } + + public String getConnectionPoolingMaxSize() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_MAXSIZE); + } + + public String getConnectionPoolingPrefSize() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_PREFSIZE); + } + + public String getConnectionPoolingProtocol() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_PROTOCOL); + } + + public String getConnectionPoolingTimeout() { + return config.getFirst(LDAPConstants.CONNECTION_POOLING_TIMEOUT); + } + public String getConnectionTimeout() { return config.getFirst(LDAPConstants.CONNECTION_TIMEOUT); } diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPIdentityStoreRegistry.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPIdentityStoreRegistry.java index f6be1180ea..91077f859a 100644 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPIdentityStoreRegistry.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPIdentityStoreRegistry.java @@ -81,21 +81,26 @@ public class LDAPIdentityStoreRegistry { * Create LDAPIdentityStore to be cached in the local registry */ public static LDAPIdentityStore createLdapIdentityStore(LDAPConfig cfg) { - checkSystemProperty("com.sun.jndi.ldap.connect.pool.authentication", "none simple"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.initsize", "1"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.maxsize", "1000"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.prefsize", "5"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.timeout", "300000"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.protocol", "plain"); - checkSystemProperty("com.sun.jndi.ldap.connect.pool.debug", "off"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.authentication", cfg.getConnectionPoolingAuthentication(), "none simple"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.initsize", cfg.getConnectionPoolingInitSize(), "1"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.maxsize", cfg.getConnectionPoolingMaxSize(), "1000"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.prefsize", cfg.getConnectionPoolingPrefSize(), "5"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.timeout", cfg.getConnectionPoolingTimeout(), "300000"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.protocol", cfg.getConnectionPoolingProtocol(), "plain"); + checkSystemProperty("com.sun.jndi.ldap.connect.pool.debug", cfg.getConnectionPoolingDebug(), "off"); return new LDAPIdentityStore(cfg); } - private static void checkSystemProperty(String name, String defaultValue) { - if (System.getProperty(name) == null) { - System.setProperty(name, defaultValue); + private static void checkSystemProperty(String name, String cfgValue, String defaultValue) { + String value = System.getProperty(name); + if(cfgValue != null) { + value = cfgValue; } + if(value == null) { + value = defaultValue; + } + System.setProperty(name, value); } diff --git a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java index 6c33cac2df..a401e9ceb8 100755 --- a/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java +++ b/federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProviderFactory.java @@ -154,6 +154,27 @@ public class LDAPStorageProviderFactory implements UserStorageProviderFactory {{:: 'ldap.connection-pooling.tooltip' | translate}} + + +
+ +
+ +
+ {{:: 'ldap.connection-pooling.authentication.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.debug.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.initsize.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.maxsize.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.prefsize.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.protocol.tooltip' | translate}} +
+
+ +
+ +
+ {{:: 'ldap.connection-pooling.timeout.tooltip' | translate}}