use of org.keycloak.testsuite.util.SamlClientBuilder in project keycloak by keycloak.
the class SamlClientCertificateExpirationTest method testValidCertificate.
@Test
public void testValidCertificate() throws Exception {
// Unsigned request should fail
new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST_SIG, SAML_ASSERTION_CONSUMER_URL_SALES_POST_SIG, Binding.POST).build().assertResponse(Matchers.statusCodeIsHC(Status.BAD_REQUEST));
// Signed request should succeed
new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST_SIG, SAML_ASSERTION_CONSUMER_URL_SALES_POST_SIG, Binding.POST).signWith(SAML_CLIENT_SALES_POST_SIG_PRIVATE_KEY, SAML_CLIENT_SALES_POST_SIG_PUBLIC_KEY).build().assertResponse(Matchers.statusCodeIsHC(Status.OK));
}
use of org.keycloak.testsuite.util.SamlClientBuilder in project keycloak by keycloak.
the class FixedHostnameTest method assertSamlLogin.
private void assertSamlLogin(Keycloak testAdminClient, String realm, String expectedBaseUrl) throws Exception {
final String realmUrl = expectedBaseUrl + "/auth/realms/" + realm;
final String baseSamlEndpointUrl = realmUrl + "/protocol/saml";
String entityDescriptor = null;
RealmResource realmResource = testAdminClient.realm(realm);
ClientRepresentation clientRep = ClientBuilder.create().protocol(SamlProtocol.LOGIN_PROTOCOL).clientId(SAML_CLIENT_ID).enabled(true).attribute(SamlConfigAttributes.SAML_CLIENT_SIGNATURE_ATTRIBUTE, "false").redirectUris("http://foo.bar/").build();
try (Creator<ClientResource> c = Creator.create(realmResource, clientRep);
Creator<UserResource> u = Creator.create(realmResource, UserBuilder.create().username("bicycle").password("race").enabled(true).build())) {
SAMLDocumentHolder samlResponse = new SamlClientBuilder().authnRequest(new URI(baseSamlEndpointUrl), SAML_CLIENT_ID, "http://foo.bar/", Binding.POST).build().login().user("bicycle", "race").build().getSamlResponse(Binding.POST);
assertThat(samlResponse.getSamlObject(), org.keycloak.testsuite.util.Matchers.isSamlResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
ResponseType response = (ResponseType) samlResponse.getSamlObject();
assertThat(response.getAssertions(), hasSize(1));
assertThat(response.getAssertions().get(0).getAssertion().getIssuer().getValue(), is(realmUrl));
} catch (Exception e) {
log.errorf("Caught exception while parsing SAML descriptor %s", entityDescriptor);
}
}
use of org.keycloak.testsuite.util.SamlClientBuilder in project keycloak by keycloak.
the class SAMLServletAdapterTest method salesPostSigChangeContents.
@Test
public void salesPostSigChangeContents() {
UserRepresentation user = createUserRepresentation("bburke-additional-domain", "bburke@redhat.com.additional.domain", "Bill", "Burke", true);
setPasswordFor(user, PASSWORD);
String resultPage = new SamlClientBuilder().navigateTo(salesPostSigEmailServletPage.buildUri()).processSamlResponse(Binding.POST).build().login().user(user).build().processSamlResponse(Binding.POST).transformString(s -> {
Assert.assertThat(s, containsString(">bburke@redhat.com.additional.domain<"));
s = s.replaceAll("bburke@redhat.com.additional.domain", "bburke@redhat.com");
return s;
}).build().executeAndTransform(resp -> EntityUtils.toString(resp.getEntity()));
Assert.assertThat(resultPage, anyOf(containsString("INVALID_SIGNATURE"), // WAS
containsString("Error 403: SRVE0295E: Error reported: 403")));
}
use of org.keycloak.testsuite.util.SamlClientBuilder in project keycloak by keycloak.
the class SAMLServletAdapterTest method testNameIDUnset.
@Test
public void testNameIDUnset() throws Exception {
new SamlClientBuilder().navigateTo(employee2ServletPage.toString()).processSamlResponse(Binding.POST).build().login().user(bburkeUser).build().processSamlResponse(Binding.POST).transformDocument(responseDoc -> {
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//*[local-name()='NameID']");
NodeList nodeList = (NodeList) expr.evaluate(responseDoc, XPathConstants.NODESET);
Assert.assertThat(nodeList.getLength(), is(1));
final Node nameIdNode = nodeList.item(0);
nameIdNode.getParentNode().removeChild(nameIdNode);
return responseDoc;
}).build().navigateTo(employee2ServletPage.toString()).execute(r -> {
Assert.assertThat(r, statusCodeIsHC(Response.Status.OK));
Assert.assertThat(r, bodyHC(containsString("principal=")));
});
}
use of org.keycloak.testsuite.util.SamlClientBuilder in project keycloak by keycloak.
the class SAMLClockSkewAdapterTest method assertOutcome.
private void assertOutcome(int timeOffset, Matcher matcher) throws Exception {
try {
String resultPage = new SamlClientBuilder().navigateTo(salesPostClockSkewServletPage.toString()).processSamlResponse(POST).build().login().user(bburkeUser).build().processSamlResponse(POST).transformDocument(doc -> {
setAdapterAndServerTimeOffset(timeOffset, salesPostClockSkewServletPage.toString());
return doc;
}).build().executeAndTransform(resp -> EntityUtils.toString(resp.getEntity()));
Assert.assertThat(resultPage, matcher);
} finally {
setAdapterAndServerTimeOffset(0, salesPostClockSkewServletPage.toString());
}
}
Aggregations