diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/LDAPLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/LDAPLoginModule.java index b865bc6..94086ac 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/LDAPLoginModule.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/LDAPLoginModule.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.naming.Context; +import javax.naming.CommunicationException; import javax.naming.NamingEnumeration; import javax.naming.directory.*; import javax.net.ssl.SSLSocketFactory; @@ -271,6 +272,13 @@ public class LDAPLoginModule extends AbstractKarafLoginModule { } userDN = userDnAndNamespace[0]; userDNNamespace = userDnAndNamespace[1]; + } catch (CommunicationException ce) { + // explicitly catch CommunicationException as it my wrap a lower level root cause. + String rootCause = null; + if ( ce.getRootCause() != null) + rootCause = ce.getRootCause().getMessage(); + logger.warn("Can't connect to the LDAP server: " + ce.getMessage() + " " + rootCause); + throw new LoginException("Can't connect to the LDAP server: " + ce.getMessage()); } catch (Exception e) { throw new LoginException("Can't connect to the LDAP server: " + e.getMessage()); }