KEYCLOAK-4175 Provide a way to set the connect and read timeout for ldap connections
This commit is contained in:
1 parent
be4f2aff63
commit
c32620b718
13 files changed
+85
-14
No files matched your search
+5
-1
@@ -35,7 +35,7 @@ public class LDAPConnectionTestManager {
|
||||
public static final String TEST_CONNECTION = "testConnection";
|
||||
public static final String TEST_AUTHENTICATION = "testAuthentication";
|
||||
|
||||
public boolean testLDAP(String action, String connectionUrl, String bindDn, String bindCredential, String useTruststoreSpi) {
|
||||
public boolean testLDAP(String action, String connectionUrl, String bindDn, String bindCredential, String useTruststoreSpi, String connectionTimeout) {
|
||||
if (!TEST_CONNECTION.equals(action) && !TEST_AUTHENTICATION.equals(action)) {
|
||||
ServicesLogger.LOGGER.unknownAction(action);
|
||||
return false;
|
||||
@@ -70,6 +70,10 @@ public class LDAPConnectionTestManager {
|
||||
|
||||
LDAPConstants.setTruststoreSpiIfNeeded(useTruststoreSpi, connectionUrl, env);
|
||||
|
||||
if (connectionTimeout != null && !connectionTimeout.isEmpty()) {
|
||||
env.put("com.sun.jndi.ldap.connect.timeout", connectionTimeout);
|
||||
}
|
||||
|
||||
ldapContext = new InitialLdapContext(env, null);
|
||||
return true;
|
||||
} catch (Exception ne) {
|
||||
|
||||
+3
-2
@@ -750,14 +750,15 @@ public class RealmAdminResource {
|
||||
@NoCache
|
||||
public Response testLDAPConnection(@QueryParam("action") String action, @QueryParam("connectionUrl") String connectionUrl,
|
||||
@QueryParam("bindDn") String bindDn, @QueryParam("bindCredential") String bindCredential,
|
||||
@QueryParam("useTruststoreSpi") String useTruststoreSpi, @QueryParam("componentId") String componentId) {
|
||||
@QueryParam("useTruststoreSpi") String useTruststoreSpi, @QueryParam("connectionTimeout") String connectionTimeout,
|
||||
@QueryParam("componentId") String componentId) {
|
||||
auth.init(RealmAuth.Resource.REALM).requireManage();
|
||||
|
||||
if (componentId != null && bindCredential.equals(ComponentRepresentation.SECRET_VALUE)) {
|
||||
bindCredential = realm.getComponent(componentId).getConfig().getFirst(LDAPConstants.BIND_CREDENTIAL);
|
||||
}
|
||||
|
||||
boolean result = new LDAPConnectionTestManager().testLDAP(action, connectionUrl, bindDn, bindCredential, useTruststoreSpi);
|
||||
boolean result = new LDAPConnectionTestManager().testLDAP(action, connectionUrl, bindDn, bindCredential, useTruststoreSpi, connectionTimeout);
|
||||
return result ? Response.noContent().build() : ErrorResponse.error("LDAP test error", Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user