Java Code Examples for org.apache.catalina.Context#setPreemptiveAuthentication()

The following examples show how to use org.apache.catalina.Context#setPreemptiveAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestClientCert.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void doTestClientCertGet(boolean preemtive) throws Exception {
    Assume.assumeTrue("SSL renegotiation has to be supported for this test",
            TesterSupport.isRenegotiationSupported(getTomcatInstance()));

    if (preemtive) {
        Tomcat tomcat = getTomcatInstance();
        // Only one context deployed
        Context c = (Context) tomcat.getHost().findChildren()[0];
        // Enable pre-emptive auth
        c.setPreemptiveAuthentication(true);
    }

    getTomcatInstance().start();

    // Unprotected resource
    ByteChunk res =
            getUrl("https://localhost:" + getPort() + "/unprotected");
    if (preemtive) {
        assertEquals("OK-" + TesterSupport.ROLE, res.toString());
    } else {
        assertEquals("OK", res.toString());
    }

    // Protected resource
    res = getUrl("https://localhost:" + getPort() + "/protected");
    assertEquals("OK-" + TesterSupport.ROLE, res.toString());
}
 
Example 2
Source File: TestClientCert.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void doTestClientCertGet(boolean preemtive) throws Exception {
    Assume.assumeTrue("SSL renegotiation has to be supported for this test",
            TesterSupport.isRenegotiationSupported(getTomcatInstance()));

    if (preemtive) {
        Tomcat tomcat = getTomcatInstance();
        // Only one context deployed
        Context c = (Context) tomcat.getHost().findChildren()[0];
        // Enable pre-emptive auth
        c.setPreemptiveAuthentication(true);
    }

    getTomcatInstance().start();

    // Unprotected resource
    ByteChunk res =
            getUrl("https://localhost:" + getPort() + "/unprotected");
    if (preemtive) {
        assertEquals("OK-" + TesterSupport.ROLE, res.toString());
    } else {
        assertEquals("OK", res.toString());
    }

    // Protected resource
    res = getUrl("https://localhost:" + getPort() + "/protected");
    assertEquals("OK-" + TesterSupport.ROLE, res.toString());
}
 
Example 3
Source File: TestClientCert.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void doTestClientCertGet(boolean preemptive) throws Exception {
    Assume.assumeTrue("SSL renegotiation has to be supported for this test",
            TesterSupport.isRenegotiationSupported(getTomcatInstance()));

    if (preemptive) {
        Tomcat tomcat = getTomcatInstance();
        // Only one context deployed
        Context c = (Context) tomcat.getHost().findChildren()[0];
        // Enable pre-emptive auth
        c.setPreemptiveAuthentication(true);
    }

    getTomcatInstance().start();

    // Unprotected resource
    ByteChunk res = getUrl("https://localhost:" + getPort() + "/unprotected");

    int count = TesterSupport.getLastClientAuthRequestedIssuerCount();
    if (log.isDebugEnabled()) {
        log.debug("Last client KeyManager usage: " + TesterSupport.getLastClientAuthKeyManagerUsage() +
                  ", " + count + " requested Issuers, first one: " +
                  (count > 0 ? TesterSupport.getLastClientAuthRequestedIssuer(0).getName() : "NONE"));
        log.debug("Expected requested Issuer: " +
                  (preemptive ? TesterSupport.getClientAuthExpectedIssuer() : "NONE"));
    }

    if (preemptive) {
        Assert.assertTrue("Checking requested client issuer against " +
                TesterSupport.getClientAuthExpectedIssuer(),
                TesterSupport.checkLastClientAuthRequestedIssuers());
        Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());
    } else {
        Assert.assertEquals(0, count);
        Assert.assertEquals("OK", res.toString());
    }

    // Protected resource
    res = getUrl("https://localhost:" + getPort() + "/protected");

    if (log.isDebugEnabled()) {
        count = TesterSupport.getLastClientAuthRequestedIssuerCount();
        log.debug("Last client KeyManager usage: " + TesterSupport.getLastClientAuthKeyManagerUsage() +
                  ", " + count + " requested Issuers, first one: " +
                  (count > 0 ? TesterSupport.getLastClientAuthRequestedIssuer(0).getName() : "NONE"));
        log.debug("Expected requested Issuer: " + TesterSupport.getClientAuthExpectedIssuer());
    }
    Assert.assertTrue("Checking requested client issuer against " +
            TesterSupport.getClientAuthExpectedIssuer(),
            TesterSupport.checkLastClientAuthRequestedIssuers());

    Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());
}