security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java
public static ContextStateCache pushIdentity(final Principal principal, final Object credential) throws Exception {
        SecurityContext current = SecurityContextAssociation.getSecurityContext();

        SecurityContext nextContext = SecurityContextFactory.createSecurityContext(principal, credential, new Subject(), "USER_DELEGATION");
        SecurityContextAssociation.setSecurityContext(nextContext);

        RemoteConnection con = RemotingContext.getRemoteConnection();
        RemotingContext.clear();

        return new ContextStateCache(con, current);
    }
public static ContextStateCache pushIdentity(final Principal principal, final Object credential) throws Exception {
        SecurityContext current = SecurityContextAssociation.getSecurityContext();

        SecurityContext nextContext = SecurityContextFactory.createSecurityContext(principal, credential, new Subject(), "USER_DELEGATION");
        SecurityContextAssociation.setSecurityContext(nextContext);

        RemoteConnection con = RemotingContext.getRemoteConnection();
        RemotingContext.clear();

        return new ContextStateCache(con, current);
    }
Push a new {@link Principal} and Credential pair.

This method is to be called before an EJB invocation is passed through it's security interceptor, at that point the
Principal and Credential pair can be verified.

Note: This method should be called from within a {@link PrivilegedAction}.

@param principal - The alternative {@link Principal} to use in verification before the next EJB is called.
@param credential - The credential to verify with the {@linl Principal}
@return A {@link ContextStateCache} that can later be used to pop the identity pushed here and restore internal state to it's previous values.
@throws Exception If there is a problem associating the new {@link Principal} and Credential pair.