// Establish a LoginContext to use for authentication
try {
if ((principalName != null) && (!principalName.equals(""))) {
LoginContext loginContext = null;
if (appName == null)
appName = "Tomcat";
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.beginLogin", principalName, appName));
// What if the LoginModule is in the container class loader ?
ClassLoader ocl = null;
if (isUseContextClassLoader()) {
ocl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
}
try {
loginContext = ContextManager.login(appName, callbackHandler);
} catch (AccountExpiredException e) {
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.accountExpired", principalName));
return (null);
} catch (CredentialExpiredException e) {
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.credentialExpired", principalName));
return (null);
} catch (FailedLoginException e) {
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.failedLogin", principalName));
return (null);
} catch (LoginException e) {
log.warn(sm.getString("jaasRealm.loginException", principalName), e);
return (null);
} catch (Throwable e) {
log.error(sm.getString("jaasRealm.unexpectedError"), e);
return (null);
} finally {
if (isUseContextClassLoader()) {
Thread.currentThread().setContextClassLoader(ocl);
}
}
if (log.isDebugEnabled())
log.debug("Login context created " + principalName);
// Negotiate a login via this LoginContext
Subject subject = loginContext.getSubject();
ContextManager.setCallers(subject, subject);
if (log.isDebugEnabled())
log.debug(sm.getString("jaasRealm.loginContextCreated", principalName));