Spring Security by Badr Nasslahsen

Spring Security by Badr Nasslahsen

Author:Badr Nasslahsen
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2024-05-30T00:00:00+00:00


Creating a custom RelyingPartyRegistrationRepository

Spring Boot creates a RelyingPartyRegistrationRepository, which represents the asserting party and relying party metadata. This includes things such as the location of the SSO endpoint the relying party should use when requesting authentication from the asserting party.

You can override the default by publishing your own RelyingPartyRegistrationRepository bean. You can also remove the existing spring.security.saml2.relyingparty.registration configuration properties programmatically.

For example, you can look up the asserting party’s configuration by hitting its metadata endpoint:

//src/main/java/com/packtpub/springsecurity/service/ SecurityConfig.java @Value("${metadata.location}") private String assertingPartyMetadataLocation; @Bean public RelyingPartyRegistrationRepository relyingPartyRegistrations() { RelyingPartyRegistration registration = RelyingPartyRegistrations .fromMetadataLocation(assertingPartyMetadataLocation) .registrationId("okta") .build(); return new InMemoryRelyingPartyRegistrationRepository(registration); }

Alternatively, you can directly wire up the repository by using the DSL, which also overrides the auto-configured SecurityFilterChain:

//src/main/java/com/packtpub/springsecurity/service/ SecurityConfig.java @Configuration @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { ... omitted for brevity http .saml2Login(saml2 -> saml2 .relyingPartyRegistrationRepository(relyingPartyRegistrations()) ); return http.build(); } }

Important note

The registrationId is a user-defined value chosen to distinguish between different registrations.

Your code should now look like that in chapter10.04-calendar.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.