final AssemblyDescriptor assemblyDescriptor = ejbModule.getEjbJar().getAssemblyDescriptor();
final List<String> classPermissions = getDeclaredClassPermissions(assemblyDescriptor, ejbName);
for (final Class<?> clazzz : Classes.ancestors(beanClass)) {
final MetaAnnotatedClass<?> clazz = new MetaAnnotatedClass(clazzz);
/*
* Process annotations at the class level
*/
if (!classPermissions.contains("*") || !classPermissions.contains(clazz.getName())) {
final RolesAllowed rolesAllowed = clazz.getAnnotation(RolesAllowed.class);
final PermitAll permitAll = clazz.getAnnotation(PermitAll.class);
final DenyAll denyAll = clazz.getAnnotation(DenyAll.class);
/*
* @RolesAllowed
*/
if ((rolesAllowed != null && permitAll != null)
|| (rolesAllowed != null && denyAll != null)
|| (permitAll != null && denyAll != null)) {
ejbModule.getValidation().fail(ejbName, "permitAllAndRolesAllowedOnClass", clazz.getName());
}
if (rolesAllowed != null) {
final MethodPermission methodPermission = new MethodPermission();
methodPermission.getRoleName().addAll(Arrays.asList(rolesAllowed.value()));
methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
assemblyDescriptor.getMethodPermission().add(methodPermission);
// Automatically add a role ref for any role listed in RolesAllowed
final RemoteBean remoteBean = (RemoteBean) bean;
final List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
for (final String role : rolesAllowed.value()) {
securityRoleRefs.add(new SecurityRoleRef(role));
}
}
/*
* @PermitAll
*/
if (permitAll != null) {
final MethodPermission methodPermission = new MethodPermission();
methodPermission.setUnchecked(true);
methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
assemblyDescriptor.getMethodPermission().add(methodPermission);
}
/**
* @DenyAll
*/
if (denyAll != null) {
assemblyDescriptor.getExcludeList()
.addMethod(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
}
}
/*
* @RunAs
*/
final RunAs runAs = clazz.getAnnotation(RunAs.class);
if (runAs != null && bean.getSecurityIdentity() == null) {
final SecurityIdentity securityIdentity = new SecurityIdentity();
securityIdentity.setRunAs(runAs.value());
bean.setSecurityIdentity(securityIdentity);
}
/*
* @DeclareRoles
*/
final DeclareRoles declareRoles = clazz.getAnnotation(DeclareRoles.class);
if (declareRoles != null && bean instanceof RemoteBean) {
final RemoteBean remoteBean = (RemoteBean) bean;
final List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
for (final String role : declareRoles.value()) {
securityRoleRefs.add(new SecurityRoleRef(role));