added logging

This commit is contained in:
jomu
2016-09-28 08:53:49 +00:00
parent 6be7883713
commit 3afa1b9837

View File

@ -8,6 +8,8 @@ import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm; import org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm;
import org.apache.shiro.realm.ldap.LdapContextFactory; import org.apache.shiro.realm.ldap.LdapContextFactory;
import org.apache.shiro.realm.ldap.LdapUtils; import org.apache.shiro.realm.ldap.LdapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -15,10 +17,12 @@ import org.apache.shiro.realm.ldap.LdapUtils;
*/ */
public class UserNameActiveDirectoryRealm extends ActiveDirectoryRealm { public class UserNameActiveDirectoryRealm extends ActiveDirectoryRealm {
private static final Logger LOGGER = LoggerFactory.getLogger(UserNameActiveDirectoryRealm.class);
@Override @Override
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException { protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token; UsernamePasswordToken upToken = (UsernamePasswordToken) token;
// Binds using the username and password provided by the user.
LdapContext ctx = null; LdapContext ctx = null;
String userName = upToken.getUsername(); String userName = upToken.getUsername();
try { try {
@ -28,13 +32,17 @@ public class UserNameActiveDirectoryRealm extends ActiveDirectoryRealm {
} }
} }
// use system context (system user / password) to connect to server // Binds using the username and password provided by the user.
// ctx = ldapContextFactory.getSystemLdapContext(); LOGGER.debug("start creating context");
ctx = ldapContextFactory.getLdapContext(userName, upToken.getCredentials()); ctx = ldapContextFactory.getLdapContext(userName, upToken.getCredentials());
LOGGER.debug("context created");
} finally { } finally {
LdapUtils.closeContext(ctx); LdapUtils.closeContext(ctx);
} }
return buildAuthenticationInfo(userName, upToken.getPassword()); LOGGER.debug("building authentication info");
AuthenticationInfo authInfo = buildAuthenticationInfo(userName, upToken.getPassword());
LOGGER.debug("authentifaction info created");
return authInfo;
} }
} }