Package javax.servlet

Examples of javax.servlet.HttpMethodConstraintElement


                                                .getTransportGuarantee().toString());
                                    }
                                    roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                                    HttpConstraintElement constraint2 = new HttpConstraintElement(emptyRoleSemantic,
                                            transportGuarantee, roleNames);
                                    HttpMethodConstraintElement methodConstraint = new HttpMethodConstraintElement(
                                            annotationMethodConstraint.getMethod(), constraint2);
                                    methodConstraints.add(methodConstraint);
                                }
                            }
View Full Code Here


        //     @HttpMethodConstraint(value = "GET", rolesAllowed = "R1"),
        //     @HttpMethodConstraint(value = "POST", rolesAllowed = "R1",
        //     transportGuarantee = TransportGuarantee.CONFIDENTIAL)
        // })
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("GET",
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE, ROLE1)));
        hmces.add(new HttpMethodConstraintElement("POST",
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.CONFIDENTIAL,
                        ROLE1)));
        element = new ServletSecurityElement(hmces);
        result = SecurityConstraint.createConstraints(element, URL_PATTERN);
       
        assertEquals(2, result.length);
        for (int i = 0; i < 2; i++) {
            assertTrue(result[i].getAuthConstraint());
            assertEquals(1, result[i].findAuthRoles().length);
            assertTrue(result[i].findAuthRole(ROLE1));
            assertTrue(result[i].findCollections()[0].findPattern(URL_PATTERN));
            assertEquals(1, result[i].findCollections()[0].findMethods().length);
            String method = result[i].findCollections()[0].findMethods()[0];
            if ("GET".equals(method)) {
                assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                        result[i].getUserConstraint());
            } else if ("POST".equals(method)) {
                assertEquals(ServletSecurity.TransportGuarantee.CONFIDENTIAL.name(),
                        result[i].getUserConstraint());
            } else {
                fail("Unexpected method :[" + method + "]");
            }
        }
       
        // Example 13-6
        // @ServletSecurity(value = @HttpConstraint(rolesAllowed = "R1"),
        //     httpMethodConstraints = @HttpMethodConstraint("GET"))
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("GET"));
        element = new ServletSecurityElement(
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE,
                        ROLE1),
                hmces);
        result = SecurityConstraint.createConstraints(element, URL_PATTERN);
       
        assertEquals(2, result.length);
        for (int i = 0; i < 2; i++) {
            assertTrue(result[i].findCollections()[0].findPattern(URL_PATTERN));
            if (result[i].findCollections()[0].findMethods().length == 1) {
                assertEquals("GET",
                        result[i].findCollections()[0].findMethods()[0]);
                assertFalse(result[i].getAuthConstraint());
            } else if (result[i].findCollections()[0].findOmittedMethods().length == 1) {
                assertEquals("GET",
                        result[i].findCollections()[0].findOmittedMethods()[0]);
                assertTrue(result[i].getAuthConstraint());
                assertEquals(1, result[i].findAuthRoles().length);
                assertEquals(ROLE1, result[i].findAuthRoles()[0]);
            } else {
                fail("Unexpected number of methods defined");
            }
            assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                    result[i].getUserConstraint());
        }
       
        // Example 13-7
        // @ServletSecurity(value = @HttpConstraint(rolesAllowed = "R1"),
        //     httpMethodConstraints = @HttpMethodConstraint(value="TRACE",
        //         emptyRoleSemantic = EmptyRoleSemantic.DENY))
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("TRACE",
                new HttpConstraintElement(EmptyRoleSemantic.DENY)));
        element = new ServletSecurityElement(
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE,
                        ROLE1),
View Full Code Here

        //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);
        if (uneffectedUrlPatterns.size() == 0) {
            throw new RuntimeException("/SampleServlet3Dynamic should be returned as it is defined in the web.xml file");
        }
View Full Code Here

                                                .getTransportGuarantee().toString());
                                    }
                                    roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                                    HttpConstraintElement constraint2 = new HttpConstraintElement(emptyRoleSemantic,
                                            transportGuarantee, roleNames);
                                    HttpMethodConstraintElement methodConstraint = new HttpMethodConstraintElement(
                                            annotationMethodConstraint.getMethod(), constraint2);
                                    methodConstraints.add(methodConstraint);
                                }
                            }
View Full Code Here

                                                .getTransportGuarantee().toString());
                                    }
                                    roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                                    HttpConstraintElement constraint2 = new HttpConstraintElement(emptyRoleSemantic,
                                            transportGuarantee, roleNames);
                                    HttpMethodConstraintElement methodConstraint = new HttpMethodConstraintElement(
                                            annotationMethodConstraint.getMethod(), constraint2);
                                    methodConstraints.add(methodConstraint);
                                }
                            }
View Full Code Here

            sr.addMapping("/test");

            // Add a constraint with uncovered methods
            HttpConstraintElement hce = new HttpConstraintElement(
                    TransportGuarantee.NONE, "tomcat");
            HttpMethodConstraintElement hmce =
                    new HttpMethodConstraintElement("POST", hce);
            Set<HttpMethodConstraintElement> hmces = new HashSet<>();
            hmces.add(hmce);
            ServletSecurityElement sse = new ServletSecurityElement(hmces);
            sr.setServletSecurity(sse);
        }
View Full Code Here

        //     @HttpMethodConstraint(value = "GET", rolesAllowed = "R1"),
        //     @HttpMethodConstraint(value = "POST", rolesAllowed = "R1",
        //     transportGuarantee = TransportGuarantee.CONFIDENTIAL)
        // })
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("GET",
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE, ROLE1)));
        hmces.add(new HttpMethodConstraintElement("POST",
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.CONFIDENTIAL,
                        ROLE1)));
        element = new ServletSecurityElement(hmces);
        result = SecurityConstraint.createConstraints(element, URL_PATTERN);
       
        assertEquals(2, result.length);
        for (int i = 0; i < 2; i++) {
            assertEquals(true, result[i].getAuthConstraint());
            assertEquals(1, result[i].findAuthRoles().length);
            assertEquals(true, result[i].findAuthRole(ROLE1));
            assertEquals(true,
                    result[i].findCollections()[0].findPattern(URL_PATTERN));
            assertEquals(1, result[i].findCollections()[0].findMethods().length);
            String method = result[i].findCollections()[0].findMethods()[0];
            if ("GET".equals(method)) {
                assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                        result[i].getUserConstraint());
            } else if ("POST".equals(method)) {
                assertEquals(ServletSecurity.TransportGuarantee.CONFIDENTIAL.name(),
                        result[i].getUserConstraint());
            } else {
                fail("Unexpected method :[" + method + "]");
            }
        }
       
        // Example 13-6
        // @ServletSecurity(value = @HttpConstraint(rolesAllowed = "R1"),
        //     httpMethodConstraints = @HttpMethodConstraint("GET"))
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("GET"));
        element = new ServletSecurityElement(
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE,
                        ROLE1),
                hmces);
        result = SecurityConstraint.createConstraints(element, URL_PATTERN);
       
        assertEquals(2, result.length);
        for (int i = 0; i < 2; i++) {
            assertEquals(true,
                    result[i].findCollections()[0].findPattern(URL_PATTERN));
            if (result[i].findCollections()[0].findMethods().length == 1) {
                assertEquals("GET",
                        result[i].findCollections()[0].findMethods()[0]);
                assertEquals(false, result[i].getAuthConstraint());
            } else if (result[i].findCollections()[0].findOmittedMethods().length == 1) {
                assertEquals("GET",
                        result[i].findCollections()[0].findOmittedMethods()[0]);
                assertEquals(true, result[i].getAuthConstraint());
                assertEquals(1, result[i].findAuthRoles().length);
                assertEquals(ROLE1, result[i].findAuthRoles()[0]);
            } else {
                fail("Unexpected number of methods defined");
            }
            assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                    result[i].getUserConstraint());
        }
       
        // Example 13-7
        // @ServletSecurity(value = @HttpConstraint(rolesAllowed = "R1"),
        //     httpMethodConstraints = @HttpMethodConstraint(value="TRACE",
        //         emptyRoleSemantic = EmptyRoleSemantic.DENY))
        hmces.clear();
        hmces.add(new HttpMethodConstraintElement("TRACE",
                new HttpConstraintElement(EmptyRoleSemantic.DENY)));
        element = new ServletSecurityElement(
                new HttpConstraintElement(
                        ServletSecurity.TransportGuarantee.NONE,
                        ROLE1),
View Full Code Here

                                                .getTransportGuarantee().toString());
                                    }
                                    roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                                    HttpConstraintElement constraint2 = new HttpConstraintElement(emptyRoleSemantic,
                                            transportGuarantee, roleNames);
                                    HttpMethodConstraintElement methodConstraint = new HttpMethodConstraintElement(
                                            annotationMethodConstraint.getMethod(), constraint2);
                                    methodConstraints.add(methodConstraint);
                                }
                            }
View Full Code Here

                                                .getTransportGuarantee().toString());
                                    }
                                    roleNames = annotationMethodConstraint.getRolesAllowed().toArray(new String[0]);
                                    HttpConstraintElement constraint2 = new HttpConstraintElement(emptyRoleSemantic,
                                            transportGuarantee, roleNames);
                                    HttpMethodConstraintElement methodConstraint = new HttpMethodConstraintElement(
                                            annotationMethodConstraint.getMethod(), constraint2);
                                    methodConstraints.add(methodConstraint);
                                }
                            }
View Full Code Here

        // Add the per method constraints
        Collection<HttpMethodConstraintElement> methods =
            element.getHttpMethodConstraints();
        Iterator<HttpMethodConstraintElement> methodIter = methods.iterator();
        while (methodIter.hasNext()) {
            HttpMethodConstraintElement methodElement = methodIter.next();
            SecurityConstraint constraint =
                createConstraint(methodElement, urlPattern, true);
            // There will always be a single collection
            SecurityCollection collection = constraint.findCollections()[0];
            collection.addMethod(methodElement.getMethodName());
            result.add(constraint);
        }
       
        // Add the constraint for all the other methods
        SecurityConstraint constraint = createConstraint(element, urlPattern, false);
View Full Code Here

TOP

Related Classes of javax.servlet.HttpMethodConstraintElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.