private PrincipalCollection popIdentity() {
        PrincipalCollection popped = null;

        List<PrincipalCollection> stack = getRunAsPrincipalsStack();
        if (!CollectionUtils.isEmpty(stack)) {
            popped = stack.remove(0);
            Session session;
            if (!CollectionUtils.isEmpty(stack)) {
                //persist the changed stack to the session
                session = getSession();
                session.setAttribute(RUN_AS_PRINCIPALS_SESSION_KEY, stack);
            } else {
                //stack is empty, remove it from the session:
                clearRunAsIdentities();
            }
        }

        return popped;
    }
Returns {@code true} if this Subject is allowed to create sessions, {@code false} otherwise.

@return {@code true} if this Subject is allowed to create sessions, {@code false} otherwise.
@since 1.2
core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java