public void testCallerPrincipal()
{
//With no security context
assertNull("Caller Principal is null", SecurityAssociation.getCallerPrincipal());
//Create a security context
SecurityContext sc = new JBossSecurityContext("TEST");
Principal p = new SimplePrincipal("anil");
sc.getUtil().createSubjectInfo(p, "pass", null);
SecurityContextAssociation.setSecurityContext(sc);
assertEquals("CallerPrincipal=anil",p,SecurityAssociation.getCallerPrincipal());
//Clear the SecurityContext
SecurityContextAssociation.clearSecurityContext();
assertNull("Caller Principal is null", SecurityAssociation.getCallerPrincipal());
//Create a security context with runas
sc = new JBossSecurityContext("TEST");
@SuppressWarnings("unchecked")
RunAs ras = new RunAs()
{
public <T> T getIdentity()
{
return (T) getName();
}
public <T> T getProof()
{
return null;
}
public String getName()
{
return "anil";
}};
sc.setIncomingRunAs(ras);
SecurityContextAssociation.setSecurityContext(sc);
assertEquals("CallerPrincipal=anil",p,SecurityAssociation.getCallerPrincipal());
}