Search in sources :

Example 1 with OpenSamlMetadataResolver

use of org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver in project spring-security by spring-projects.

the class OpenSamlMetadataResolverTests method resolveWhenRelyingPartyNameIDFormatThenMetadataMatches.

@Test
public void resolveWhenRelyingPartyNameIDFormatThenMetadataMatches() {
    RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.full().nameIdFormat("format").build();
    OpenSamlMetadataResolver openSamlMetadataResolver = new OpenSamlMetadataResolver();
    String metadata = openSamlMetadataResolver.resolve(relyingPartyRegistration);
    assertThat(metadata).contains("<md:NameIDFormat>format</md:NameIDFormat>");
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Test(org.junit.jupiter.api.Test)

Example 2 with OpenSamlMetadataResolver

use of org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver in project spring-security by spring-projects.

the class OpenSamlMetadataResolverTests method resolveWhenRelyingPartyNoLogoutThenMetadataMatches.

@Test
public void resolveWhenRelyingPartyNoLogoutThenMetadataMatches() {
    RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.full().singleLogoutServiceLocation(null).nameIdFormat("format").build();
    OpenSamlMetadataResolver openSamlMetadataResolver = new OpenSamlMetadataResolver();
    String metadata = openSamlMetadataResolver.resolve(relyingPartyRegistration);
    assertThat(metadata).doesNotContain("ResponseLocation");
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Test(org.junit.jupiter.api.Test)

Example 3 with OpenSamlMetadataResolver

use of org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver in project spring-security by spring-projects.

the class OpenSamlMetadataResolverTests method resolveWhenRelyingPartyNoCredentialsThenMetadataMatches.

@Test
public void resolveWhenRelyingPartyNoCredentialsThenMetadataMatches() {
    RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials().assertingPartyDetails((party) -> party.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))).build();
    OpenSamlMetadataResolver openSamlMetadataResolver = new OpenSamlMetadataResolver();
    String metadata = openSamlMetadataResolver.resolve(relyingPartyRegistration);
    assertThat(metadata).contains("<EntityDescriptor").contains("entityID=\"rp-entity-id\"").doesNotContain("<md:KeyDescriptor use=\"signing\">").doesNotContain("<md:KeyDescriptor use=\"encryption\">").contains("Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\"").contains("Location=\"https://rp.example.org/acs\" index=\"1\"").contains("ResponseLocation=\"https://rp.example.org/logout/saml2/response\"");
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Test(org.junit.jupiter.api.Test) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestSaml2X509Credentials(org.springframework.security.saml2.core.TestSaml2X509Credentials) TestRelyingPartyRegistrations(org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations) RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Saml2MessageBinding(org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding) Test(org.junit.jupiter.api.Test)

Example 4 with OpenSamlMetadataResolver

use of org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver in project midpoint by Evolveum.

the class SamlModuleWebSecurityConfigurer method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    super.configure(http);
    MidpointSaml2LoginConfigurer configurer = new MidpointSaml2LoginConfigurer<>(auditProvider);
    configurer.relyingPartyRegistrationRepository(relyingPartyRegistrations()).loginProcessingUrl(getConfiguration().getPrefixOfModule() + SamlModuleWebSecurityConfiguration.SSO_LOCATION_URL_SUFFIX).successHandler(getObjectPostProcessor().postProcess(new MidPointAuthenticationSuccessHandler())).failureHandler(new MidpointAuthenticationFailureHandler());
    try {
        configurer.authenticationManager(new ProviderManager(Collections.emptyList(), authenticationManager()));
    } catch (Exception e) {
        LOGGER.error("Couldn't initialize authentication manager for saml2 module");
    }
    getOrApply(http, configurer);
    Saml2MetadataFilter filter = new Saml2MetadataFilter(new MidpointMetadataRelyingPartyRegistrationResolver(relyingPartyRegistrations()), new OpenSamlMetadataResolver());
    filter.setRequestMatcher(new AntPathRequestMatcher(getConfiguration().getPrefixOfModule() + "/metadata/*"));
    http.addFilterAfter(filter, Saml2WebSsoAuthenticationFilter.class);
}
Also used : MidPointAuthenticationSuccessHandler(com.evolveum.midpoint.authentication.impl.handler.MidPointAuthenticationSuccessHandler) MidpointAuthenticationFailureHandler(com.evolveum.midpoint.authentication.impl.handler.MidpointAuthenticationFailureHandler) Saml2MetadataFilter(org.springframework.security.saml2.provider.service.web.Saml2MetadataFilter) ProviderManager(org.springframework.security.authentication.ProviderManager) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) MidpointSaml2LoginConfigurer(com.evolveum.midpoint.authentication.impl.saml.MidpointSaml2LoginConfigurer) MidpointMetadataRelyingPartyRegistrationResolver(com.evolveum.midpoint.authentication.impl.saml.MidpointMetadataRelyingPartyRegistrationResolver) OpenSamlMetadataResolver(org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver)

Example 5 with OpenSamlMetadataResolver

use of org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver in project spring-security by spring-projects.

the class OpenSamlMetadataResolverTests method resolveWhenRelyingPartyThenMetadataMatches.

@Test
public void resolveWhenRelyingPartyThenMetadataMatches() {
    RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.full().assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT).build();
    OpenSamlMetadataResolver openSamlMetadataResolver = new OpenSamlMetadataResolver();
    String metadata = openSamlMetadataResolver.resolve(relyingPartyRegistration);
    assertThat(metadata).contains("<EntityDescriptor").contains("entityID=\"rp-entity-id\"").contains("<md:KeyDescriptor use=\"signing\">").contains("<md:KeyDescriptor use=\"encryption\">").contains("<ds:X509Certificate>MIICgTCCAeoCCQCuVzyqFgMSyDANBgkqhkiG9w0BAQsFADCBhDELMAkGA1UEBh").contains("Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\"").contains("Location=\"https://rp.example.org/acs\" index=\"1\"").contains("ResponseLocation=\"https://rp.example.org/logout/saml2/response\"");
}
Also used : RelyingPartyRegistration(org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 RelyingPartyRegistration (org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration)4 MidPointAuthenticationSuccessHandler (com.evolveum.midpoint.authentication.impl.handler.MidPointAuthenticationSuccessHandler)1 MidpointAuthenticationFailureHandler (com.evolveum.midpoint.authentication.impl.handler.MidpointAuthenticationFailureHandler)1 MidpointMetadataRelyingPartyRegistrationResolver (com.evolveum.midpoint.authentication.impl.saml.MidpointMetadataRelyingPartyRegistrationResolver)1 MidpointSaml2LoginConfigurer (com.evolveum.midpoint.authentication.impl.saml.MidpointSaml2LoginConfigurer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ProviderManager (org.springframework.security.authentication.ProviderManager)1 TestSaml2X509Credentials (org.springframework.security.saml2.core.TestSaml2X509Credentials)1 OpenSamlMetadataResolver (org.springframework.security.saml2.provider.service.metadata.OpenSamlMetadataResolver)1 Saml2MessageBinding (org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding)1 TestRelyingPartyRegistrations (org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations)1 Saml2MetadataFilter (org.springframework.security.saml2.provider.service.web.Saml2MetadataFilter)1 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)1