Search in sources :

Example 6 with DefaultSaml2AuthenticatedPrincipal

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

the class Saml2LogoutConfigurerTests method saml2LogoutWhenNoRegistrationThen401.

@Test
public void saml2LogoutWhenNoRegistrationThen401() throws Exception {
    this.spring.register(Saml2LogoutDefaultsConfig.class).autowire();
    DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", Collections.emptyMap());
    principal.setRelyingPartyRegistrationId("wrong");
    Saml2Authentication authentication = new Saml2Authentication(principal, "response", AuthorityUtils.createAuthorityList("ROLE_USER"));
    this.mvc.perform(post("/logout").with(authentication(authentication)).with(csrf())).andExpect(status().isUnauthorized());
}
Also used : Saml2Authentication(org.springframework.security.saml2.provider.service.authentication.Saml2Authentication) DefaultSaml2AuthenticatedPrincipal(org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultSaml2AuthenticatedPrincipal

use of org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal 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 8 with DefaultSaml2AuthenticatedPrincipal

use of org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal 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 9 with DefaultSaml2AuthenticatedPrincipal

use of org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal 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)

Example 10 with DefaultSaml2AuthenticatedPrincipal

use of org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal 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)

Aggregations

DefaultSaml2AuthenticatedPrincipal (org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal)10 Saml2Authentication (org.springframework.security.saml2.provider.service.authentication.Saml2Authentication)10 Test (org.junit.jupiter.api.Test)3 List (java.util.List)2 Saml2ModuleAuthenticationImpl (com.evolveum.midpoint.authentication.impl.module.authentication.Saml2ModuleAuthenticationImpl)1 SamlAdditionalConfiguration (com.evolveum.midpoint.authentication.impl.module.configuration.SamlAdditionalConfiguration)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 LinkedHashMap (java.util.LinkedHashMap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 Saml2AuthenticationToken (org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken)1 LogoutHandler (org.springframework.security.web.authentication.logout.LogoutHandler)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1