Search in sources :

Example 61 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project spring-security by spring-projects.

the class OpenSamlAuthenticationRequestFactory method createAuthenticationRequest.

@Override
@Deprecated
public String createAuthenticationRequest(Saml2AuthenticationRequest request) {
    Saml2MessageBinding binding = this.protocolBindingResolver.convert(null);
    RelyingPartyRegistration registration = RelyingPartyRegistration.withRegistrationId("noId").assertionConsumerServiceBinding(binding).assertionConsumerServiceLocation(request.getAssertionConsumerServiceUrl()).entityId(request.getIssuer()).remoteIdpEntityId("noIssuer").idpWebSsoUrl("noUrl").credentials((credentials) -> credentials.addAll(request.getCredentials())).build();
    Saml2AuthenticationRequestContext context = Saml2AuthenticationRequestContext.builder().relyingPartyRegistration(registration).issuer(request.getIssuer()).assertionConsumerServiceUrl(request.getAssertionConsumerServiceUrl()).build();
    AuthnRequest authnRequest = this.authenticationRequestContextConverter.convert(context);
    return OpenSamlSigningUtils.serialize(OpenSamlSigningUtils.sign(authnRequest, registration));
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Converter(org.springframework.core.convert.converter.Converter) OpenSamlInitializationService(org.springframework.security.saml2.core.OpenSamlInitializationService) DateTime(org.joda.time.DateTime) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) ConfigurationService(org.opensaml.core.config.ConfigurationService) UUID(java.util.UUID) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) XMLObjectProviderRegistry(org.opensaml.core.xml.config.XMLObjectProviderRegistry) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) IssuerBuilder(org.opensaml.saml.saml2.core.impl.IssuerBuilder) Saml2MessageBinding(org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding) AuthnRequestBuilder(org.opensaml.saml.saml2.core.impl.AuthnRequestBuilder) Saml2ParameterNames(org.springframework.security.saml2.core.Saml2ParameterNames) Issuer(org.opensaml.saml.saml2.core.Issuer) Map(java.util.Map) Clock(java.time.Clock) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) QueryParametersPartial(org.springframework.security.saml2.provider.service.authentication.OpenSamlSigningUtils.QueryParametersPartial) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Saml2MessageBinding(org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)

Example 62 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project spring-security by spring-projects.

the class OpenSamlAuthenticationRequestFactory method createPostAuthenticationRequest.

@Override
public Saml2PostAuthenticationRequest createPostAuthenticationRequest(Saml2AuthenticationRequestContext context) {
    AuthnRequest authnRequest = this.authenticationRequestContextConverter.convert(context);
    RelyingPartyRegistration registration = context.getRelyingPartyRegistration();
    if (registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()) {
        OpenSamlSigningUtils.sign(authnRequest, registration);
    }
    String xml = OpenSamlSigningUtils.serialize(authnRequest);
    return Saml2PostAuthenticationRequest.withAuthenticationRequestContext(context).samlRequest(Saml2Utils.samlEncode(xml.getBytes(StandardCharsets.UTF_8))).build();
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest)

Example 63 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project spring-security by spring-projects.

the class OpenSamlAuthenticationRequestFactory method createRedirectAuthenticationRequest.

@Override
public Saml2RedirectAuthenticationRequest createRedirectAuthenticationRequest(Saml2AuthenticationRequestContext context) {
    AuthnRequest authnRequest = this.authenticationRequestContextConverter.convert(context);
    RelyingPartyRegistration registration = context.getRelyingPartyRegistration();
    String xml = OpenSamlSigningUtils.serialize(authnRequest);
    Saml2RedirectAuthenticationRequest.Builder result = Saml2RedirectAuthenticationRequest.withAuthenticationRequestContext(context);
    String deflatedAndEncoded = Saml2Utils.samlEncode(Saml2Utils.samlDeflate(xml));
    result.samlRequest(deflatedAndEncoded).relayState(context.getRelayState());
    if (registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()) {
        QueryParametersPartial partial = OpenSamlSigningUtils.sign(registration).param(Saml2ParameterNames.SAML_REQUEST, deflatedAndEncoded);
        if (StringUtils.hasText(context.getRelayState())) {
            partial.param(Saml2ParameterNames.RELAY_STATE, context.getRelayState());
        }
        Map<String, String> parameters = partial.parameters();
        return result.sigAlg(parameters.get(Saml2ParameterNames.SIG_ALG)).signature(parameters.get(Saml2ParameterNames.SIGNATURE)).build();
    }
    return result.build();
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) QueryParametersPartial(org.springframework.security.saml2.provider.service.authentication.OpenSamlSigningUtils.QueryParametersPartial) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest)

Example 64 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project spring-security by spring-projects.

the class TestOpenSamlObjects method authnRequest.

public static AuthnRequest authnRequest() {
    Issuer issuer = build(Issuer.DEFAULT_ELEMENT_NAME);
    issuer.setValue(ASSERTING_PARTY_ENTITY_ID);
    AuthnRequest authnRequest = build(AuthnRequest.DEFAULT_ELEMENT_NAME);
    authnRequest.setIssuer(issuer);
    authnRequest.setDestination(ASSERTING_PARTY_ENTITY_ID + "/SSO.saml2");
    authnRequest.setAssertionConsumerServiceURL(DESTINATION);
    return authnRequest;
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Issuer(org.opensaml.saml.saml2.core.Issuer)

Example 65 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project spring-security by spring-projects.

the class OpenSaml4AuthenticationRequestFactoryTests method createAuthenticationRequestWhenSetNameIDPolicyThenReturnsCorrectNameIDPolicy.

@Test
public void createAuthenticationRequestWhenSetNameIDPolicyThenReturnsCorrectNameIDPolicy() {
    RelyingPartyRegistration registration = TestRelyingPartyRegistrations.full().nameIdFormat("format").build();
    this.context = this.contextBuilder.relayState("Relay State Value").relyingPartyRegistration(registration).build();
    AuthnRequest authn = getAuthNRequest(Saml2MessageBinding.POST);
    assertThat(authn.getNameIDPolicy()).isNotNull();
    assertThat(authn.getNameIDPolicy().getAllowCreate()).isFalse();
    assertThat(authn.getNameIDPolicy().getFormat()).isEqualTo("format");
    assertThat(authn.getNameIDPolicy().getSPNameQualifier()).isNull();
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Test(org.junit.jupiter.api.Test)

Aggregations

AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)63 Test (org.junit.Test)11 Issuer (org.opensaml.saml.saml2.core.Issuer)10 Document (org.w3c.dom.Document)9 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)9 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)8 DateTime (org.joda.time.DateTime)7 IOException (java.io.IOException)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)6 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)6 XMLObject (org.opensaml.core.xml.XMLObject)6 MessageContext (org.opensaml.messaging.context.MessageContext)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Response (javax.ws.rs.core.Response)5 Assertion (org.jasig.cas.client.validation.Assertion)5 NameIDPolicy (org.opensaml.saml.saml2.core.NameIDPolicy)5 Element (org.w3c.dom.Element)5 QName (javax.xml.namespace.QName)4 AuthnContextClassRef (org.opensaml.saml.saml2.core.AuthnContextClassRef)4