Search in sources :

Example 1 with AbstractSaml2AuthenticationRequest

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

the class Saml2LoginConfigurerTests method authenticationRequestWhenCustomAuthnRequestRepositoryThenUses.

@Test
public void authenticationRequestWhenCustomAuthnRequestRepositoryThenUses() throws Exception {
    this.spring.register(CustomAuthenticationRequestRepository.class).autowire();
    MockHttpServletRequestBuilder request = get("/saml2/authenticate/registration-id");
    this.mvc.perform(request).andExpect(status().isFound());
    Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> repository = this.spring.getContext().getBean(Saml2AuthenticationRequestRepository.class);
    verify(repository).saveAuthenticationRequest(any(AbstractSaml2AuthenticationRequest.class), any(HttpServletRequest.class), any(HttpServletResponse.class));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 2 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method loadAuthenticationRequestWhenNoAttributeInSessionThenNull.

@Test
public void loadAuthenticationRequestWhenNoAttributeInSessionThenNull() {
    this.request.getSession();
    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 3 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method saveAuthenticationRequestWhenNullAuthenticationRequestThenDontSave.

@Test
public void saveAuthenticationRequestWhenNullAuthenticationRequestThenDontSave() {
    this.request.getSession();
    this.authenticationRequestRepository.saveAuthenticationRequest(null, this.request, this.response);
    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 4 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method removeAuthenticationRequestWhenValidSessionNoAttributeThenReturnsNull.

@Test
public void removeAuthenticationRequestWhenValidSessionNoAttributeThenReturnsNull() {
    MockHttpSession session = mock(MockHttpSession.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    AbstractSaml2AuthenticationRequest authenticationRequest = this.authenticationRequestRepository.removeAuthenticationRequest(request, this.response);
    verify(session).getAttribute(anyString());
    assertThat(authenticationRequest).isNull();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 5 with AbstractSaml2AuthenticationRequest

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

the class HttpSessionSaml2AuthenticationRequestRepositoryTests method saveAuthenticationRequestWhenSessionDontExistsThenCreateAndSave.

@Test
public void saveAuthenticationRequestWhenSessionDontExistsThenCreateAndSave() {
    AbstractSaml2AuthenticationRequest mockAuthenticationRequest = mock(AbstractSaml2AuthenticationRequest.class);
    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)

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