1 23 package com.sun.enterprise.deployment.annotation.handlers; 24 25 import java.lang.annotation.Annotation ; 26 import java.lang.annotation.ElementType ; 27 import java.lang.reflect.AnnotatedElement ; 28 import java.lang.reflect.Method ; 29 30 import javax.annotation.security.DeclareRoles; 31 32 import com.sun.enterprise.deployment.EjbDescriptor; 33 import com.sun.enterprise.deployment.Role; 34 import com.sun.enterprise.deployment.RoleReference; 35 import com.sun.enterprise.deployment.SecurityRoleDescriptor; 36 import com.sun.enterprise.deployment.WebBundleDescriptor; 37 import com.sun.enterprise.deployment.WebComponentDescriptor; 38 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 39 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 40 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 41 import com.sun.enterprise.deployment.annotation.context.EjbContext; 42 import com.sun.enterprise.deployment.annotation.context.WebBundleContext; 43 import com.sun.enterprise.deployment.annotation.context.WebComponentContext; 44 45 51 public class DeclareRolesHandler extends AbstractCommonAttributeHandler { 52 53 public DeclareRolesHandler() { 54 } 55 56 59 public Class <? extends Annotation > getAnnotationType() { 60 return DeclareRoles.class; 61 } 62 63 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 64 EjbContext[] ejbContexts) throws AnnotationProcessorException { 65 66 DeclareRoles rolesRefAn = (DeclareRoles)ainfo.getAnnotation(); 67 68 for (EjbContext ejbContext : ejbContexts) { 69 EjbDescriptor ejbDescriptor = ejbContext.getDescriptor(); 70 for (String roleName : rolesRefAn.value()) { 71 if (ejbDescriptor.getRoleReferenceByName(roleName) == null) { 72 RoleReference roleRef = new RoleReference(roleName, ""); 73 roleRef.setRolename(roleName); 74 roleRef.setSecurityRoleLink( 75 new SecurityRoleDescriptor(roleName, "")); 76 ejbDescriptor.addRoleReference(roleRef); 77 } 78 79 Role role = new Role(roleName); 80 ejbDescriptor.getEjbBundleDescriptor().addRole(role); 81 } 82 } 83 return getDefaultProcessedResult(); 84 } 85 86 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 87 WebComponentContext[] webCompContexts) 88 throws AnnotationProcessorException { 89 WebBundleDescriptor webBundleDesc = 90 webCompContexts[0].getDescriptor().getWebBundleDescriptor(); 91 return processAnnotation(ainfo, webBundleDesc); 92 } 93 94 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 95 WebBundleContext webBundleContext) 96 throws AnnotationProcessorException { 97 WebBundleDescriptor webBundleDesc = webBundleContext.getDescriptor(); 98 return processAnnotation(ainfo, webBundleDesc); 99 } 100 101 private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 102 WebBundleDescriptor webBundleDesc) { 103 DeclareRoles rolesRefAn = (DeclareRoles)ainfo.getAnnotation(); 104 for (String roleName : rolesRefAn.value()) { 105 Role role = new Role(roleName); 106 webBundleDesc.addRole(role); 107 } 108 return getDefaultProcessedResult(); 109 } 110 111 116 public Class <? extends Annotation >[] getTypeDependencies() { 117 return getEjbAnnotationTypes(); 118 } 119 120 protected boolean supportTypeInheritance() { 121 return true; 122 } 123 } 124 | Popular Tags |