Search in sources :

Example 16 with Saml2Authentication

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

the class OpenSamlLogoutRequestResolverTests method authentication.

private Saml2Authentication authentication(RelyingPartyRegistration registration) {
    DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", new HashMap<>(), Arrays.asList("session-index"));
    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 17 with Saml2Authentication

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

the class OpenSaml4AuthenticationProvider 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);
        AbstractAuthenticationToken authenticationResponse = this.responseAuthenticationConverter.convert(new ResponseToken(response, token));
        if (authenticationResponse != null) {
            authenticationResponse.setDetails(authentication.getDetails());
        }
        return authenticationResponse;
    } 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) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) XSString(org.opensaml.core.xml.schema.XSString) AuthenticationException(org.springframework.security.core.AuthenticationException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 18 with Saml2Authentication

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

the class OpenSamlAuthenticationProviderTests method createDefaultResponseAuthenticationConverterWhenResponseThenConverts.

@Test
public void createDefaultResponseAuthenticationConverterWhenResponseThenConverts() {
    Response response = TestOpenSamlObjects.signedResponseWithOneAssertion();
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    ResponseToken responseToken = new ResponseToken(response, token);
    Saml2Authentication authentication = OpenSamlAuthenticationProvider.createDefaultResponseAuthenticationConverter().convert(responseToken);
    assertThat(authentication.getName()).isEqualTo("test@saml.user");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseToken(org.springframework.security.saml2.provider.service.authentication.OpenSamlAuthenticationProvider.ResponseToken) Test(org.junit.jupiter.api.Test)

Example 19 with Saml2Authentication

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

the class OpenSaml4AuthenticationProviderTests method createDefaultResponseAuthenticationConverterWhenResponseThenConverts.

@Test
public void createDefaultResponseAuthenticationConverterWhenResponseThenConverts() {
    Response response = TestOpenSamlObjects.signedResponseWithOneAssertion();
    Saml2AuthenticationToken token = token(response, verifying(registration()));
    ResponseToken responseToken = new ResponseToken(response, token);
    Saml2Authentication authentication = OpenSaml4AuthenticationProvider.createDefaultResponseAuthenticationConverter().convert(responseToken);
    assertThat(authentication.getName()).isEqualTo("test@saml.user");
}
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)

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