[jboss-cvs] JBossAS SVN: r69469 - projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 29 16:15:16 EST 2008
Author: sguilhen at redhat.com
Date: 2008-01-29 16:15:16 -0500 (Tue, 29 Jan 2008)
New Revision: 69469
Modified:
projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java
projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/SimpleIdentity.java
Log:
Added equals and hashCode to SimpleIdentity and added a new factory method to IdentityFactory that takes the identity class as an argument.
Modified: projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java
===================================================================
--- projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java 2008-01-29 21:04:54 UTC (rev 69468)
+++ projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/IdentityFactory.java 2008-01-29 21:15:16 UTC (rev 69469)
@@ -41,27 +41,34 @@
public static final String IDENTITY_CLASS = "org.jboss.security.identity.plugins.SimpleIdentity";
public static final String PRINCIPAL_CLASS = "org.jboss.security.SimplePrincipal";
-
+
public static final String GROUP_CLASS = "org.jboss.security.SimpleGroup";
public static Principal createPrincipal(String name) throws Exception
{
- Class<?> clazz = SecurityActions.getClass(PRINCIPAL_CLASS);
- Constructor<?> ctr = clazz.getConstructor(new Class[]{String.class});
- return (Principal) ctr.newInstance(new Object[]{name});
+ return (Principal) loadClass(PRINCIPAL_CLASS, name);
}
-
+
public static Group createGroup(String name) throws Exception
{
- Class<?> clazz = SecurityActions.getClass(GROUP_CLASS);
- Constructor<?> ctr = clazz.getConstructor(new Class[]{String.class});
- return (Group) ctr.newInstance(new Object[]{name});
+ return (Group) loadClass(GROUP_CLASS, name);
}
public static Identity createIdentity(String name) throws Exception
{
- Class<?> clazz = SecurityActions.getClass(IDENTITY_CLASS);
- Constructor<?> ctr = clazz.getConstructor(new Class[]{String.class});
- return (Identity) ctr.newInstance(new Object[]{name});
+ return (Identity) loadClass(IDENTITY_CLASS, name);
}
+
+ public static Identity createIdentity(String identityClass, String name) throws Exception
+ {
+ return (Identity) loadClass(identityClass, name);
+ }
+
+ private static Object loadClass(String className, String ctorArg) throws Exception
+ {
+ Class<?> clazz = SecurityActions.getClass(className);
+ Constructor<?> ctr = clazz.getConstructor(new Class[]{String.class});
+ return ctr.newInstance(new Object[]{ctorArg});
+
+ }
}
Modified: projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/SimpleIdentity.java
===================================================================
--- projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/SimpleIdentity.java 2008-01-29 21:04:54 UTC (rev 69468)
+++ projects/security/security-jboss-sx/trunk/identity/src/main/org/jboss/security/identity/plugins/SimpleIdentity.java 2008-01-29 21:15:16 UTC (rev 69469)
@@ -39,50 +39,52 @@
public class SimpleIdentity implements Identity, Serializable
{
private static final long serialVersionUID = 1L;
- private String name;
+
+ private final String name;
+
private Role role;
public SimpleIdentity(String name)
{
this.name = name;
}
-
+
public SimpleIdentity(String name, String roleName)
{
this.name = name;
this.role = new SimpleRole(roleName);
}
-
+
public SimpleIdentity(String name, Role role)
{
this.name = name;
this.role = role;
}
-
+
public Group asGroup()
{
try
{
Group gp = IdentityFactory.createGroup("Roles");
gp.addMember(IdentityFactory.createPrincipal(role.getRoleName()));
- return gp;
+ return gp;
}
- catch(Exception e)
+ catch (Exception e)
{
throw new RuntimeException(e);
}
}
public Principal asPrincipal()
- {
+ {
try
{
- return IdentityFactory.createPrincipal(name);
+ return IdentityFactory.createPrincipal(name);
}
- catch(Exception e)
+ catch (Exception e)
{
throw new RuntimeException(e);
- }
+ }
}
public String getName()
@@ -93,5 +95,24 @@
public Role getRole()
{
return this.role;
- }
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof SimpleIdentity)
+ {
+ SimpleIdentity other = (SimpleIdentity) obj;
+ if (this.name != null)
+ return this.name.equals(other.name);
+ return (other.name == null);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return this.name.hashCode();
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list