Example usage for org.springframework.security.authentication.jaas JaasAuthenticationToken getPrincipal

List of usage examples for org.springframework.security.authentication.jaas JaasAuthenticationToken getPrincipal

Introduction

In this page you can find the example usage for org.springframework.security.authentication.jaas JaasAuthenticationToken getPrincipal.

Prototype

public Object getPrincipal() 

Source Link

Usage

From source file:org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider.java

/**
 * Handles the logout by getting the security contexts for the destroyed session and
 * invoking {@code LoginContext.logout()} for any which contain a
 * {@code JaasAuthenticationToken}./*  w w  w  . j  av a  2  s  .  c  om*/
 *
 *
 * @param event the session event which contains the current session
 */
protected void handleLogout(SessionDestroyedEvent event) {
    List<SecurityContext> contexts = event.getSecurityContexts();

    if (contexts.isEmpty()) {
        this.log.debug("The destroyed session has no SecurityContexts");

        return;
    }

    for (SecurityContext context : contexts) {
        Authentication auth = context.getAuthentication();

        if ((auth != null) && (auth instanceof JaasAuthenticationToken)) {
            JaasAuthenticationToken token = (JaasAuthenticationToken) auth;

            try {
                LoginContext loginContext = token.getLoginContext();
                boolean debug = this.log.isDebugEnabled();
                if (loginContext != null) {
                    if (debug) {
                        this.log.debug("Logging principal: [" + token.getPrincipal() + "] out of LoginContext");
                    }
                    loginContext.logout();
                } else if (debug) {
                    this.log.debug("Cannot logout principal: [" + token.getPrincipal() + "] from LoginContext. "
                            + "The LoginContext is unavailable");
                }
            } catch (LoginException e) {
                this.log.warn("Error error logging out of LoginContext", e);
            }
        }
    }
}