diff --git a/security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java b/security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java
index <HASH>..<HASH> 100644
--- a/security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java
+++ b/security/api/src/main/java/org/jboss/as/security/api/ConnectionSecurityContext.java
@@ -72,7 +72,7 @@ public class ConnectionSecurityContext {
             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()));
+                principals.add(realm == null ? new RealmUser(principal.getName()) : new RealmUser(realm, principal.getName()));
                 for (String role : localIdentity.getRoles()) {
                     principals.add(new RealmGroup(role));
                     principals.add(new RealmRole(role));
WFLY-<I>: prevent IllegalStateException while creation of RealmUser without realm