diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java index 8a6999849c..248d653dac 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java @@ -41,6 +41,7 @@ import org.keycloak.models.ClientModel; import org.keycloak.models.Constants; import org.keycloak.models.GroupModel; import org.keycloak.models.KeycloakSession; +import org.keycloak.models.LDAPConstants; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.UserSessionModel; @@ -56,6 +57,8 @@ import org.keycloak.provider.ProviderFactory; import org.keycloak.representations.adapters.action.GlobalRequestResult; import org.keycloak.representations.idm.AdminEventRepresentation; import org.keycloak.representations.idm.ClientRepresentation; +import org.keycloak.representations.idm.ComponentRepresentation; +import org.keycloak.representations.idm.CredentialRepresentation; import org.keycloak.representations.idm.EventRepresentation; import org.keycloak.representations.idm.GroupRepresentation; import org.keycloak.representations.idm.PartialImportRepresentation; @@ -747,9 +750,13 @@ 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("useTruststoreSpi") String useTruststoreSpi, @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); return result ? Response.noContent().build() : ErrorResponse.error("LDAP test error", Response.Status.BAD_REQUEST); } diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js index 43d37503db..27be677d48 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js @@ -1261,7 +1261,8 @@ module.controller('LDAPUserStorageCtrl', function($scope, $location, Notificatio connectionUrl: ldapConfig.connectionUrl, bindDn: ldapConfig.bindDn, bindCredential: ldapConfig.bindCredential, - useTruststoreSpi: ldapConfig.useTruststoreSpi + useTruststoreSpi: ldapConfig.useTruststoreSpi, + componentId: instance.id }; };