Class ServletSecurityAnnotationHandler

All Implemented Interfaces:
AnnotationIntrospector.IntrospectableAnnotationHandler

public class ServletSecurityAnnotationHandler extends AnnotationIntrospector.AbstractIntrospectableAnnotationHandler
ServletSecurityAnnotationHandler Inspect a class to see if it has an @ServletSecurity annotation on it, setting up the <security-constraint>s. A servlet can be defined in:
  • web.xml
  • web-fragment.xml
  • @WebServlet annotation discovered
  • ServletContext.createServlet
The ServletSecurity annotation for a servlet should only be processed iff metadata-complete == false.
  • Constructor Details

    • ServletSecurityAnnotationHandler

      public ServletSecurityAnnotationHandler(WebAppContext wac)
  • Method Details

    • doHandle

      public void doHandle(Class clazz)
      Specified by:
      doHandle in class AnnotationIntrospector.AbstractIntrospectableAnnotationHandler
    • makeConstraint

      protected Constraint makeConstraint(Class servlet, String[] rolesAllowed, jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, jakarta.servlet.annotation.ServletSecurity.TransportGuarantee transport)
      Make a jetty Constraint object, which represents the <auth-constraint> and <user-data-constraint> elements, based on the security annotation.
      Parameters:
      servlet - the servlet
      rolesAllowed - the roles allowed
      permitOrDeny - the role / permission semantic
      transport - the transport guarantee
      Returns:
      the constraint
    • getServletMappings

      protected List<ServletMapping> getServletMappings(String className)
      Get the ServletMappings for the servlet's class.
      Parameters:
      className - the class name
      Returns:
      the servlet mappings for the class
    • constraintsExist

      protected boolean constraintsExist(List<ServletMapping> servletMappings, List<ConstraintMapping> constraintMappings)
      Check if there are already <security-constraint> elements defined that match the url-patterns for the servlet.
      Parameters:
      servletMappings - the servlet mappings
      constraintMappings - the constraint mappings
      Returns:
      true if constraint exists