use of javax.servlet.ServletSecurityElement in project jetty.project by eclipse.
the class ConstraintTest method testSecurityElementExample13_4.
/**
* Equivalent of Servlet Spec 3.1 pg 132, sec 13.4.1.1, Example 13-4
* @ServletSecurity(@HttpConstraint(rolesAllowed = "R1"))
* @throws Exception if test fails
*/
@Test
public void testSecurityElementExample13_4() throws Exception {
HttpConstraintElement httpConstraintElement = new HttpConstraintElement(TransportGuarantee.NONE, "R1");
ServletSecurityElement element = new ServletSecurityElement(httpConstraintElement);
List<ConstraintMapping> mappings = ConstraintSecurityHandler.createConstraintsWithMappingsForPath("foo", "/foo/*", element);
Assert.assertTrue(!mappings.isEmpty());
Assert.assertEquals(1, mappings.size());
ConstraintMapping mapping = mappings.get(0);
Assert.assertTrue(mapping.getConstraint().getAuthenticate());
Assert.assertTrue(mapping.getConstraint().getRoles() != null);
Assert.assertEquals(1, mapping.getConstraint().getRoles().length);
Assert.assertEquals("R1", mapping.getConstraint().getRoles()[0]);
Assert.assertEquals(0, mapping.getConstraint().getDataConstraint());
}
use of javax.servlet.ServletSecurityElement in project jetty.project by eclipse.
the class ConstraintTest method testSecurityElementExample13_2.
/**
* Equivalent of Servlet Spec 3.1 pg 132, sec 13.4.1.1, Example 13-2
* @ServletSecurity(@HttpConstraint(transportGuarantee = TransportGuarantee.CONFIDENTIAL))
*
* @throws Exception if test fails
*/
@Test
public void testSecurityElementExample13_2() throws Exception {
HttpConstraintElement httpConstraintElement = new HttpConstraintElement(TransportGuarantee.CONFIDENTIAL);
ServletSecurityElement element = new ServletSecurityElement(httpConstraintElement);
List<ConstraintMapping> mappings = ConstraintSecurityHandler.createConstraintsWithMappingsForPath("foo", "/foo/*", element);
Assert.assertTrue(!mappings.isEmpty());
Assert.assertEquals(1, mappings.size());
ConstraintMapping mapping = mappings.get(0);
Assert.assertEquals(2, mapping.getConstraint().getDataConstraint());
}
Aggregations