use of org.keycloak.testsuite.util.SamlClient in project keycloak by keycloak.
the class BasicSamlTest method testReauthnWithForceAuthn.
private void testReauthnWithForceAuthn(Boolean reloginRequired) throws Exception {
// Ensure that the first authentication passes
SamlClient samlClient = new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, Binding.POST).build().login().user(bburkeUser).build().execute(hr -> {
try {
SAMLDocumentHolder doc = Binding.POST.extractResponse(hr);
assertThat(doc.getSamlObject(), Matchers.isSamlStatusResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
} catch (IOException ex) {
Logger.getLogger(BasicSamlTest.class.getName()).log(Level.SEVERE, null, ex);
}
});
List<Step> secondAuthn = new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST2, SAML_ASSERTION_CONSUMER_URL_SALES_POST2, Binding.POST).transformObject(so -> {
so.setForceAuthn(reloginRequired);
return so;
}).build().assertResponse(Matchers.bodyHC(containsString(Objects.equals(reloginRequired, Boolean.TRUE) ? "Sign in" : GeneralConstants.SAML_RESPONSE_KEY))).getSteps();
samlClient.execute(secondAuthn);
}
use of org.keycloak.testsuite.util.SamlClient in project keycloak by keycloak.
the class SamlRelayStateTest method relayStateConcurrencyTest.
@Test
@Ignore("KEYCLOAK-5179")
public void relayStateConcurrencyTest() throws Exception {
ThreadLocal<UUID> tl = new ThreadLocal<>();
List<SamlClient.Step> steps = new SamlClientBuilder().addStep(() -> tl.set(UUID.randomUUID())).authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, SamlClient.Binding.POST).relayState(() -> tl.get().toString()).build().login().user(bburkeUser).build().assertSamlRelayState(SamlClient.Binding.POST, relayState -> {
assertThat(relayState, is(notNullValue()));
assertThat(relayState, is(equalTo(tl.get().toString())));
}).getSteps();
SamlClient client = new SamlClient();
client.execute(steps);
// removing login as it should not be necessary anymore
steps.remove(2);
AbstractConcurrencyTest.run(2, 10, this, (threadIndex, keycloak, realm) -> {
client.execute(steps);
});
}
use of org.keycloak.testsuite.util.SamlClient in project keycloak by keycloak.
the class AbstractSAMLAdapterClusteredTest method testLogoutViaSessionIndex.
private void testLogoutViaSessionIndex(URL employeeUrl, boolean forceRefreshAtOtherNode, BiConsumer<SamlClientBuilder, String> logoutFunction) {
setPasswordFor(bburkeUser, CredentialRepresentation.PASSWORD);
String employeeUrlString = getProxiedUrl(employeeUrl);
SamlClientBuilder builder = new SamlClientBuilder().navigateTo(employeeUrlString).processSamlResponse(Binding.POST).build().login().user(bburkeUser).build().processSamlResponse(Binding.POST).build().assertResponse(Matchers.bodyHC(containsString("principal=bburke"))).addStep(() -> updateProxy(NODE_2_NAME, NODE_2_URI, NODE_1_URI));
if (forceRefreshAtOtherNode) {
// Go to employee URL at reverse proxy which is set to forward to _second_ node now
builder.navigateTo(employeeUrlString).doNotFollowRedirects().assertResponse(Matchers.bodyHC(containsString("principal=bburke")));
}
// Logout at the _second_ node
logoutFunction.accept(builder, employeeUrlString);
SamlClient samlClient = builder.execute();
delayedCheckLoggedOut(samlClient, employeeUrlString);
// Update the proxy to forward to the first node.
updateProxy(NODE_1_NAME, NODE_1_URI, NODE_2_URI);
delayedCheckLoggedOut(samlClient, employeeUrlString);
}
use of org.keycloak.testsuite.util.SamlClient in project keycloak by keycloak.
the class AbstractSAMLAdapterClusteredTest method testNodeRestartResiliency.
@Test
public void testNodeRestartResiliency(@ArquillianResource @OperateOnDeployment(value = EmployeeServletDistributable.DEPLOYMENT_NAME) URL employeeUrl) throws Exception {
ContainerInfo containerInfo = testContext.getAppServerBackendsInfo().get(0);
setPasswordFor(bburkeUser, CredentialRepresentation.PASSWORD);
String employeeUrlString = getProxiedUrl(employeeUrl);
SamlClient samlClient = new SamlClientBuilder().navigateTo(employeeUrlString).processSamlResponse(Binding.POST).build().login().user(bburkeUser).build().processSamlResponse(Binding.POST).build().assertResponse(Matchers.bodyHC(containsString("principal=bburke"))).execute();
controller.stop(containerInfo.getQualifier());
// Update the proxy to forward to the second node.
updateProxy(NODE_2_NAME, NODE_2_URI, NODE_1_URI);
samlClient.execute(new SamlClientBuilder().navigateTo(employeeUrlString).doNotFollowRedirects().assertResponse(Matchers.bodyHC(containsString("principal=bburke"))).getSteps());
controller.start(containerInfo.getQualifier());
// Update the proxy to forward to the first node.
updateProxy(NODE_1_NAME, NODE_1_URI, NODE_2_URI);
samlClient.execute(new SamlClientBuilder().navigateTo(employeeUrlString).doNotFollowRedirects().assertResponse(Matchers.bodyHC(containsString("principal=bburke"))).getSteps());
}
use of org.keycloak.testsuite.util.SamlClient in project keycloak by keycloak.
the class SamlRedirectBindingTest method testQueryParametersInSamlProcessingUriRedirectWithSignature.
@Test
public void testQueryParametersInSamlProcessingUriRedirectWithSignature() throws Exception {
SamlClient samlClient = new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST_SIG, SAML_ASSERTION_CONSUMER_URL_SALES_POST_SIG + "?param1=value1¶m2=value2", Binding.REDIRECT).signWith(SAML_CLIENT_SALES_POST_SIG_PRIVATE_KEY, SAML_CLIENT_SALES_POST_SIG_PUBLIC_KEY).build().login().user(bburkeUser).build().doNotFollowRedirects().execute(hr -> {
try {
// obtain the document validating the signature (it should be valid)
SAMLDocumentHolder doc = Binding.REDIRECT.extractResponse(hr, REALM_PUBLIC_KEY);
// assert doc is OK and the destination really has the extra parameters
assertThat(doc.getSamlObject(), isSamlStatusResponse(JBossSAMLURIConstants.STATUS_SUCCESS));
assertThat(doc.getSamlObject(), instanceOf(ResponseType.class));
ResponseType res = (ResponseType) doc.getSamlObject();
assertThat(res.getDestination(), is(SAML_ASSERTION_CONSUMER_URL_SALES_POST_SIG + "?param1=value1¶m2=value2"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
});
}
Aggregations