Search in sources :

Example 11 with Saml2Authentication

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

the class Saml2LogoutConfigurerTests method saml2LogoutRequestWhenDefaultsThenLogsOutAndSendsLogoutResponse.

@Test
public void saml2LogoutRequestWhenDefaultsThenLogsOutAndSendsLogoutResponse() throws Exception {
    this.spring.register(Saml2LogoutDefaultsConfig.class).autowire();
    DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", Collections.emptyMap());
    principal.setRelyingPartyRegistrationId("get");
    Saml2Authentication user = new Saml2Authentication(principal, "response", AuthorityUtils.createAuthorityList("ROLE_USER"));
    MvcResult result = this.mvc.perform(get("/logout/saml2/slo").param("SAMLRequest", this.apLogoutRequest).param("RelayState", this.apLogoutRequestRelayState).param("SigAlg", this.apLogoutRequestSigAlg).param("Signature", this.apLogoutRequestSignature).with(authentication(user))).andExpect(status().isFound()).andReturn();
    String location = result.getResponse().getHeader("Location");
    assertThat(location).startsWith("https://ap.example.org/logout/saml2/response");
    verify(getBean(LogoutHandler.class)).logout(any(), any(), any());
}
Also used : Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) DefaultSaml2AuthenticatedPrincipal(org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal) Matchers.containsString(org.hamcrest.Matchers.containsString) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 12 with Saml2Authentication

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

the class OpenSaml4AuthenticationProviderTests method authenticateWhenResponseAuthenticationConverterConfiguredThenUses.

@Test
public void authenticateWhenResponseAuthenticationConverterConfiguredThenUses() {
    Converter<ResponseToken, Saml2Authentication> authenticationConverter = mock(Converter.class);
    OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
    provider.setResponseAuthenticationConverter(authenticationConverter);
    Response response = TestOpenSamlObjects.signedResponseWithOneAssertion();
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    provider.authenticate(token);
    verify(authenticationConverter).convert(any());
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseToken(org.springframework.security.saml2.provider.service.authentication.OpenSaml4AuthenticationProvider.ResponseToken) Test(org.junit.jupiter.api.Test)

Example 13 with Saml2Authentication

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

the class OpenSamlAuthenticationProvider method authenticate.

/**
 * @param authentication the authentication request object, must be of type
 * {@link Saml2AuthenticationToken}
 * @return {@link Saml2Authentication} if the assertion is valid
 * @throws AuthenticationException if a validation exception occurs
 */
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    try {
        Saml2AuthenticationToken token = (Saml2AuthenticationToken) authentication;
        String serializedResponse = token.getSaml2Response();
        Response response = parse(serializedResponse);
        process(token, response);
        return this.responseAuthenticationConverter.convert(new ResponseToken(response, token));
    } catch (Saml2AuthenticationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw createAuthenticationException(Saml2ErrorCodes.INTERNAL_VALIDATION_ERROR, ex.getMessage(), ex);
    }
}
Also used : Response(org.opensaml.saml.saml2.core.Response) XSString(org.opensaml.core.xml.schema.XSString) AuthenticationException(org.springframework.security.core.AuthenticationException) AssertionValidationException(org.opensaml.saml.common.assertion.AssertionValidationException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 14 with Saml2Authentication

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

the class OpenSamlLogoutResponseResolverTests method authentication.

private Saml2Authentication authentication(RelyingPartyRegistration registration) {
    DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", new HashMap<>());
    principal.setRelyingPartyRegistrationId(registration.getRegistrationId());
    return new Saml2Authentication(principal, "response", new ArrayList<>());
}
Also used : Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) DefaultSaml2AuthenticatedPrincipal(org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)

Example 15 with Saml2Authentication

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

the class Saml2RelyingPartyInitiatedLogoutSuccessHandlerTests method authentication.

private Saml2Authentication authentication(RelyingPartyRegistration registration) {
    DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", new HashMap<>());
    principal.setRelyingPartyRegistrationId(registration.getRegistrationId());
    return new Saml2Authentication(principal, "response", new ArrayList<>());
}
Also used : Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) DefaultSaml2AuthenticatedPrincipal(org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)

Aggregations

Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)13 DefaultSaml2AuthenticatedPrincipal (org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)11 Test (org.junit.jupiter.api.Test)9 Response (org.opensaml.saml.saml2.core.Response)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 Saml2Exception (org.springframework.security.saml2.Saml2Exception)3 Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 List (java.util.List)2 XSString (org.opensaml.core.xml.schema.XSString)2 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)2 ResponseToken (org.springframework.security.saml2.provider.service.authentication.OpenSaml4AuthenticationProvider.ResponseToken)2 ResponseToken (org.springframework.security.saml2.provider.service.authentication.OpenSamlAuthenticationProvider.ResponseToken)2 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)2 Saml2LogoutRequest (org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest)2 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)2 Saml2MessageBinding (org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)2 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)1 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)1