improved ldap logging. added stacktrace in debug level incase of exceptions.

Conflicts:
	plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
This commit is contained in:
Rajani Karuturi 2014-04-22 11:37:31 +05:30 committed by Abhinandan Prateek
parent ef9e2a9367
commit a92610d277
2 changed files with 12 additions and 4 deletions

View File

@ -53,9 +53,12 @@ public class LdapContextFactory {
return createInitialDirContext(principal, password, null, isSystemContext);
}
private DirContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext)
throws NamingException {
return new InitialDirContext(getEnvironment(principal, password, providerUrl, isSystemContext));
private DirContext createInitialDirContext(final String principal,
final String password, final String providerUrl,
final boolean isSystemContext) throws NamingException {
Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext);
s_logger.debug("initializing ldap with provider url: "+ environment.get(Context.PROVIDER_URL));
return new InitialDirContext(environment);
}
public DirContext createUserContext(final String principal, final String password) throws NamingException {

View File

@ -81,6 +81,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
s_logger.info("Added new ldap server with hostname: " + hostname);
return new LdapConfigurationResponse(hostname, port);
} catch (final NamingException e) {
s_logger.debug("NamingException while doing an LDAP bind", e);
throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
}
} else {
@ -98,6 +99,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
closeContext(context);
return true;
} catch (final NamingException e) {
s_logger.debug("NamingException: while doing an LDAP bind for user "+" "+username, e);
s_logger.info("Failed to authenticate user: " + username + ". incorrect password.");
return false;
}
@ -109,7 +111,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
context.close();
}
} catch (final NamingException e) {
s_logger.warn(e.getMessage());
s_logger.warn(e.getMessage(),e);
}
}
@ -183,6 +185,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
context = _ldapContextFactory.createBindContext();
return _ldapUserManager.getUsers(context);
} catch (final NamingException e) {
s_logger.debug("ldap NamingException: ",e);
throw new NoLdapUserMatchingQueryException("*");
} finally {
closeContext(context);
@ -196,6 +199,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
context = _ldapContextFactory.createBindContext();
return _ldapUserManager.getUsersInGroup(groupName, context);
} catch (final NamingException e) {
s_logger.debug("ldap NamingException: ",e);
throw new NoLdapUserMatchingQueryException("groupName=" + groupName);
} finally {
closeContext(context);
@ -223,6 +227,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator {
final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username);
return _ldapUserManager.getUsers("*" + escapedUsername + "*", context);
} catch (final NamingException e) {
s_logger.debug("ldap NamingException: ",e);
throw new NoLdapUserMatchingQueryException(username);
} finally {
closeContext(context);