Search in sources :

Example 21 with AbstractSaml2AuthenticationRequest

use of org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest in project spring-security by spring-projects.

the class OpenSaml4AuthenticationRequestFactoryTests method getAuthNRequest.

private AuthnRequest getAuthNRequest(Saml2MessageBinding binding) {
    AbstractSaml2AuthenticationRequest result = (binding == Saml2MessageBinding.REDIRECT) ? this.factory.createRedirectAuthenticationRequest(this.context) : this.factory.createPostAuthenticationRequest(this.context);
    String samlRequest = result.getSamlRequest();
    assertThat(samlRequest).isNotEmpty();
    if (result.getBinding() == Saml2MessageBinding.REDIRECT) {
        samlRequest = Saml2Utils.samlInflate(Saml2Utils.samlDecode(samlRequest));
    } else {
        samlRequest = new String(Saml2Utils.samlDecode(samlRequest), StandardCharsets.UTF_8);
    }
    try {
        Document document = XMLObjectProviderRegistrySupport.getParserPool().parse(new ByteArrayInputStream(samlRequest.getBytes(StandardCharsets.UTF_8)));
        Element element = document.getDocumentElement();
        return (AuthnRequest) this.unmarshaller.unmarshall(element);
    } catch (Exception ex) {
        throw new Saml2Exception(ex);
    }
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException)

Aggregations

AbstractSaml2AuthenticationRequest (org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest)17 Test (org.junit.jupiter.api.Test)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)3 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Saml2Exception (org.springframework.security.saml2.Saml2Exception)2 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)2 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)2 Saml2AuthenticationTokenConverter (org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter)2 AuthenticationConverter (org.springframework.security.web.authentication.AuthenticationConverter)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 HttpSession (jakarta.servlet.http.HttpSession)1 Issuer (org.opensaml.saml.saml2.core.Issuer)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1