Search in sources :

Example 61 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class SPNEGOLoginModuleTestCase method testPlainKerberosWorkflow.

/**
     * Kerberos simple scenario. Client provides a valid Kerberos token (without SPNEGO envelope) in the first round. See
     * <a href="https://tools.ietf.org/html/rfc4121">RFC-4121</a>.
     */
@Test
@OperateOnDeployment("WEB")
public void testPlainKerberosWorkflow(@ArquillianResource URL webAppURL) throws Exception {
    final URI uri = getServletURI(webAppURL, SimpleSecuredServlet.SERVLET_PATH);
    final byte[] kerberosToken = createNewKerberosTicketForHttp(uri);
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        final HttpGet httpGet = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpGet);
        assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
        assertHttpHeader(response, HEADER_WWW_AUTHENTICATE, "Negotiate");
        EntityUtils.consume(response.getEntity());
        httpGet.setHeader(HEADER_AUTHORIZATION, "Negotiate " + Base64.getEncoder().encodeToString(kerberosToken));
        response = httpClient.execute(httpGet);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Negotiate response in HTTP header:\n" + KerberosTestUtils.dumpNegotiateHeader(response));
        }
        assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
        assertEquals("Unexpected response body", SimpleSecuredServlet.RESPONSE_BODY, EntityUtils.toString(response.getEntity()));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 62 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class JACCForEarModulesTestCase method testEJBPermissions.

/**
     * Tests EJB permissions (jar directly and jar in ear).
     *
     * @param webAppURL
     * @throws Exception
     */
@Test
@OperateOnDeployment("war")
public void testEJBPermissions(@ArquillianResource URL webAppURL) throws Exception {
    final Document doc = getPermissionDocument(webAppURL);
    testJACCEjbPermissions(doc.selectSingleNode("/" + ListJACCPoliciesServlet.ROOT_ELEMENT + "/ActiveContextPolicies/ContextPolicy[@contextID='jar-jacc-test.jar']"));
    testJACCEjbPermissions(doc.selectSingleNode("/" + ListJACCPoliciesServlet.ROOT_ELEMENT + "/ActiveContextPolicies/ContextPolicy[@contextID='ear-jacc-test.ear!ear-jacc-test.jar']"));
}
Also used : Document(org.dom4j.Document) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 63 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class SPNEGOLoginModuleTestCase method testContSpnegoWorkflow.

/**
     * SPNEGO continuation scenario - more mechanismTypes is provided and the Kerberos mechanism is not the most preferable one.
     * Client provides valid token in the second round.
     */
@Test
@OperateOnDeployment("WEB")
public void testContSpnegoWorkflow(@ArquillianResource URL webAppURL) throws Exception {
    final URI uri = getServletURI(webAppURL, SimpleSecuredServlet.SERVLET_PATH);
    final String[] mechTypes = new String[] { OID_DUMMY, OID_KERBEROS_V5_LEGACY, OID_KERBEROS_V5 };
    assertSpnegoWorkflow(uri, mechTypes, DUMMY_TOKEN, createNewKerberosTicketForHttp(uri), true, true);
}
Also used : URI(java.net.URI) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 64 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class SPNEGOLoginModuleTestCase method testLegacyKerberosSpnegoWorkflow.

/**
     * SPNEGO continuation scenario - Kerberos mechanisms are provided as mechanismTypes. The Legacy (aka Microsoft) mechanism
     * is provided as the first one and we expect the server will not accept it and it'll ask the token for the standard
     * Kerberos mechanism OID. Client provides valid token in both rounds.
     */
@Test
@OperateOnDeployment("WEB")
public void testLegacyKerberosSpnegoWorkflow(@ArquillianResource URL webAppURL) throws Exception {
    final URI uri = getServletURI(webAppURL, SimpleSecuredServlet.SERVLET_PATH);
    final String[] mechTypes = new String[] { OID_KERBEROS_V5_LEGACY, OID_KERBEROS_V5 };
    final byte[] kerberosToken = createNewKerberosTicketForHttp(uri);
    assertSpnegoWorkflow(uri, mechTypes, kerberosToken, kerberosToken, true, true);
}
Also used : URI(java.net.URI) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 65 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class SPNEGOLoginModuleTestCase method testFormFallback.

/**
     * Tests web SPNEGO authentication with FORM method fallback.
     *
     * @throws Exception
     */
@Test
@OperateOnDeployment("WEB-FORM")
public void testFormFallback(@ArquillianResource URL webAppURL) throws Exception {
    KerberosTestUtils.assumeKerberosAuthenticationSupported();
    final URI servletUri = getServletURI(webAppURL, SimpleSecuredServlet.SERVLET_PATH);
    LOGGER.trace("Testing fallback to FORM authentication. " + servletUri);
    LOGGER.trace("Testing successful SPNEGO authentication");
    String responseBody = Utils.makeCallWithKerberosAuthn(servletUri, "jduke", "theduke", HttpServletResponse.SC_OK);
    assertEquals("Unexpected response body", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
    LOGGER.trace("Testing successful FORM authentication");
    responseBody = Utils.makeHttpCallWoSPNEGO(webAppURL.toExternalForm(), SimpleSecuredServlet.SERVLET_PATH, "jduke@JBOSS.ORG", "fallback", HttpServletResponse.SC_OK);
    assertEquals("Unexpected response body", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
    LOGGER.trace("Testing FORM fallback");
    responseBody = Utils.makeHttpCallWithFallback(webAppURL.toExternalForm(), SimpleSecuredServlet.SERVLET_PATH, "jduke@JBOSS.ORG", "fallback", HttpServletResponse.SC_OK);
    assertEquals("Unexpected response body", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
}
Also used : URI(java.net.URI) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)94 Test (org.junit.Test)93 URL (java.net.URL)31 URI (java.net.URI)22 HttpGet (org.apache.http.client.methods.HttpGet)20 HttpResponse (org.apache.http.HttpResponse)17 InitialContext (javax.naming.InitialContext)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)13 QName (javax.xml.namespace.QName)11 Service (javax.xml.ws.Service)11 HttpEntity (org.apache.http.HttpEntity)10 Bus (org.apache.cxf.Bus)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)5 WebConversation (com.meterware.httpunit.WebConversation)5 WebForm (com.meterware.httpunit.WebForm)5 WebRequest (com.meterware.httpunit.WebRequest)5