@Override
    public Principal getUserPrincipal() {

        Principal result;

        Subject subject = getSubject();
        PrincipalCollection shiroPrincipals = subject.getPrincipals();
        if (shiroPrincipals != null) {
            result = shiroPrincipals.oneByType(Principal.class);

            if (result == null) {
                result = new ObjectPrincipal(shiroPrincipals.getPrimaryPrincipal());
            }
        } else {
            result = originalSecurityContext.getUserPrincipal();
        }

        return result;
    }
A Shiro based {@link SecurityContext} that exposes the current Shiro {@link Subject} as a {@link Principal}.
The {@link #isUserInRole(String)} method returns the result of {@link Subject#hasRole(String)}.

@since 1.4
support/jaxrs/src/main/java/org/apache/shiro/web/jaxrs/ShiroSecurityContext.java