if (subject instanceof DelegatingSubject) { DelegatingSubjectdelegating= (DelegatingSubject) subject; //we have to do this in case there are assumed identities - we don't want to lose the 'real' principals: principals = delegating.principals; host = delegating.host; } else { principals = subject.getPrincipals(); }
if (principals == null || principals.isEmpty()) { Stringmsg="Principals returned from securityManager.login( token ) returned a null or " + "empty value. This value must be non null and populated with one or more elements."; thrownewIllegalStateException(msg); } this.principals = principals; this.authenticated = true; if (token instanceof HostAuthenticationToken) { host = ((HostAuthenticationToken) token).getHost(); } if (host != null) { this.host = host; } Sessionsession= subject.getSession(false); if (session != null) { this.session = decorate(session); } else { this.session = null; } }
if (token == null) { thrownewIllegalArgumentException("Method argument (authentication token) cannot be null."); }
log.trace("Authentication attempt received for token [{}]", token);
AuthenticationInfo info; try { info = doAuthenticate(token); if (info == null) { Stringmsg="No account information found for authentication token [" + token + "] by this " + "Authenticator instance. Please check that it is configured correctly."; thrownewAuthenticationException(msg); } } catch (Throwable t) { AuthenticationExceptionae=null; if (t instanceof AuthenticationException) { ae = (AuthenticationException) t; } if (ae == null) { //Exception thrown was not an expected AuthenticationException. Therefore it is probably a little more //severe or unexpected. So, wrap in an AuthenticationException, log to warn, and propagate: Stringmsg="Authentication failed for token submission [" + token + "]. Possible unexpected " + "error? (Typical or expected login exceptions should extend from AuthenticationException)."; ae = newAuthenticationException(msg, t); if (log.isWarnEnabled()) log.warn(msg, t); } try { notifyFailure(token, ae); } catch (Throwable t2) { if (log.isWarnEnabled()) { Stringmsg="Unable to send notification for failed authentication attempt - listener error?. " + "Please check your AuthenticationListener implementation(s). Logging sending exception " + "and propagating original AuthenticationException instead..."; log.warn(msg, t2); } }
throw ae; }
log.debug("Authentication successful for token [{}]. Returned account [{}]", token, info);