1 23 package com.sun.enterprise.deployment.annotation.handlers; 24 25 import java.lang.annotation.Annotation ; 26 import java.util.logging.Level ; 27 import javax.annotation.security.RunAs; 28 29 import com.sun.enterprise.deployment.EjbDescriptor; 30 import com.sun.enterprise.deployment.Role; 31 import com.sun.enterprise.deployment.RunAsIdentityDescriptor; 32 import com.sun.enterprise.deployment.WebComponentDescriptor; 33 import com.sun.enterprise.deployment.annotation.AnnotationInfo; 34 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException; 35 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult; 36 import com.sun.enterprise.deployment.annotation.context.EjbContext; 37 import com.sun.enterprise.deployment.annotation.context.WebBundleContext; 38 import com.sun.enterprise.deployment.annotation.context.WebComponentContext; 39 40 45 public class RunAsHandler extends AbstractCommonAttributeHandler { 46 47 public RunAsHandler() { 48 } 49 50 53 public Class <? extends Annotation > getAnnotationType() { 54 return RunAs.class; 55 } 56 57 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 58 EjbContext[] ejbContexts) throws AnnotationProcessorException { 59 60 RunAs runAsAn = (RunAs)ainfo.getAnnotation(); 61 62 for (EjbContext ejbContext : ejbContexts) { 63 EjbDescriptor ejbDesc = ejbContext.getDescriptor(); 64 if (ejbDesc.getUsesCallerIdentity() != null) { 66 continue; 67 } 68 String roleName = runAsAn.value(); 69 Role role = new Role(roleName); 70 ejbDesc.getEjbBundleDescriptor().addRole(role); 72 RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor(); 73 runAsDesc.setRoleName(roleName); 74 ejbDesc.setUsesCallerIdentity(false); 75 if (ejbDesc.getRunAsIdentity() == null) { 76 ejbDesc.setRunAsIdentity(runAsDesc); 77 } 78 } 79 80 return getDefaultProcessedResult(); 81 } 82 83 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 84 WebComponentContext[] webCompContexts) throws AnnotationProcessorException { 85 RunAs runAsAn = (RunAs)ainfo.getAnnotation(); 86 87 for (WebComponentContext webCompContext : webCompContexts) { 88 WebComponentDescriptor webDesc = webCompContext.getDescriptor(); 89 if (webDesc.getRunAsIdentity() != null) { 91 continue; 92 } 93 String roleName = runAsAn.value(); 94 Role role = new Role(roleName); 95 webDesc.getWebBundleDescriptor().addRole(role); 97 RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor(); 98 runAsDesc.setRoleName(roleName); 99 webDesc.setRunAsIdentity(runAsDesc); 100 } 101 102 return getDefaultProcessedResult(); 103 } 104 105 protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, 106 WebBundleContext webBundleContext) 107 throws AnnotationProcessorException { 108 return getInvalidAnnotatedElementHandlerResult( 109 ainfo.getProcessingContext().getHandler(), ainfo); 110 } 111 112 113 public Class <? extends Annotation >[] getTypeDependencies() { 114 return getEjbAnnotationTypes(); 115 } 116 } 117 | Popular Tags |