Search in sources :

Example 1 with RedirectStrategyWithSwitchableFollowRedirect

use of org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect in project keycloak by keycloak.

the class BasicSamlTest method testWithOverriddenPort.

private void testWithOverriddenPort(int port, Response.Status expectedHttpCode, Matcher<String> pageTextMatcher) throws Exception {
    AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, RealmsResource.protocolUrl(UriBuilder.fromUri(getAuthServerRoot()).port(port)).build(REALM_NAME, SamlProtocol.LOGIN_PROTOCOL));
    Document doc = SAML2Request.convert(loginRep);
    HttpUriRequest post = Binding.POST.createSamlUnsignedRequest(getAuthServerSamlEndpoint(REALM_NAME), null, doc);
    try (CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new RedirectStrategyWithSwitchableFollowRedirect()).build();
        CloseableHttpResponse response = client.execute(post)) {
        assertThat(response, statusCodeIsHC(expectedHttpCode));
        assertThat(EntityUtils.toString(response.getEntity(), "UTF-8"), pageTextMatcher);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) RedirectStrategyWithSwitchableFollowRedirect(org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.w3c.dom.Document)

Example 2 with RedirectStrategyWithSwitchableFollowRedirect

use of org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect in project keycloak by keycloak.

the class BasicSamlTest method testNoDestinationPost.

@Test
public void testNoDestinationPost() throws Exception {
    AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, null);
    Document doc = SAML2Request.convert(loginRep);
    HttpUriRequest post = Binding.POST.createSamlUnsignedRequest(getAuthServerSamlEndpoint(REALM_NAME), null, doc);
    try (CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new RedirectStrategyWithSwitchableFollowRedirect()).build();
        CloseableHttpResponse response = client.execute(post)) {
        assertThat(response, statusCodeIsHC(Response.Status.OK));
        assertThat(EntityUtils.toString(response.getEntity(), "UTF-8"), containsString("login"));
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) RedirectStrategyWithSwitchableFollowRedirect(org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with RedirectStrategyWithSwitchableFollowRedirect

use of org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect in project keycloak by keycloak.

the class BasicSamlTest method testNoDestinationRedirect.

@Test
public void testNoDestinationRedirect() throws Exception {
    AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, null);
    Document doc = SAML2Request.convert(loginRep);
    HttpUriRequest post = Binding.REDIRECT.createSamlUnsignedRequest(getAuthServerSamlEndpoint(REALM_NAME), null, doc);
    try (CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new RedirectStrategyWithSwitchableFollowRedirect()).build();
        CloseableHttpResponse response = client.execute(post)) {
        assertThat(response, statusCodeIsHC(Response.Status.OK));
        assertThat(EntityUtils.toString(response.getEntity(), "UTF-8"), containsString("login"));
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) RedirectStrategyWithSwitchableFollowRedirect(org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with RedirectStrategyWithSwitchableFollowRedirect

use of org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect in project keycloak by keycloak.

the class BasicSamlTest method testNoDestinationSignedPost.

@Test
public void testNoDestinationSignedPost() throws Exception {
    AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(SAML_CLIENT_ID_SALES_POST_SIG, SAML_ASSERTION_CONSUMER_URL_SALES_POST_SIG, null);
    Document doc = SAML2Request.convert(loginRep);
    HttpUriRequest post = Binding.POST.createSamlSignedRequest(getAuthServerSamlEndpoint(REALM_NAME), null, doc, SAML_CLIENT_SALES_POST_SIG_PRIVATE_KEY, SAML_CLIENT_SALES_POST_SIG_PUBLIC_KEY);
    try (CloseableHttpClient client = HttpClientBuilder.create().setRedirectStrategy(new RedirectStrategyWithSwitchableFollowRedirect()).build();
        CloseableHttpResponse response = client.execute(post)) {
        assertThat(response, statusCodeIsHC(Status.BAD_REQUEST));
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) RedirectStrategyWithSwitchableFollowRedirect(org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)4 AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)4 RedirectStrategyWithSwitchableFollowRedirect (org.keycloak.testsuite.util.SamlClient.RedirectStrategyWithSwitchableFollowRedirect)4 Document (org.w3c.dom.Document)4 Test (org.junit.Test)3