Search in sources :

Example 1 with ApplicationServletRegistration

use of org.apache.catalina.core.ApplicationServletRegistration in project tomcat by apache.

the class WebAnnotationSet method loadApplicationServletAnnotations.

/**
 * Process the annotations for the servlets.
 *
 * @param context The context which will have its annotations processed
 */
protected static void loadApplicationServletAnnotations(Context context) {
    Container[] children = context.findChildren();
    for (Container child : children) {
        if (child instanceof Wrapper) {
            Wrapper wrapper = (Wrapper) child;
            if (wrapper.getServletClass() == null) {
                continue;
            }
            Class<?> clazz = Introspection.loadClass(context, wrapper.getServletClass());
            if (clazz == null) {
                continue;
            }
            loadClassAnnotation(context, clazz);
            loadFieldsAnnotation(context, clazz);
            loadMethodsAnnotation(context, clazz);
            /* Process RunAs annotation which can be only on servlets.
                 * Ref JSR 250, equivalent to the run-as element in
                 * the deployment descriptor
                 */
            RunAs runAs = clazz.getAnnotation(RunAs.class);
            if (runAs != null) {
                wrapper.setRunAs(runAs.value());
            }
            // Process ServletSecurity annotation
            ServletSecurity servletSecurity = clazz.getAnnotation(ServletSecurity.class);
            if (servletSecurity != null) {
                context.addServletSecurity(new ApplicationServletRegistration(wrapper, context), new ServletSecurityElement(servletSecurity));
            }
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container) ServletSecurity(jakarta.servlet.annotation.ServletSecurity) RunAs(jakarta.annotation.security.RunAs) ApplicationServletRegistration(org.apache.catalina.core.ApplicationServletRegistration) ServletSecurityElement(jakarta.servlet.ServletSecurityElement)

Example 2 with ApplicationServletRegistration

use of org.apache.catalina.core.ApplicationServletRegistration in project tomcat70 by apache.

the class WebAnnotationSet method loadApplicationServletAnnotations.

/**
 * Process the annotations for the servlets.
 *
 * @param context The context which will have its annotations processed
 */
protected static void loadApplicationServletAnnotations(Context context) {
    Container[] children = context.findChildren();
    for (Container child : children) {
        if (child instanceof Wrapper) {
            Wrapper wrapper = (Wrapper) child;
            if (wrapper.getServletClass() == null) {
                continue;
            }
            Class<?> clazz = Introspection.loadClass(context, wrapper.getServletClass());
            if (clazz == null) {
                continue;
            }
            loadClassAnnotation(context, clazz);
            loadFieldsAnnotation(context, clazz);
            loadMethodsAnnotation(context, clazz);
            /* Process RunAs annotation which can be only on servlets.
                 * Ref JSR 250, equivalent to the run-as element in
                 * the deployment descriptor
                 */
            RunAs runAs = clazz.getAnnotation(RunAs.class);
            if (runAs != null) {
                wrapper.setRunAs(runAs.value());
            }
            // Process ServletSecurity annotation
            ServletSecurity servletSecurity = clazz.getAnnotation(ServletSecurity.class);
            if (servletSecurity != null) {
                context.addServletSecurity(new ApplicationServletRegistration(wrapper, context), new ServletSecurityElement(servletSecurity));
            }
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) Container(org.apache.catalina.Container) ServletSecurity(javax.servlet.annotation.ServletSecurity) RunAs(javax.annotation.security.RunAs) ApplicationServletRegistration(org.apache.catalina.core.ApplicationServletRegistration) ServletSecurityElement(javax.servlet.ServletSecurityElement)

Aggregations

Container (org.apache.catalina.Container)2 Wrapper (org.apache.catalina.Wrapper)2 ApplicationServletRegistration (org.apache.catalina.core.ApplicationServletRegistration)2 RunAs (jakarta.annotation.security.RunAs)1 ServletSecurityElement (jakarta.servlet.ServletSecurityElement)1 ServletSecurity (jakarta.servlet.annotation.ServletSecurity)1 RunAs (javax.annotation.security.RunAs)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 ServletSecurity (javax.servlet.annotation.ServletSecurity)1