1515 */
1616package org .springframework .security .samples .config ;
1717
18+
19+ import org .springframework .context .annotation .Bean ;
1820import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
1921import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
2022import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
2325import org .springframework .security .saml2 .credentials .Saml2X509Credential ;
2426import org .springframework .security .saml2 .provider .service .registration .InMemoryRelyingPartyRegistrationRepository ;
2527import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration ;
28+ import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistrationRepository ;
2629import org .springframework .security .saml2 .provider .service .servlet .filter .Saml2WebSsoAuthenticationFilter ;
2730
2831import java .io .ByteArrayInputStream ;
3942@ EnableGlobalMethodSecurity (prePostEnabled = true )
4043public class SecurityConfig extends WebSecurityConfigurerAdapter {
4144
42- RelyingPartyRegistration getSaml2AuthenticationConfiguration () throws Exception {
45+ @ Bean
46+ RelyingPartyRegistrationRepository getSaml2AuthenticationConfiguration () throws Exception {
4347 //remote IDP entity ID
4448 String idpEntityId = "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ;
4549 //remote WebSSO Endpoint - Where to Send AuthNRequests to
@@ -53,14 +57,14 @@ RelyingPartyRegistration getSaml2AuthenticationConfiguration() throws Exception
5357 //IDP certificate for verification of incoming messages
5458 Saml2X509Credential idpVerificationCertificate = getVerificationCertificate ();
5559 String acsUrlTemplate = "{baseUrl}" + Saml2WebSsoAuthenticationFilter .DEFAULT_FILTER_PROCESSES_URI ;
56- return RelyingPartyRegistration .withRegistrationId (registrationId )
60+ return new InMemoryRelyingPartyRegistrationRepository ( RelyingPartyRegistration .withRegistrationId (registrationId )
5761 .providerDetails (config -> config .entityId (idpEntityId ))
5862 .providerDetails (config -> config .webSsoUrl (webSsoEndpoint ))
5963 .credentials (c -> c .add (signingCredential ))
6064 .credentials (c -> c .add (idpVerificationCertificate ))
6165 .localEntityIdTemplate (localEntityIdTemplate )
6266 .assertionConsumerServiceUrlTemplate (acsUrlTemplate )
63- .build ();
67+ .build ()) ;
6468 }
6569
6670 @ Override
@@ -70,14 +74,7 @@ protected void configure(HttpSecurity http) throws Exception {
7074 .authorizeRequests ()
7175 .anyRequest ().authenticated ()
7276 .and ()
73- .saml2Login ()
74- .relyingPartyRegistrationRepository (
75- new InMemoryRelyingPartyRegistrationRepository (
76- getSaml2AuthenticationConfiguration ()
77- )
78- )
79- .loginProcessingUrl ("/sample/jc/saml2/sso/{registrationId}" )
80- ;
77+ .saml2Login ();
8178 // @formatter:on
8279 }
8380
0 commit comments