Search in sources :

Example 1 with Saml2AuthenticationRequestRepository

use of org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository 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 Saml2AuthenticationRequestRepository

use of org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository in project spring-security by spring-projects.

the class Saml2WebSsoAuthenticationFilterTests method setAuthenticationRequestRepositoryWhenNotExpectedAuthenticationConverterTypeThenDoNotSet.

@Test
public void setAuthenticationRequestRepositoryWhenNotExpectedAuthenticationConverterTypeThenDoNotSet() {
    AuthenticationConverter authenticationConverter = mock(AuthenticationConverter.class);
    Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository = mock(Saml2AuthenticationRequestRepository.class);
    this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}");
    this.filter.setAuthenticationRequestRepository(authenticationRequestRepository);
    verifyNoInteractions(authenticationConverter);
}
Also used : AuthenticationConverter(org.springframework.security.web.authentication.AuthenticationConverter) AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 3 with Saml2AuthenticationRequestRepository

use of org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository in project spring-security by spring-projects.

the class Saml2WebSsoAuthenticationFilterTests method setAuthenticationRequestRepositoryWhenExpectedAuthenticationConverterTypeThenSetLoaderIntoConverter.

@Test
public void setAuthenticationRequestRepositoryWhenExpectedAuthenticationConverterTypeThenSetLoaderIntoConverter() {
    Saml2AuthenticationTokenConverter authenticationConverter = mock(Saml2AuthenticationTokenConverter.class);
    Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository = mock(Saml2AuthenticationRequestRepository.class);
    this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, "/some/other/path/{registrationId}");
    this.filter.setAuthenticationRequestRepository(authenticationRequestRepository);
    verify(authenticationConverter).setAuthenticationRequestRepository(authenticationRequestRepository);
}
Also used : Saml2AuthenticationTokenConverter(org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter) AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Test(org.junit.jupiter.api.Test)

Example 4 with Saml2AuthenticationRequestRepository

use of org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository in project spring-security by spring-projects.

the class Saml2AuthenticationTokenConverterTests method convertWhenSavedAuthenticationRequestThenToken.

@Test
public void convertWhenSavedAuthenticationRequestThenToken() {
    Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository = mock(Saml2AuthenticationRequestRepository.class);
    AbstractSaml2AuthenticationRequest authenticationRequest = mock(AbstractSaml2AuthenticationRequest.class);
    Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(this.relyingPartyRegistrationResolver);
    converter.setAuthenticationRequestRepository(authenticationRequestRepository);
    given(this.relyingPartyRegistrationResolver.convert(any(HttpServletRequest.class))).willReturn(this.relyingPartyRegistration);
    given(authenticationRequestRepository.loadAuthenticationRequest(any(HttpServletRequest.class))).willReturn(authenticationRequest);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(Saml2ParameterNames.SAML_RESPONSE, Saml2Utils.samlEncode("response".getBytes(StandardCharsets.UTF_8)));
    Saml2AuthenticationToken token = converter.convert(request);
    assertThat(token.getSaml2Response()).isEqualTo("response");
    assertThat(token.getRelyingPartyRegistration().getRegistrationId()).isEqualTo(this.relyingPartyRegistration.getRegistrationId());
    assertThat(token.getAuthenticationRequest()).isEqualTo(authenticationRequest);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AbstractSaml2AuthenticationRequest(org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest) Saml2AuthenticationToken(org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 5 with Saml2AuthenticationRequestRepository

use of org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository in project spring-security by spring-projects.

the class Saml2LoginConfigurerTests method authenticateWhenCustomAuthnRequestRepositoryThenUses.

@Test
public void authenticateWhenCustomAuthnRequestRepositoryThenUses() throws Exception {
    this.spring.register(CustomAuthenticationRequestRepository.class).autowire();
    MockHttpServletRequestBuilder request = post("/login/saml2/sso/registration-id").param("SAMLResponse", SIGNED_RESPONSE);
    Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> repository = this.spring.getContext().getBean(Saml2AuthenticationRequestRepository.class);
    this.mvc.perform(request);
    verify(repository).loadAuthenticationRequest(any(HttpServletRequest.class));
    verify(repository).removeAuthenticationRequest(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)

Aggregations

Test (org.junit.jupiter.api.Test)6 AbstractSaml2AuthenticationRequest (org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest)6 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)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 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)1