[jboss-cvs] JBossAS SVN: r70251 - in projects/security/security-jboss-sx/trunk/jbosssx/src: tests/org/jboss/test/securityassociation and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 29 02:08:34 EST 2008
Author: anil.saldhana at jboss.com
Date: 2008-02-29 02:08:34 -0500 (Fri, 29 Feb 2008)
New Revision: 70251
Modified:
projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/SecurityAssociation.java
projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
Log:
SecurityAssociation Updates to take care of client side static view
Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/SecurityAssociation.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/SecurityAssociation.java 2008-02-29 07:07:52 UTC (rev 70250)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/SecurityAssociation.java 2008-02-29 07:08:34 UTC (rev 70251)
@@ -184,10 +184,9 @@
Principal thePrincipal = principal;
+ if(!server)
+ return principal;
- if (server)
- thePrincipal = (Principal) threadPrincipal.get();
-
if( trace )
log.trace("getPrincipal, principal="+thePrincipal);
@@ -257,10 +256,8 @@
if (sm != null)
sm.checkPermission(getPrincipalInfoPermission);
- /*if (server)
- return threadCredential.get();
- else
- return credential;*/
+ if(!server)
+ return credential;
SecurityContext sc = SecurityContextAssociation.getSecurityContext();
if(sc != null)
@@ -324,32 +321,15 @@
if (trace)
log.trace("setPrincipal, p=" + principal + ", server=" + server);
- /*if (server)
+
+ if(!server)
{
- threadPrincipal.set(principal);
- }
- else
SecurityAssociation.principal = principal;
- // Integrate with the new SubjectContext
- SubjectContext sc = threadSubjectStacks.peek();
- if( sc == null )
- {
- // There is no active security context
- sc = new SubjectContext();
- threadSubjectStacks.push(sc);
+ return;
}
- else if( (sc.getFlags() & SubjectContext.PRINCIPAL_WAS_SET) != 0 )
- {
- // The current security context has its principal set
- sc = new SubjectContext();
- threadSubjectStacks.push(sc);
- }
- sc.setPrincipal(principal);
- if (trace)
- log.trace("setPrincipal, sc="+sc);*/
SecurityContext securityContext = SecurityContextAssociation.getSecurityContext();
//Clients code that may have set directly (Legacy)
- if(!server && securityContext == null)
+ if(securityContext == null)
{
try
{
@@ -360,15 +340,12 @@
throw new RuntimeException(e);
}
SecurityContextAssociation.setSecurityContext(securityContext);
- }
- if(securityContext != null)
- {
- if(trace)
- log.warn("Using deprecated API. Move to a security context based approach");
- Object cred = securityContext.getUtil().getCredential();
- Subject subj = securityContext.getUtil().getSubject();
- securityContext.getUtil().createSubjectInfo(principal,cred, subj);
- }
+ }
+ if(trace)
+ log.warn("Using deprecated API. Move to a security context based approach");
+ Object cred = securityContext.getUtil().getCredential();
+ Subject subj = securityContext.getUtil().getSubject();
+ securityContext.getUtil().createSubjectInfo(principal,cred, subj);
}
/**
@@ -388,30 +365,15 @@
if (sm != null)
sm.checkPermission(setPrincipalInfoPermission);
- /*if (server)
- threadCredential.set(credential);
- else
- SecurityAssociation.credential = credential;
- // Integrate with the new SubjectContext
- SubjectContext sc = threadSubjectStacks.peek();
- if( sc == null )
+ if(!server)
{
- // There is no active security context
- sc = new SubjectContext();
- threadSubjectStacks.push(sc);
+ SecurityAssociation.credential = credential;
+ return;
}
- else if( (sc.getFlags() & SubjectContext.CREDENTIAL_WAS_SET) != 0 )
- {
- // The current security context has its principal set
- sc = new SubjectContext();
- threadSubjectStacks.push(sc);
- }
- sc.setCredential(credential);
- if (trace)
- log.trace("setCredential, sc="+sc);*/
+
SecurityContext securityContext = SecurityContextAssociation.getSecurityContext();
//Clients code that may have set directly (Legacy)
- if(!server && securityContext == null)
+ if(securityContext == null)
{
try
{
@@ -423,15 +385,12 @@
}
SecurityContextAssociation.setSecurityContext(securityContext);
}
-
- if(securityContext != null)
- {
- if(trace)
- log.warn("Using deprecated API. Move to a security context based approach");
- Principal principal = securityContext.getUtil().getUserPrincipal();
- Subject subj = securityContext.getUtil().getSubject();
- securityContext.getUtil().createSubjectInfo(principal,credential, subj);
- }
+
+ if(trace)
+ log.warn("Using deprecated API. Move to a security context based approach");
+ Principal principal = securityContext.getUtil().getUserPrincipal();
+ Subject subj = securityContext.getUtil().getSubject();
+ securityContext.getUtil().createSubjectInfo(principal,credential, subj);
}
/**
Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java 2008-02-29 07:07:52 UTC (rev 70250)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java 2008-02-29 07:08:34 UTC (rev 70251)
@@ -50,7 +50,7 @@
public void testClientSideSecurityAssociation()
{
assertFalse("Client Side", SecurityAssociation.isServer());
- checkSA();
+ checkSA(false);
}
public void testServerSideSecurityAssociation()
@@ -58,7 +58,7 @@
assertFalse("Client Side", SecurityAssociation.isServer());
SecurityAssociation.setServer();
assertTrue("Server Side", SecurityAssociation.isServer());
- checkSA();
+ checkSA(true);
}
@SuppressWarnings("deprecation")
@@ -151,15 +151,27 @@
assertNull("RAI is null", sc.getOutgoingRunAs());
}
- private void checkSA()
+ private void checkSA(boolean threaded)
{
SecurityAssociation.setPrincipal(new SimplePrincipal("Anil"));
SecurityAssociation.setCredential("p".toCharArray());
- //Check the security context
- SecurityContext sc = getSecurityContext();
- assertEquals("Principal=Anil","Anil", sc.getUtil().getUserPrincipal().getName());
- Object cred = sc.getUtil().getCredential();
+ Principal p = null;
+ Object cred = null;
+
+ if(threaded)
+ {
+ //Check the security context
+ SecurityContext sc = getSecurityContext();
+ p = sc.getUtil().getUserPrincipal();
+ cred = sc.getUtil().getCredential();
+ }
+ else
+ {
+ p = SecurityAssociation.getPrincipal();
+ cred = SecurityAssociation.getCredential();
+ }
+ assertEquals("Principal=Anil","Anil", p.getName());
assertEquals("Cred=p","p", new String((char[])cred));
}
-}
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list