Search in sources :

Example 16 with Saml2LogoutResponse

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

the class OpenSaml4LogoutResponseResolverTests method resolveWhenCustomParametersConsumerThenUses.

@Test
public void resolveWhenCustomParametersConsumerThenUses() {
    OpenSaml4LogoutResponseResolver logoutResponseResolver = new OpenSaml4LogoutResponseResolver(this.relyingPartyRegistrationResolver);
    Consumer<LogoutResponseParameters> parametersConsumer = mock(Consumer.class);
    logoutResponseResolver.setParametersConsumer(parametersConsumer);
    MockHttpServletRequest request = new MockHttpServletRequest();
    RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration().assertingPartyDetails((party) -> party.singleLogoutServiceResponseLocation("https://ap.example.com/logout")).build();
    Authentication authentication = new TestingAuthenticationToken("user", "password");
    LogoutRequest logoutRequest = TestOpenSamlObjects.assertingPartyLogoutRequest(registration);
    request.setParameter(Saml2ParameterNames.SAML_REQUEST, Saml2Utils.samlEncode(OpenSamlSigningUtils.serialize(logoutRequest).getBytes()));
    given(this.relyingPartyRegistrationResolver.resolve(any(), any())).willReturn(registration);
    Saml2LogoutResponse logoutResponse = logoutResponseResolver.resolve(request, authentication);
    assertThat(logoutResponse).isNotNull();
    verify(parametersConsumer).accept(any());
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) RelyingPartyRegistrationResolver(org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutResponse(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) TestOpenSamlObjects(org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) Saml2ParameterNames(org.springframework.security.saml2.core.Saml2ParameterNames) BDDMockito.given(org.mockito.BDDMockito.given) LogoutResponseParameters(org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver.LogoutResponseParameters) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Authentication(org.springframework.security.core.Authentication) TestRelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations) Mockito.mock(org.mockito.Mockito.mock) LogoutResponseParameters(org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver.LogoutResponseParameters) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Authentication(org.springframework.security.core.Authentication) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) Saml2LogoutResponse(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Aggregations

RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)16 Test (org.junit.jupiter.api.Test)12 Saml2LogoutResponse (org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse)10 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)9 Authentication (org.springframework.security.core.Authentication)8 Saml2ParameterNames (org.springframework.security.saml2.core.Saml2ParameterNames)8 Saml2MessageBinding (org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)7 RelyingPartyRegistrationResolver (org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver)7 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 StandardCharsets (java.nio.charset.StandardCharsets)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 BDDMockito.given (org.mockito.BDDMockito.given)4 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)4 TestRelyingPartyRegistrations (org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3 Mockito.mock (org.mockito.Mockito.mock)3