use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.
the class BasicSamlTest method testIsPassiveAttributeOmittedWhenFalse.
@Test
public void testIsPassiveAttributeOmittedWhenFalse() throws Exception {
// Verifies that the IsPassive attribute is not emitted in the authnRequest
// when it is set to false
// Build the login request document
AuthnRequestType loginRep = SamlClient.createLoginRequestDocument(SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, getAuthServerSamlEndpoint(REALM_NAME));
loginRep.setIsPassive(false);
Document document = SAML2Request.convert(loginRep);
// Find the AuthnRequest element
Element authnRequestElement = document.getDocumentElement();
Attr isPassiveAttribute = authnRequestElement.getAttributeNode("IsPassive");
assertThat("AuthnRequest element shouldn't contain the IsPassive attribute when isPassive is false, but it does", isPassiveAttribute, nullValue());
}
use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType 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));
}
}
use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.
the class SAMLParserTest method testAuthnRequestOptionalIsPassive.
// https://issues.jboss.org/browse/KEYCLOAK-7316
@Test
public void testAuthnRequestOptionalIsPassive() throws Exception {
AuthnRequestType req = assertParsed("KEYCLOAK-7316-noAtrributes.xml", AuthnRequestType.class);
assertThat("Not null!", req.isIsPassive(), nullValue());
assertThat("Not null!", req.isForceAuthn(), nullValue());
req = assertParsed("KEYCLOAK-7316-withTrueAttributes.xml", AuthnRequestType.class);
assertThat(req.isIsPassive(), notNullValue());
assertTrue("Wrong value!", req.isIsPassive().booleanValue());
assertThat(req.isForceAuthn(), notNullValue());
assertTrue("Wrong value!", req.isForceAuthn().booleanValue());
req = assertParsed("KEYCLOAK-7316-withFalseAttributes.xml", AuthnRequestType.class);
assertThat(req.isIsPassive(), notNullValue());
assertFalse("Wrong value!", req.isIsPassive().booleanValue());
assertThat(req.isForceAuthn(), notNullValue());
assertFalse("Wrong value!", req.isForceAuthn().booleanValue());
}
use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.
the class SAMLParserTest method testAuthnRequest.
@Test
public void testAuthnRequest() throws Exception {
AuthnRequestType req = assertParsed("saml20-authnrequest.xml", AuthnRequestType.class);
assertThat(req.getRequestedAuthnContext(), notNullValue());
assertThat(req.getRequestedAuthnContext().getAuthnContextClassRef(), hasItem(is("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport")));
assertThat(req.getRequestedAuthnContext().getAuthnContextDeclRef(), hasItem(is("urn:kc:SAML:2.0:ac:ref:demo:decl")));
}
use of org.keycloak.dom.saml.v2.protocol.AuthnRequestType in project keycloak by keycloak.
the class SamlClient method createLoginRequestDocument.
/**
* Creates a SAML login request document with the given parameters. See SAML <AuthnRequest> description for more details.
*
* @param issuer
* @param assertionConsumerURL
* @param destination
* @return
*/
public static AuthnRequestType createLoginRequestDocument(String issuer, String assertionConsumerURL, URI destination) {
try {
SAML2Request samlReq = new SAML2Request();
AuthnRequestType loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(), assertionConsumerURL, destination == null ? null : destination.toString(), issuer);
return loginReq;
} catch (ConfigurationException ex) {
throw new RuntimeException(ex);
}
}
Aggregations