20
20
import java .security .cert .CertificateFactory ;
21
21
import java .security .cert .X509Certificate ;
22
22
import java .security .interfaces .RSAPrivateKey ;
23
- import java .util .ArrayList ;
24
23
import java .util .List ;
25
24
import java .util .Map ;
26
25
import java .util .stream .Collectors ;
34
33
import org .springframework .context .annotation .Configuration ;
35
34
import org .springframework .core .io .Resource ;
36
35
import org .springframework .security .converter .RsaKeyConverters ;
37
- import org .springframework .security .saml2 .credentials .Saml2X509Credential ;
38
- import org .springframework .security .saml2 .credentials .Saml2X509Credential .Saml2X509CredentialType ;
36
+ import org .springframework .security .saml2 .core .Saml2X509Credential ;
39
37
import org .springframework .security .saml2 .provider .service .registration .InMemoryRelyingPartyRegistrationRepository ;
40
38
import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration ;
41
39
import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistrationRepository ;
@@ -69,15 +67,19 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
69
67
boolean signRequest = properties .getIdentityprovider ().getSinglesignon ().isSignRequest ();
70
68
validateSigningCredentials (properties , signRequest );
71
69
RelyingPartyRegistration .Builder builder = RelyingPartyRegistration .withRegistrationId (id );
72
- builder .assertionConsumerServiceUrlTemplate (
70
+ builder .assertionConsumerServiceLocation (
73
71
"{baseUrl}" + Saml2WebSsoAuthenticationFilter .DEFAULT_FILTER_PROCESSES_URI );
74
- builder .providerDetails (
75
- (details ) -> details .webSsoUrl (properties .getIdentityprovider ().getSinglesignon ().getUrl ()));
76
- builder .providerDetails ((details ) -> details .entityId (properties .getIdentityprovider ().getEntityId ()));
77
- builder .providerDetails (
78
- (details ) -> details .binding (properties .getIdentityprovider ().getSinglesignon ().getBinding ()));
79
- builder .providerDetails ((details ) -> details .signAuthNRequest (signRequest ));
80
- builder .credentials ((credentials ) -> credentials .addAll (asCredentials (properties )));
72
+ builder .assertingPartyDetails ((details ) -> {
73
+ details .singleSignOnServiceLocation (properties .getIdentityprovider ().getSinglesignon ().getUrl ());
74
+ details .entityId (properties .getIdentityprovider ().getEntityId ());
75
+ details .singleSignOnServiceBinding (properties .getIdentityprovider ().getSinglesignon ().getBinding ());
76
+ details .wantAuthnRequestsSigned (signRequest );
77
+ });
78
+ builder .signingX509Credentials ((credentials ) -> properties .getSigning ().getCredentials ().stream ()
79
+ .map (this ::asSigningCredential ).forEach (credentials ::add ));
80
+ builder .assertingPartyDetails ((details ) -> details
81
+ .verificationX509Credentials ((credentials ) -> properties .getIdentityprovider ().getVerification ()
82
+ .getCredentials ().stream ().map (this ::asVerificationCredential ).forEach (credentials ::add )));
81
83
return builder .build ();
82
84
}
83
85
@@ -88,25 +90,17 @@ private void validateSigningCredentials(Registration properties, boolean signReq
88
90
}
89
91
}
90
92
91
- private List <Saml2X509Credential > asCredentials (Registration properties ) {
92
- List <Saml2X509Credential > credentials = new ArrayList <>();
93
- properties .getSigning ().getCredentials ().stream ().map (this ::asSigningCredential ).forEach (credentials ::add );
94
- properties .getIdentityprovider ().getVerification ().getCredentials ().stream ().map (this ::asVerificationCredential )
95
- .forEach (credentials ::add );
96
- return credentials ;
97
- }
98
-
99
93
private Saml2X509Credential asSigningCredential (Signing .Credential properties ) {
100
94
RSAPrivateKey privateKey = readPrivateKey (properties .getPrivateKeyLocation ());
101
95
X509Certificate certificate = readCertificate (properties .getCertificateLocation ());
102
- return new Saml2X509Credential (privateKey , certificate , Saml2X509CredentialType .SIGNING ,
103
- Saml2X509CredentialType .DECRYPTION );
96
+ return new Saml2X509Credential (privateKey , certificate , Saml2X509Credential . Saml2X509CredentialType .SIGNING ,
97
+ Saml2X509Credential . Saml2X509CredentialType .DECRYPTION );
104
98
}
105
99
106
100
private Saml2X509Credential asVerificationCredential (Verification .Credential properties ) {
107
101
X509Certificate certificate = readCertificate (properties .getCertificateLocation ());
108
- return new Saml2X509Credential (certificate , Saml2X509CredentialType .ENCRYPTION ,
109
- Saml2X509CredentialType .VERIFICATION );
102
+ return new Saml2X509Credential (certificate , Saml2X509Credential . Saml2X509CredentialType .ENCRYPTION ,
103
+ Saml2X509Credential . Saml2X509CredentialType .VERIFICATION );
110
104
}
111
105
112
106
private RSAPrivateKey readPrivateKey (Resource location ) {
0 commit comments