Method method = ((MethodInvocation)invocation).getActualMethod();
Class[] classes = new Class[]{DenyAll.class, PermitAll.class, RolesAllowed.class};
Object annotation = container.resolveAnnotation(method, classes);
int classIndex = 0;
while (annotation == null && classIndex < 3)
{
annotation = container.resolveAnnotation(classes[classIndex++]);
}
HashSet set = new HashSet();
if (annotation != null)
{
if (annotation instanceof DenyAll)
{
set.add(NobodyPrincipal.NOBODY_PRINCIPAL);
}
else if (annotation instanceof PermitAll)
{
set.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
}
else if (annotation instanceof RolesAllowed)
{
RolesAllowed permissions = (RolesAllowed) annotation;
for (int i = 0; i < permissions.value().length; i++)
{
set.add(new SimplePrincipal(permissions.value()[i]));
}
}
else
set.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
}
else
set.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
return set;