Search in sources :

Example 16 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method removeAuthenticationRequestWhenAttributeInSessionThenRemoveAuthenticationRequest.

@Test
public void removeAuthenticationRequestWhenAttributeInSessionThenRemoveAuthenticationRequest() {
    AbstractSaml2AuthenticationRequest mockAuthenticationRequest = mock(AbstractSaml2AuthenticationRequest.class);
    given(mockAuthenticationRequest.getAuthenticationRequestUri()).willReturn(IDP_SSO_URL);
    this.request.getSession();
    this.authenticationRequestRepository.saveAuthenticationRequest(mockAuthenticationRequest, this.request, this.response);
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.removeAuthenticationRequest(this.request, this.response);
    AbstractSaml2AuthenticationRequest authenticationRequestAfterRemove = this.authenticationRequestRepository.loadAuthenticationRequest(this.request);
    assertThat(authenticationRequest.getAuthenticationRequestUri()).isEqualTo(IDP_SSO_URL);
    assertThat(authenticationRequestAfterRemove).isNull();
}
Also used : AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 17 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method saveAuthenticationRequestWhenSessionExistsThenSave.

@Test
public void saveAuthenticationRequestWhenSessionExistsThenSave() {
    AbstractSaml2AuthenticationRequest mockAuthenticationRequest = mock(AbstractSaml2AuthenticationRequest.class);
    this.request.getSession();
    this.authenticationRequestRepository.saveAuthenticationRequest(mockAuthenticationRequest, this.request, this.response);
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.loadAuthenticationRequest(this.request);
    assertThat(authenticationRequest).isNotNull();
}
Also used : AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 18 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method loadAuthenticationRequestWhenInvalidSessionThenNull.

@Test
public void loadAuthenticationRequestWhenInvalidSessionThenNull() {
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.loadAuthenticationRequest(this.request);
    assertThat(authenticationRequest).isNull();
}
Also used : AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 19 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method loadAuthenticationRequestWhenAttributeInSessionThenReturnsAuthenticationRequest.

@Test
public void loadAuthenticationRequestWhenAttributeInSessionThenReturnsAuthenticationRequest() {
    AbstractSaml2AuthenticationRequest mockAuthenticationRequest = mock(AbstractSaml2AuthenticationRequest.class);
    given(mockAuthenticationRequest.getAuthenticationRequestUri()).willReturn(IDP_SSO_URL);
    this.request.getSession();
    this.authenticationRequestRepository.saveAuthenticationRequest(mockAuthenticationRequest, this.request, this.response);
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.loadAuthenticationRequest(this.request);
    assertThat(authenticationRequest.getAuthenticationRequestUri()).isEqualTo(IDP_SSO_URL);
}
Also used : AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 20 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method removeAuthenticationRequestWhenInvalidSessionThenReturnNull.

@Test
public void removeAuthenticationRequestWhenInvalidSessionThenReturnNull() {
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.removeAuthenticationRequest(this.request, this.response);
    assertThat(authenticationRequest).isNull();
}
Also used : AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

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