use of org.keycloak.dom.saml.v2.protocol.NameIDPolicyType in project keycloak by keycloak.
the class AuthnRequestNameIdFormatTest method testPostLoginNameIdPolicyPersistent.
@Test
public void testPostLoginNameIdPolicyPersistent() throws Exception {
NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.getUri());
testLoginWithNameIdPolicy(Binding.POST, Binding.POST, nameIdPolicy, startsWith("G-"));
}
use of org.keycloak.dom.saml.v2.protocol.NameIDPolicyType in project keycloak by keycloak.
the class AuthnRequestNameIdFormatTest method testRedirectLoginNameIdPolicyPersistent.
@Test
public void testRedirectLoginNameIdPolicyPersistent() throws Exception {
NameIDPolicyType nameIdPolicy = new NameIDPolicyType();
nameIdPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.getUri());
testLoginWithNameIdPolicy(Binding.REDIRECT, Binding.REDIRECT, nameIdPolicy, startsWith("G-"));
}
use of org.keycloak.dom.saml.v2.protocol.NameIDPolicyType in project keycloak by keycloak.
the class BrokerTest method testLogoutPropagatesToSamlIdentityProvider.
@Test
public void testLogoutPropagatesToSamlIdentityProvider() throws IOException {
final RealmResource realm = adminClient.realm(REALM_NAME);
final ClientsResource clients = realm.clients();
AuthenticationExecutionInfoRepresentation reviewProfileAuthenticator = null;
String firstBrokerLoginFlowAlias = null;
try (IdentityProviderCreator idp = new IdentityProviderCreator(realm, addIdentityProvider("https://saml.idp/saml"))) {
IdentityProviderRepresentation idpRepresentation = idp.identityProvider().toRepresentation();
firstBrokerLoginFlowAlias = idpRepresentation.getFirstBrokerLoginFlowAlias();
List<AuthenticationExecutionInfoRepresentation> executions = realm.flows().getExecutions(firstBrokerLoginFlowAlias);
reviewProfileAuthenticator = executions.stream().filter(ex -> Objects.equals(ex.getProviderId(), IdpReviewProfileAuthenticatorFactory.PROVIDER_ID)).findFirst().orElseGet(() -> {
Assert.fail("Could not find update profile in first broker login flow");
return null;
});
reviewProfileAuthenticator.setRequirement(Requirement.DISABLED.name());
realm.flows().updateExecutions(firstBrokerLoginFlowAlias, reviewProfileAuthenticator);
SAMLDocumentHolder samlResponse = new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, POST).transformObject(ar -> {
NameIDPolicyType nameIDPolicy = new NameIDPolicyType();
nameIDPolicy.setAllowCreate(Boolean.TRUE);
nameIDPolicy.setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_EMAIL.getUri());
ar.setNameIDPolicy(nameIDPolicy);
return ar;
}).build().login().idp(SAML_BROKER_ALIAS).build().processSamlResponse(REDIRECT).transformObject(this::createAuthnResponse).targetAttributeSamlResponse().targetUri(getSamlBrokerUrl(REALM_NAME)).build().followOneRedirect().followOneRedirect().getSamlResponse(POST);
assertThat(samlResponse.getSamlObject(), isSamlStatusResponse(JBossSAMLURIConstants.STATUS_RESPONDER, JBossSAMLURIConstants.STATUS_INVALID_NAMEIDPOLICY));
} finally {
reviewProfileAuthenticator.setRequirement(Requirement.REQUIRED.name());
realm.flows().updateExecutions(firstBrokerLoginFlowAlias, reviewProfileAuthenticator);
}
}
use of org.keycloak.dom.saml.v2.protocol.NameIDPolicyType in project unity by unity-idm.
the class SAMLHelper method createSAMLRequest.
public static AuthnRequestDocument createSAMLRequest(String responseConsumerAddress, boolean sign, String requestrId, String identityProviderURL, String requestedNameFormat, boolean allowCreate, X509Credential credential) throws InternalException {
NameID issuer = new NameID(requestrId, SAMLConstants.NFORMAT_ENTITY);
AuthnRequest request = new AuthnRequest(issuer.getXBean());
if (requestedNameFormat != null)
request.setFormat(requestedNameFormat);
if (allowCreate) {
NameIDPolicyType policy = request.getXMLBean().getNameIDPolicy();
if (policy == null)
policy = request.getXMLBean().addNewNameIDPolicy();
policy.setAllowCreate(true);
}
if (identityProviderURL != null)
request.getXMLBean().setDestination(identityProviderURL);
request.getXMLBean().setAssertionConsumerServiceURL(responseConsumerAddress);
if (sign) {
try {
request.sign(credential.getKey(), credential.getCertificateChain());
} catch (Exception e) {
throw new InternalException("Can't sign request", e);
}
}
return request.getXMLBeanDoc();
}
Aggregations