[jboss-cvs] Picketbox SVN: r93 - in trunk: security-spi/identity/src/main/java/org/jboss/security/identity/extensions and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 12 21:23:49 EDT 2010
Author: anil.saldhana at jboss.com
Date: 2010-05-12 21:23:48 -0400 (Wed, 12 May 2010)
New Revision: 93
Modified:
trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/authentication/jaas/JASPICallbackHandlerUnitTestCase.java
trunk/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java
trunk/security-spi/spi/src/main/java/org/jboss/security/SecurityConstants.java
trunk/security-spi/spi/src/main/java/org/jboss/security/SubjectInfo.java
Log:
SECURITY-510: addition of identity should always replace the null identity
Modified: trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/authentication/jaas/JASPICallbackHandlerUnitTestCase.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/authentication/jaas/JASPICallbackHandlerUnitTestCase.java 2010-05-13 00:22:14 UTC (rev 92)
+++ trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/authentication/jaas/JASPICallbackHandlerUnitTestCase.java 2010-05-13 01:23:48 UTC (rev 93)
@@ -108,7 +108,8 @@
assertEquals( subject, currentSC.getUtil().getSubject() );
Set<Identity> identities = currentSC.getUtil().getIdentities( CredentialIdentity.class );
- assertEquals( 2, identities.size() );
+ assertEquals( 1, identities.size() );
+ assertEquals( principal , currentSC.getUtil().getUserPrincipal() );
}
@Test
Modified: trunk/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java
===================================================================
--- trunk/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java 2010-05-13 00:22:14 UTC (rev 92)
+++ trunk/security-spi/identity/src/main/java/org/jboss/security/identity/extensions/CredentialIdentityFactory.java 2010-05-13 01:23:48 UTC (rev 93)
@@ -27,6 +27,7 @@
import org.jboss.security.identity.IdentityFactory;
import org.jboss.security.identity.Role;
+
/**
* Factory to create Credential Identity
* @author Anil.Saldhana at redhat.com
@@ -34,7 +35,13 @@
* @version $Revision$
*/
public class CredentialIdentityFactory extends IdentityFactory
-{
+{
+ /**
+ * An empty identity
+ */
+ @SuppressWarnings("unchecked")
+ public static final CredentialIdentity NULL_IDENTITY = CredentialIdentityFactory.createIdentity( null, null );
+
private static CredentialIdentityFactory _instance = null;
protected CredentialIdentityFactory()
@@ -48,9 +55,12 @@
return _instance;
}
+ @SuppressWarnings("unchecked")
public static CredentialIdentity<Object> createIdentity(final Principal principal,
final Object cred)
{
+ if( principal == null && cred == null )
+ return NULL_IDENTITY;
return createIdentity(principal,cred, null);
}
Modified: trunk/security-spi/spi/src/main/java/org/jboss/security/SecurityConstants.java
===================================================================
--- trunk/security-spi/spi/src/main/java/org/jboss/security/SecurityConstants.java 2010-05-13 00:22:14 UTC (rev 92)
+++ trunk/security-spi/spi/src/main/java/org/jboss/security/SecurityConstants.java 2010-05-13 01:23:48 UTC (rev 93)
@@ -21,6 +21,7 @@
*/
package org.jboss.security;
+
//$Id: SecurityConstants.java 58038 2006-11-03 04:39:59Z anil.saldhana at jboss.com $
/**
@@ -127,4 +128,4 @@
* Identity Trust Constants
*/
String JAVAEE = "JavaEE";
-}
+}
\ No newline at end of file
Modified: trunk/security-spi/spi/src/main/java/org/jboss/security/SubjectInfo.java
===================================================================
--- trunk/security-spi/spi/src/main/java/org/jboss/security/SubjectInfo.java 2010-05-13 00:22:14 UTC (rev 92)
+++ trunk/security-spi/spi/src/main/java/org/jboss/security/SubjectInfo.java 2010-05-13 01:23:48 UTC (rev 93)
@@ -29,7 +29,8 @@
import javax.security.auth.Subject;
import org.jboss.security.identity.Identity;
-import org.jboss.security.identity.RoleGroup;
+import org.jboss.security.identity.IdentityFactory;
+import org.jboss.security.identity.RoleGroup;
import org.jboss.security.identity.extensions.CredentialIdentityFactory;
@@ -52,7 +53,7 @@
SubjectInfo(Principal principal, Object credential,Subject subject)
{
- this.addIdentity(CredentialIdentityFactory.createIdentity(principal, credential));
+ this.addIdentity( IdentityFactory.getIdentity(principal, credential ) );
this.authenticatedSubject = subject;
}
@@ -91,17 +92,31 @@
{
if(identities == null)
identities = new HashSet<Identity>();
+ if( id != null )
+ {
+ Identity identity = getIdentity( id.getClass() );
+ if( identity == CredentialIdentityFactory.NULL_IDENTITY )
+ removeIdentity( identity );
+ }
+
identities.add(id);
}
@SuppressWarnings("unchecked")
public <T> T getIdentity(Class<T> clazz)
{
+ if( clazz == null )
+ throw new IllegalArgumentException( "clazz is null" );
if(this.identities != null)
{
for(Identity id:identities)
{
- if(clazz.isAssignableFrom(id.getClass()))
+ if( id == null )
+ break;
+ Class<?> idClass = id.getClass();
+ if( idClass == null )
+ throw new RuntimeException( id + " has null class " );
+ if(clazz.isAssignableFrom( idClass ))
return (T) id;
}
}
@@ -119,6 +134,15 @@
identities = new HashSet<Identity>();
identities.addAll(ids);
}
+
+ /**
+ * Remove an identity
+ * @param id
+ */
+ public void removeIdentity( Identity id )
+ {
+ identities.remove( id );
+ }
@Override
public String toString()
More information about the jboss-cvs-commits
mailing list