Search in sources :

Example 11 with ServletSecurityElement

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());
}
Also used : HttpConstraintElement(javax.servlet.HttpConstraintElement) ServletSecurityElement(javax.servlet.ServletSecurityElement) Test(org.junit.Test)

Example 12 with ServletSecurityElement

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
     * &#064;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());
}
Also used : HttpConstraintElement(javax.servlet.HttpConstraintElement) ServletSecurityElement(javax.servlet.ServletSecurityElement) Test(org.junit.Test)

Aggregations

ServletSecurityElement (javax.servlet.ServletSecurityElement)12 Test (org.junit.Test)9 HttpConstraintElement (javax.servlet.HttpConstraintElement)8 ArrayList (java.util.ArrayList)4 HttpMethodConstraintElement (javax.servlet.HttpMethodConstraintElement)4 ServletSecurity (javax.servlet.annotation.ServletSecurity)3 Context (org.apache.catalina.Context)2 HashSet (java.util.HashSet)1 FilterRegistration (javax.servlet.FilterRegistration)1 ServletContext (javax.servlet.ServletContext)1 ServletRegistration (javax.servlet.ServletRegistration)1 Response (org.apache.catalina.connector.Response)1 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)1 TesterContext (org.apache.tomcat.unittest.TesterContext)1 TesterRequest (org.apache.tomcat.unittest.TesterRequest)1 TesterResponse (org.apache.tomcat.unittest.TesterResponse)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 ConstraintAware (org.eclipse.jetty.security.ConstraintAware)1 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)1