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 import java.util.logging.Level ; 30 31 import javax.annotation.security.DenyAll; 32 import javax.annotation.security.PermitAll; 33 import javax.annotation.security.RolesAllowed; 34 35 import com.sun.enterprise.deployment.EjbDescriptor; 36 import com.sun.enterprise.deployment.MethodDescriptor; 37 import com.sun.enterprise.deployment.MethodPermission; 38 import com.sun.enterprise.deployment.Role; 39 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler; 40 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 41 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 42 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 43 import com.sun.enterprise.deployment.annotation.context.EjbContext; 44 import com.sun.enterprise.util.TypeUtil; 45 46 52 public class PermitAllHandler extends AbstractAttributeHandler implements PostProcessor { 53 54 public PermitAllHandler() { 55 } 56 57 60 public Class <? extends Annotation > getAnnotationType() { 61 return PermitAll.class; 62 } 63 64 70 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 71 EjbContext[] ejbContexts) throws AnnotationProcessorException { 72 73 AnnotatedElement ae = (AnnotatedElement )ainfo.getAnnotatedElement(); 74 if (ae.isAnnotationPresent(DenyAll.class) || 75 ae.isAnnotationPresent(RolesAllowed.class)) { 76 log(Level.SEVERE, ainfo, 77 localStrings.getLocalString( 78 "enterprise.deployment.annotation.handlers.inconsistentsecannotation", 79 "This annotation is not consistent with other annotations. One cannot have more than one of @RolesAllowed, @PermitAll, @DenyAll in the same AnnotatedElement.")); 80 return getDefaultFailedResult(); 81 } 82 83 for (EjbContext ejbContext : ejbContexts) { 84 EjbDescriptor ejbDesc = ejbContext.getDescriptor(); 85 86 if (ElementType.TYPE.equals(ainfo.getElementType())) { 87 ejbContext.addPostProcessInfo(ainfo, this); 89 } else { Method annMethod = (Method )ainfo.getAnnotatedElement(); 91 for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) { 92 MethodDescriptor md = (MethodDescriptor)next; 93 Method m = md.getMethod(ejbDesc); 94 if (TypeUtil.sameMethodSignature(m, annMethod)) { 95 if (!hasMethodPermissionsFromDD(md, ejbDesc)) { 97 ejbDesc.addPermissionedMethod( 98 MethodPermission.getUncheckedMethodPermission(), 99 md); 100 } 101 } 102 } 103 } 104 } 105 106 return getDefaultProcessedResult(); 107 } 108 109 114 public Class <? extends Annotation >[] getTypeDependencies() { 115 return getEjbAnnotationTypes(); 116 } 117 118 protected boolean supportTypeInheritance() { 119 return true; 120 } 121 122 public void postProcessAnnotation(AnnotationInfo ainfo, 123 AnnotatedElementHandler aeHandler) 124 throws AnnotationProcessorException { 125 EjbContext ejbContext = (EjbContext)aeHandler; 126 EjbDescriptor ejbDesc = ejbContext.getDescriptor(); 127 if (!ejbContext.isInherited() && 128 (ejbDesc.getMethodPermissionsFromDD() == null || 129 ejbDesc.getMethodPermissionsFromDD().size() == 0)) { 130 for (MethodDescriptor md : getMethodAllDescriptors(ejbDesc)) { 131 ejbDesc.addPermissionedMethod( 132 MethodPermission.getUncheckedMethodPermission(), md); 133 } 134 } else { 135 Class classAn = (Class )ainfo.getAnnotatedElement(); 136 for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) { 137 MethodDescriptor md = (MethodDescriptor)next; 138 if (classAn.equals(ejbContext.getDeclaringClass(md)) && 139 !hasMethodPermissionsFromDD(md, ejbDesc)) { 140 ejbDesc.addPermissionedMethod( 141 MethodPermission.getUncheckedMethodPermission(), 142 md); 143 } 144 } 145 } 146 } 147 } 148 | Popular Tags |