diff --git a/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java b/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java
index de755c4..68262f0 100644
--- a/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java
+++ b/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java
@@ -40,7 +40,8 @@ public class CredentialIdentityFactory extends IdentityFactory
     * An empty identity
     */
    @SuppressWarnings("unchecked")
-   public static final CredentialIdentity NULL_IDENTITY = CredentialIdentityFactory.createIdentity( null, null );
+   public static final CredentialIdentity NULL_IDENTITY = createIdentity(null,null,null);
+       
    
    private static CredentialIdentityFactory _instance = null;
    
@@ -67,47 +68,102 @@ public class CredentialIdentityFactory extends IdentityFactory
    public static CredentialIdentity<Object> createIdentity(final Principal principal, 
          final Object cred, final Role roles)
    {
-      return new CredentialIdentity<Object>()
+      return new InnerCredentialIdentity(principal,cred, roles);
+      
+   }
+      
+   final static class InnerCredentialIdentity implements CredentialIdentity<Object> {
+
+      private static final long serialVersionUID = 2L;
+      private final Principal principal;
+      private final Object cred;
+      private final Role roles;
+
+      public InnerCredentialIdentity(Principal principal, Object cred, Role roles) {
+         super();
+         this.principal = principal;
+         this.cred = cred;
+         this.roles = roles;
+        }
+
+      public Object getCredential()
       {
-         private static final long serialVersionUID = 1L;
+         return cred;
+      }
+
+      public void setCredential(Object credential)
+      {   
+      }
 
-         public Object getCredential()
-         {
-            return cred;
-         }
+      public Group asGroup()
+      { 
+         return null;
+      }
+          
+      public Principal asPrincipal()
+      {
+         return principal;
+      }
 
-         public void setCredential(Object credential)
-         {   
-         }
+      public String getName()
+      { 
+          if(principal!=null){
+             return principal.getName();
+          }else{
+             return null;
+          }
+      }
 
-         public Group asGroup()
-         { 
-            return null;
-         }
-         
-         public Principal asPrincipal()
-         {
-            return principal;
-         }
+      public Role getRole()
+      {
+         return roles;
+      }
 
-         public String getName()
-         { 
-            return principal.getName();
-         }
+      @Override
+      public String toString()
+      {
+         StringBuilder builder = new StringBuilder();
+         builder.append("CredentialIdentity[principal=").append(principal);
+         builder.append(";roles=").append(roles).append("]");
+         return builder.toString();
+      } 
 
-         public Role getRole()
-         {
-            return roles;
-         }
+      @Override
+      public int hashCode() {
+         final int prime = 31;
+         int result = 1;
+         result = prime * result + ((cred == null) ? 0 : cred.hashCode());
+         result = prime * result + ((principal == null) ? 0 : principal.hashCode());
+         result = prime * result + ((roles == null) ? 0 : roles.hashCode());
+         return result;
+      }
 
-         @Override
-         public String toString()
-         {
-            StringBuilder builder = new StringBuilder();
-            builder.append("CredentialIdentity[principal=").append(principal);
-            builder.append(";roles=").append(roles).append("]");
-            return builder.toString();
-         } 
-      }; 
-   } 
-}
\ No newline at end of file
+      @Override
+      public boolean equals(Object obj) {
+         if (this == obj)
+            return true;
+         if (obj == null)
+            return false;
+         if (getClass() != obj.getClass())
+            return false;
+         InnerCredentialIdentity other = (InnerCredentialIdentity) obj;
+         if (cred == null) {
+            if (other.cred != null)
+                return false;
+         } else if (!cred.equals(other.cred))
+            return false;
+         if (principal == null) {
+            if (other.principal != null)
+                return false;
+         } else if (!principal.equals(other.principal))
+            return false;
+         if (roles == null) {
+            if (other.roles != null)
+                return false;
+            } else if (!roles.equals(other.roles))
+                return false;
+            return true;
+      }
+   }
+} 
+   
