MethodInvocation mi = (MethodInvocation)invocation;
SecurityDomain domain = (SecurityDomain)container.resolveAnnotation(SecurityDomain.class);
if (domain != null && domain.unauthenticatedPrincipal() != null && domain.unauthenticatedPrincipal().length() != 0)
{
Principal principal = (Principal)invocation.getMetaData("security", "principal");
if (principal == null)
principal = SecurityAssociation.getPrincipal();
if (principal == null)
{
invocation.getMetaData().addMetaData("security", "principal", new SimplePrincipal(domain.unauthenticatedPrincipal()));
Object oldDomain = SecurityContext.getCurrentDomain().get();
try
{
SecurityContext.getCurrentDomain().set(authenticationManager);
return invocation.invokeNext();
}
finally
{
SecurityContext.getCurrentDomain().set(oldDomain);
}
}
}
try
{
//Set a map of principal-roles that may be configured at deployment level
if(container.getAssemblyDescriptor() != null)
{
SecurityRolesAssociation.setSecurityRoles(container.getAssemblyDescriptor().getPrincipalVersusRolesMap());
}
return super.invoke(invocation);
}
finally
{
SecurityRolesAssociation.setSecurityRoles(null);
}