FileDocCategorySizeDatePackage
RolesAllowedHandler.javaAPI DocGlassfish v2 API7460Fri May 04 22:31:34 BST 2007com.sun.enterprise.deployment.annotation.handlers

RolesAllowedHandler

public class RolesAllowedHandler extends AbstractAttributeHandler implements PostProcessor
This handler is responsible for handling the javax.annotation.security.RolesAllowed.
author
Shing Wai Chan

Fields Summary
Constructors Summary
public RolesAllowedHandler()

    
Methods Summary
private voidaddMethodPermissions(javax.annotation.security.RolesAllowed rolesAllowedAn, com.sun.enterprise.deployment.EjbDescriptor ejbDesc, com.sun.enterprise.deployment.MethodDescriptor md)
Add roles and permissions to given method in EjbDescriptor.

param
rolesAllowedAn
param
ejbDesc
param
md

        for (String roleName : rolesAllowedAn.value()) {
            Role role = new Role(roleName);
            // add role if not exists
            ejbDesc.getEjbBundleDescriptor().addRole(role);
            ejbDesc.addPermissionedMethod(new MethodPermission(role), md);
        }
    
public java.lang.ClassgetAnnotationType()

return
the annoation type this annotation handler is handling

        return RolesAllowed.class;
    
public java.lang.Class[]getTypeDependencies()

return
an array of annotation types this annotation handler would require to be processed (if present) before it processes it's own annotation type.

        return getEjbAnnotationTypes();
    
public voidpostProcessAnnotation(com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo, com.sun.enterprise.deployment.annotation.AnnotatedElementHandler aeHandler)

        EjbContext ejbContext = (EjbContext)aeHandler;
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        RolesAllowed rolesAllowedAn = (RolesAllowed)ainfo.getAnnotation();
        if (!ejbContext.isInherited() &&
                (ejbDesc.getMethodPermissionsFromDD() == null ||
                ejbDesc.getMethodPermissionsFromDD().size() == 0)) {
            for (MethodDescriptor md : getMethodAllDescriptors(ejbDesc)) {
                addMethodPermissions(rolesAllowedAn, ejbDesc, md);
            }
        } else {
            Class classAn = (Class)ainfo.getAnnotatedElement();
            for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) {
                MethodDescriptor md = (MethodDescriptor)next;
                Method m = md.getMethod(ejbDesc);
                // override by existing info
                if (classAn.equals(ejbContext.getDeclaringClass(md)) &&
                        !hasMethodPermissionsFromDD(md, ejbDesc)) {
                    addMethodPermissions(rolesAllowedAn, ejbDesc, md);
                }
            }
        }
    
protected com.sun.enterprise.deployment.annotation.HandlerProcessingResultprocessAnnotation(com.sun.enterprise.deployment.annotation.AnnotationInfo ainfo, com.sun.enterprise.deployment.annotation.context.EjbContext[] ejbContexts)


        AnnotatedElement ae = (AnnotatedElement)ainfo.getAnnotatedElement();

        if (ae.isAnnotationPresent(DenyAll.class) ||
                ae.isAnnotationPresent(PermitAll.class)) {
            log(Level.SEVERE, ainfo,
                localStrings.getLocalString(
                "enterprise.deployment.annotation.handlers.inconsistentsecannotation",
                "This annotation is not consistent with other annotations.  One cannot have more than one of @RolesAllowed, @PermitAll, @DenyAll in the same AnnotatedElement."));
            return getDefaultFailedResult();
        }
        
        RolesAllowed rolesAllowedAn = (RolesAllowed)ainfo.getAnnotation();

        for (EjbContext ejbContext : ejbContexts) {
            EjbDescriptor ejbDesc = ejbContext.getDescriptor();
            if (ElementType.TYPE.equals(ainfo.getElementType())) {
                // postpone the processing at the end
                ejbContext.addPostProcessInfo(ainfo, this);
            } else {
                Method annMethod = (Method) ainfo.getAnnotatedElement();
                
                for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) {
                    MethodDescriptor md = (MethodDescriptor)next;
                    Method m = md.getMethod(ejbDesc);
                    if (TypeUtil.sameMethodSignature(m, annMethod)) {
                        // override by xml
                        if (!hasMethodPermissionsFromDD(md, ejbDesc)) {
                            addMethodPermissions(rolesAllowedAn, ejbDesc, md);
                        }
                    }
                }
            }
        }

        return getDefaultProcessedResult();
    
protected booleansupportTypeInheritance()

        return true;