private static void addPermissions(EJBContainer container, PolicyConfiguration pc)
{
SecurityDomain sd = (SecurityDomain) container.resolveAnnotation(SecurityDomain.class);
PermitAll beanUnchecked = (PermitAll) container.resolveAnnotation(PermitAll.class);
RolesAllowed beanPermissions = (RolesAllowed) container.resolveAnnotation(RolesAllowed.class);
DeclareRoles beanDeclareRolesPerms = (DeclareRoles)container.resolveAnnotation(DeclareRoles.class);
if (beanUnchecked != null && beanPermissions != null)
{
throw new RuntimeException("Cannot annotate a bean with both @Unchecked and @MethodPermissions");
}
String ejbName = container.getEjbName();
//Add the security role references
if(beanDeclareRolesPerms != null)
{
String[] rolerefs = beanDeclareRolesPerms.value();
int len = rolerefs != null ? rolerefs.length : 0;
for(int i=0; i < len; i++)
{
try
{
pc.addToRole(rolerefs[i], new EJBRoleRefPermission(ejbName, rolerefs[i]));
}
catch (PolicyContextException e)
{
throw new RuntimeException(e);
}
}
}
//Am I iterating over the right thing here? Should I be using the stuff from
//Advisor.methodInterceptors instead?
for(Method m : container.getBeanClass().getMethods())
{
EJBMethodPermission permission = new EJBMethodPermission(ejbName, null, m);
log.trace("Creating permission: " + permission);
PermitAll unchecked = (PermitAll) container.resolveAnnotation(m, PermitAll.class);
RolesAllowed permissions = (RolesAllowed) container.resolveAnnotation(m, RolesAllowed.class);
DenyAll exclude = (DenyAll) container.resolveAnnotation(m, DenyAll.class);
int annotationCount = getAnnotationCount(unchecked, permissions, exclude);