ServletContext servletContext = servletContextEvent.getServletContext();
//dynamic register /SampleServlet3Dynamic and security constraint
Dynamic servlet3Dynamic = servletContext.addServlet("SampleServlet3Dynamic", SampleServlet3.class);
servlet3Dynamic.addMapping("/SampleServlet3Dynamic", "/TestDynamic");
HttpConstraintElement httpConstraintElement = new HttpConstraintElement();
List<HttpMethodConstraintElement> httpMethodConstraintElements = new ArrayList<HttpMethodConstraintElement>();
httpMethodConstraintElements.add(new HttpMethodConstraintElement("GET", new HttpConstraintElement(ServletSecurity.TransportGuarantee.NONE, "RoleC")));
ServletSecurityElement servletSecurityElement = new ServletSecurityElement(httpConstraintElement, httpMethodConstraintElements);
Set<String> uneffectedUrlPatterns = servlet3Dynamic.setServletSecurity(servletSecurityElement);