public void logout(Subject subject) {

        if (subject == null) {
            throw new IllegalArgumentException("Subject method argument cannot be null.");
        }

        beforeLogout(subject);

        PrincipalCollection principals = subject.getPrincipals();
        if (principals != null && !principals.isEmpty()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Logging out subject with primary principal {}", principals.getPrimaryPrincipal());
            }
            Authenticator authc = getAuthenticator();
            if (authc instanceof LogoutAware) {
                ((LogoutAware) authc).onLogout(principals);
            }
        }

        try {
            delete(subject);
        } catch (Exception e) {
            if (LOGGER.isDebugEnabled()) {
                String msg = "Unable to cleanly unbind Subject.  Ignoring (logging out).";
                LOGGER.debug(msg, e);
            }
        } finally {
            try {
                stopSession(subject);
            } catch (Exception e) {
                if (LOGGER.isDebugEnabled()) {
                    String msg = "Unable to cleanly stop Session for Subject [" + subject.getPrincipal() + "] "
                            + "Ignoring (logging out).";
                    LOGGER.debug(msg, e);
                }
            }
        }
    }
Attempts to resolve an identity (a {@link PrincipalCollection}) for the context using heuristics.  This
implementation functions as follows:
<ol>
<li>Check the context to see if it can already {@link SubjectContext#resolvePrincipals resolve an identity}.  If
so, this method does nothing and returns the method argument unaltered.</li>
<li>Check for a RememberMe identity by calling {@link #getRememberedIdentity}.  If that method returns a
non-null value, place the remembered {@link PrincipalCollection} in the context.</li>
</ol>

@param context the subject context data that may provide (directly or indirectly through one of its values) a
               {@link PrincipalCollection} identity.
@return The Subject context to use to pass to a {@link SubjectFactory} for subject creation.
@since 1.0
core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java