security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java
public static Collection<Principal> getConnectionPrincipals() {
        RemoteConnection con = RemotingContext.getRemoteConnection();

        if (con != null) {
            Collection<Principal> principals = new HashSet<>();
            SecurityIdentity localIdentity = con.getSecurityIdentity();
            if (localIdentity != null) {
                final Principal principal = localIdentity.getPrincipal();
                final String realm = principal instanceof RealmPrincipal ? ((RealmPrincipal) principal).getRealm() : null;
                principals.add(new RealmUser(realm, principal.getName()));
                for (String role : localIdentity.getRoles()) {
                    principals.add(new RealmGroup(role));
                    principals.add(new RealmRole(role));
                }
                return principals;
            } else {
                return Collections.emptySet();
            }
        }

        return null;
    }
public static Collection<Principal> getConnectionPrincipals() {
        RemoteConnection con = RemotingContext.getRemoteConnection();

        if (con != null) {
            Collection<Principal> principals = new HashSet<>();
            SecurityIdentity localIdentity = con.getSecurityIdentity();
            if (localIdentity != null) {
                final Principal principal = localIdentity.getPrincipal();
                final String realm = principal instanceof RealmPrincipal ? ((RealmPrincipal) principal).getRealm() : null;
                principals.add(new RealmUser(realm, principal.getName()));
                for (String role : localIdentity.getRoles()) {
                    principals.add(new RealmGroup(role));
                    principals.add(new RealmRole(role));
                }
                return principals;
            } else {
                return Collections.emptySet();
            }
        }

        return null;
    }
Obtain a {@link Collection} containing the {@link Principal} instances for the user associated with the connection.

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

@return The Collection of Principals for the user authenticated with the connection. An empty Collection will be returned
of no user is associated with the connection, {@code null} will be returned if no connection is associated with
the {@link Thread}