Search in sources :

Example 1 with DeclareRoles

use of javax.annotation.security.DeclareRoles in project jetty.project by eclipse.

the class DeclareRolesAnnotationHandler method doHandle.

/**
     * @see org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler#doHandle(java.lang.Class)
     */
public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        //only applicable on javax.servlet.Servlet derivatives
        return;
    DeclareRoles declareRoles = (DeclareRoles) clazz.getAnnotation(DeclareRoles.class);
    if (declareRoles == null)
        return;
    String[] roles = declareRoles.value();
    if (roles != null && roles.length > 0) {
        for (String r : roles) ((ConstraintSecurityHandler) _context.getSecurityHandler()).addRole(r);
    }
}
Also used : Servlet(javax.servlet.Servlet) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 2 with DeclareRoles

use of javax.annotation.security.DeclareRoles in project Payara by payara.

the class DeclareRolesHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    DeclareRoles rolesRefAn = (DeclareRoles) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDescriptor = ejbContext.getDescriptor();
        for (String roleName : rolesRefAn.value()) {
            if (ejbDescriptor.getRoleReferenceByName(roleName) == null) {
                RoleReference roleRef = new RoleReference(roleName, "");
                roleRef.setRolename(roleName);
                roleRef.setSecurityRoleLink(new SecurityRoleDescriptor(roleName, ""));
                ejbDescriptor.addRoleReference(roleRef);
            }
            Role role = new Role(roleName);
            ejbDescriptor.getEjbBundleDescriptor().addRole(role);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 3 with DeclareRoles

use of javax.annotation.security.DeclareRoles in project tomcat70 by apache.

the class WebAnnotationSet method loadClassAnnotation.

/**
 * Process the annotations on a context for a given className.
 *
 * @param context The context which will have its annotations processed
 * @param clazz The class to examine for Servlet annotations
 */
protected static void loadClassAnnotation(Context context, Class<?> clazz) {
    /* Process Resource annotation.
         * Ref JSR 250
         */
    Resource resourceAnnotation = clazz.getAnnotation(Resource.class);
    if (resourceAnnotation != null) {
        addResource(context, resourceAnnotation);
    }
    /* Process Resources annotation.
         * Ref JSR 250
         */
    Resources resourcesAnnotation = clazz.getAnnotation(Resources.class);
    if (resourcesAnnotation != null && resourcesAnnotation.value() != null) {
        for (Resource resource : resourcesAnnotation.value()) {
            addResource(context, resource);
        }
    }
    /* Process EJB annotation.
         * Ref JSR 224, equivalent to the ejb-ref or ejb-local-ref
         * element in the deployment descriptor.
        {
            EJB annotation = clazz.getAnnotation(EJB.class);
            if (annotation != null) {

                if ((annotation.mappedName().length() == 0)
                        || annotation.mappedName().equals("Local")) {

                    ContextLocalEjb ejb = new ContextLocalEjb();

                    ejb.setName(annotation.name());
                    ejb.setType(annotation.beanInterface().getCanonicalName());
                    ejb.setDescription(annotation.description());

                    ejb.setHome(annotation.beanName());

                    context.getNamingResources().addLocalEjb(ejb);

                } else if (annotation.mappedName().equals("Remote")) {

                    ContextEjb ejb = new ContextEjb();

                    ejb.setName(annotation.name());
                    ejb.setType(annotation.beanInterface().getCanonicalName());
                    ejb.setDescription(annotation.description());

                    ejb.setHome(annotation.beanName());

                    context.getNamingResources().addEjb(ejb);

                }
            }
        }
        */
    /* Process WebServiceRef annotation.
         * Ref JSR 224, equivalent to the service-ref element in
         * the deployment descriptor.
         * The service-ref registration is not implemented
        {
            WebServiceRef annotation = clazz
                    .getAnnotation(WebServiceRef.class);
            if (annotation != null) {
                ContextService service = new ContextService();

                service.setName(annotation.name());
                service.setWsdlfile(annotation.wsdlLocation());

                service.setType(annotation.type().getCanonicalName());

                if (annotation.value() == null)
                    service.setServiceinterface(annotation.type()
                            .getCanonicalName());

                if (annotation.type().getCanonicalName().equals("Service"))
                    service.setServiceinterface(annotation.type()
                            .getCanonicalName());

                if (annotation.value().getCanonicalName().equals("Endpoint"))
                    service.setServiceendpoint(annotation.type()
                            .getCanonicalName());

                service.setPortlink(annotation.type().getCanonicalName());

                context.getNamingResources().addService(service);
            }
        }
        */
    /* Process DeclareRoles annotation.
         * Ref JSR 250, equivalent to the security-role element in
         * the deployment descriptor
         */
    DeclareRoles declareRolesAnnotation = clazz.getAnnotation(DeclareRoles.class);
    if (declareRolesAnnotation != null && declareRolesAnnotation.value() != null) {
        for (String role : declareRolesAnnotation.value()) {
            context.addSecurityRole(role);
        }
    }
}
Also used : Resource(javax.annotation.Resource) ContextResource(org.apache.catalina.deploy.ContextResource) DeclareRoles(javax.annotation.security.DeclareRoles) Resources(javax.annotation.Resources)

Example 4 with DeclareRoles

use of javax.annotation.security.DeclareRoles in project Payara by payara.

the class DynamicWebServletRegistrationImpl method processServletAnnotations.

private void processServletAnnotations(Class<? extends Servlet> clazz, WebBundleDescriptor webBundleDescriptor, WebComponentDescriptor wcd, StandardWrapper wrapper) {
    // Process DeclareRoles annotation
    if (clazz.isAnnotationPresent(DeclareRoles.class)) {
        DeclareRoles declareRoles = clazz.getAnnotation(DeclareRoles.class);
        for (String roleName : declareRoles.value()) {
            webBundleDescriptor.addRole(new Role(roleName));
            webModule.declareRoles(roleName);
        }
    }
    // Process MultipartConfig annotation
    if (clazz.isAnnotationPresent(MultipartConfig.class)) {
        MultipartConfig mpConfig = clazz.getAnnotation(MultipartConfig.class);
        wrapper.setMultipartLocation(mpConfig.location());
        wrapper.setMultipartMaxFileSize(mpConfig.maxFileSize());
        wrapper.setMultipartMaxRequestSize(mpConfig.maxRequestSize());
        wrapper.setMultipartFileSizeThreshold(mpConfig.fileSizeThreshold());
    }
}
Also used : Role(org.glassfish.security.common.Role) MultipartConfig(javax.servlet.annotation.MultipartConfig) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 5 with DeclareRoles

use of javax.annotation.security.DeclareRoles in project Payara by payara.

the class DeclareRolesHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    DeclareRoles rolesRefAn = (DeclareRoles) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDescriptor = ejbContext.getDescriptor();
        for (String roleName : rolesRefAn.value()) {
            if (ejbDescriptor.getRoleReferenceByName(roleName) == null) {
                RoleReference roleRef = new RoleReference(roleName, "");
                roleRef.setRoleName(roleName);
                roleRef.setSecurityRoleLink(new SecurityRoleDescriptor(roleName, ""));
                ejbDescriptor.addRoleReference(roleRef);
            }
            Role role = new Role(roleName);
            ejbDescriptor.getEjbBundleDescriptor().addRole(role);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) DeclareRoles(javax.annotation.security.DeclareRoles)

Aggregations

DeclareRoles (javax.annotation.security.DeclareRoles)8 Role (org.glassfish.security.common.Role)5 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)2 Resource (javax.annotation.Resource)1 Resources (javax.annotation.Resources)1 Servlet (javax.servlet.Servlet)1 MultipartConfig (javax.servlet.annotation.MultipartConfig)1 ContextResource (org.apache.catalina.deploy.ContextResource)1 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)1