Search in sources :

Example 21 with Saml2LogoutRequest

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

the class HttpSessionLogoutRequestRepositoryTests method loadLogoutRequestWhenNotSavedThenReturnNull.

@Test
public void loadLogoutRequestWhenNotSavedThenReturnNull() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(Saml2ParameterNames.RELAY_STATE, "state-1234");
    Saml2LogoutRequest logoutRequest = this.logoutRequestRepository.loadLogoutRequest(request);
    assertThat(logoutRequest).isNull();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) Test(org.junit.jupiter.api.Test)

Example 22 with Saml2LogoutRequest

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

the class HttpSessionLogoutRequestRepositoryTests method loadLogoutRequestWhenSavedThenReturnLogoutRequest.

@Test
public void loadLogoutRequestWhenSavedThenReturnLogoutRequest() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    Saml2LogoutRequest logoutRequest = createLogoutRequest().build();
    this.logoutRequestRepository.saveLogoutRequest(logoutRequest, request, response);
    request.addParameter(Saml2ParameterNames.RELAY_STATE, logoutRequest.getRelayState());
    Saml2LogoutRequest loadedLogoutRequest = this.logoutRequestRepository.loadLogoutRequest(request);
    assertThat(loadedLogoutRequest).isEqualTo(logoutRequest);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 23 with Saml2LogoutRequest

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

the class HttpSessionLogoutRequestRepositoryTests method saveLogoutRequestWhenNoExistingSessionAndDistributedSessionThenSaved.

@Test
public void saveLogoutRequestWhenNoExistingSessionAndDistributedSessionThenSaved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockDistributedHttpSession());
    Saml2LogoutRequest logoutRequest = createLogoutRequest().build();
    this.logoutRequestRepository.saveLogoutRequest(logoutRequest, request, new MockHttpServletResponse());
    request.addParameter(Saml2ParameterNames.RELAY_STATE, logoutRequest.getRelayState());
    Saml2LogoutRequest loadedLogoutRequest = this.logoutRequestRepository.loadLogoutRequest(request);
    assertThat(loadedLogoutRequest).isEqualTo(logoutRequest);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 24 with Saml2LogoutRequest

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

the class HttpSessionLogoutRequestRepositoryTests method saveLogoutRequestWhenExistingSessionAndDistributedSessionThenSaved.

@Test
public void saveLogoutRequestWhenExistingSessionAndDistributedSessionThenSaved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockDistributedHttpSession());
    Saml2LogoutRequest logoutRequest1 = createLogoutRequest().build();
    this.logoutRequestRepository.saveLogoutRequest(logoutRequest1, request, new MockHttpServletResponse());
    Saml2LogoutRequest logoutRequest2 = createLogoutRequest().build();
    this.logoutRequestRepository.saveLogoutRequest(logoutRequest2, request, new MockHttpServletResponse());
    request.addParameter(Saml2ParameterNames.RELAY_STATE, logoutRequest2.getRelayState());
    Saml2LogoutRequest loadedLogoutRequest = this.logoutRequestRepository.loadLogoutRequest(request);
    assertThat(loadedLogoutRequest).isEqualTo(logoutRequest2);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 25 with Saml2LogoutRequest

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

the class HttpSessionLogoutRequestRepositoryTests method removeLogoutRequestWhenNotSavedThenNotRemoved.

@Test
public void removeLogoutRequestWhenNotSavedThenNotRemoved() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(Saml2ParameterNames.RELAY_STATE, "state-1234");
    MockHttpServletResponse response = new MockHttpServletResponse();
    Saml2LogoutRequest removedLogoutRequest = this.logoutRequestRepository.removeLogoutRequest(request, response);
    assertThat(removedLogoutRequest).isNull();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)40 Saml2LogoutRequest (org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest)34 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)31 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)27 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)22 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)15 Authentication (org.springframework.security.core.Authentication)12 Saml2MessageBinding (org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)10 Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)10 TestRelyingPartyRegistrations (org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations)10 StandardCharsets (java.nio.charset.StandardCharsets)9 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 BDDMockito.given (org.mockito.BDDMockito.given)8 Saml2ParameterNames (org.springframework.security.saml2.core.Saml2ParameterNames)7 DefaultSaml2AuthenticatedPrincipal (org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)7 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 AfterEach (org.junit.jupiter.api.AfterEach)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5