15
15
*/
16
16
package org .springframework .security .samples .config ;
17
17
18
+
19
+ import org .springframework .context .annotation .Bean ;
18
20
import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
19
21
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
20
22
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
23
25
import org .springframework .security .saml2 .credentials .Saml2X509Credential ;
24
26
import org .springframework .security .saml2 .provider .service .registration .InMemoryRelyingPartyRegistrationRepository ;
25
27
import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration ;
28
+ import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistrationRepository ;
26
29
import org .springframework .security .saml2 .provider .service .servlet .filter .Saml2WebSsoAuthenticationFilter ;
27
30
28
31
import java .io .ByteArrayInputStream ;
39
42
@ EnableGlobalMethodSecurity (prePostEnabled = true )
40
43
public class SecurityConfig extends WebSecurityConfigurerAdapter {
41
44
42
- RelyingPartyRegistration getSaml2AuthenticationConfiguration () throws Exception {
45
+ @ Bean
46
+ RelyingPartyRegistrationRepository getSaml2AuthenticationConfiguration () throws Exception {
43
47
//remote IDP entity ID
44
48
String idpEntityId = "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ;
45
49
//remote WebSSO Endpoint - Where to Send AuthNRequests to
@@ -53,14 +57,14 @@ RelyingPartyRegistration getSaml2AuthenticationConfiguration() throws Exception
53
57
//IDP certificate for verification of incoming messages
54
58
Saml2X509Credential idpVerificationCertificate = getVerificationCertificate ();
55
59
String acsUrlTemplate = "{baseUrl}" + Saml2WebSsoAuthenticationFilter .DEFAULT_FILTER_PROCESSES_URI ;
56
- return RelyingPartyRegistration .withRegistrationId (registrationId )
60
+ return new InMemoryRelyingPartyRegistrationRepository ( RelyingPartyRegistration .withRegistrationId (registrationId )
57
61
.providerDetails (config -> config .entityId (idpEntityId ))
58
62
.providerDetails (config -> config .webSsoUrl (webSsoEndpoint ))
59
63
.credentials (c -> c .add (signingCredential ))
60
64
.credentials (c -> c .add (idpVerificationCertificate ))
61
65
.localEntityIdTemplate (localEntityIdTemplate )
62
66
.assertionConsumerServiceUrlTemplate (acsUrlTemplate )
63
- .build ();
67
+ .build ()) ;
64
68
}
65
69
66
70
@ Override
@@ -70,14 +74,7 @@ protected void configure(HttpSecurity http) throws Exception {
70
74
.authorizeRequests ()
71
75
.anyRequest ().authenticated ()
72
76
.and ()
73
- .saml2Login ()
74
- .relyingPartyRegistrationRepository (
75
- new InMemoryRelyingPartyRegistrationRepository (
76
- getSaml2AuthenticationConfiguration ()
77
- )
78
- )
79
- .loginProcessingUrl ("/sample/jc/saml2/sso/{registrationId}" )
80
- ;
77
+ .saml2Login ();
81
78
// @formatter:on
82
79
}
83
80
0 commit comments