23
23
import java .util .List ;
24
24
import java .util .Map ;
25
25
import java .util .function .Consumer ;
26
- import java .util .function .Function ;
27
26
import java .util .stream .Collectors ;
28
27
29
- import org .apache .commons .logging .Log ;
30
- import org .apache .commons .logging .LogFactory ;
31
-
32
28
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
33
29
import org .springframework .boot .autoconfigure .security .saml2 .Saml2RelyingPartyProperties .AssertingParty ;
34
30
import org .springframework .boot .autoconfigure .security .saml2 .Saml2RelyingPartyProperties .AssertingParty .Verification ;
64
60
@ ConditionalOnMissingBean (RelyingPartyRegistrationRepository .class )
65
61
class Saml2RelyingPartyRegistrationConfiguration {
66
62
67
- private static final Log logger = LogFactory .getLog (Saml2RelyingPartyRegistrationConfiguration .class );
68
-
69
63
@ Bean
70
64
RelyingPartyRegistrationRepository relyingPartyRegistrationRepository (Saml2RelyingPartyProperties properties ) {
71
65
List <RelyingPartyRegistration > registrations = properties .getRegistration ().entrySet ().stream ()
@@ -78,21 +72,19 @@ private RelyingPartyRegistration asRegistration(Map.Entry<String, Registration>
78
72
}
79
73
80
74
private RelyingPartyRegistration asRegistration (String id , Registration properties ) {
81
- boolean usingMetadata = StringUtils
82
- .hasText (getFromAssertingParty (properties , id , "metadata-uri" , AssertingParty ::getMetadataUri ));
75
+ boolean usingMetadata = StringUtils .hasText (properties .getAssertingParty ().getMetadataUri ());
83
76
Builder builder = (usingMetadata ) ? RelyingPartyRegistrations
84
- .fromMetadataLocation (
85
- getFromAssertingParty (properties , id , "metadata-uri" , AssertingParty ::getMetadataUri ))
86
- .registrationId (id ) : RelyingPartyRegistration .withRegistrationId (id );
77
+ .fromMetadataLocation (properties .getAssertingParty ().getMetadataUri ()).registrationId (id )
78
+ : RelyingPartyRegistration .withRegistrationId (id );
87
79
builder .assertionConsumerServiceLocation (properties .getAcs ().getLocation ());
88
80
builder .assertionConsumerServiceBinding (properties .getAcs ().getBinding ());
89
- builder .assertingPartyDetails (mapAssertingParty (properties , id , usingMetadata ));
81
+ builder .assertingPartyDetails (mapAssertingParty (properties . getAssertingParty () , usingMetadata ));
90
82
builder .signingX509Credentials ((credentials ) -> properties .getSigning ().getCredentials ().stream ()
91
83
.map (this ::asSigningCredential ).forEach (credentials ::add ));
92
84
builder .decryptionX509Credentials ((credentials ) -> properties .getDecryption ().getCredentials ().stream ()
93
85
.map (this ::asDecryptionCredential ).forEach (credentials ::add ));
94
- builder .assertingPartyDetails ((details ) -> details . verificationX509Credentials (
95
- ( credentials ) -> getFromAssertingParty ( properties , id , "verification" , AssertingParty :: getVerification )
86
+ builder .assertingPartyDetails ((details ) -> details
87
+ . verificationX509Credentials (( credentials ) -> properties . getAssertingParty (). getVerification ( )
96
88
.getCredentials ().stream ().map (this ::asVerificationCredential ).forEach (credentials ::add )));
97
89
builder .entityId (properties .getEntityId ());
98
90
RelyingPartyRegistration registration = builder .build ();
@@ -101,35 +93,14 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
101
93
return registration ;
102
94
}
103
95
104
- @ SuppressWarnings ("deprecation" )
105
- private <T > T getFromAssertingParty (Registration registration , String id , String name ,
106
- Function <AssertingParty , T > getter ) {
107
- T newValue = getter .apply (registration .getAssertingParty ());
108
- if (newValue != null ) {
109
- return newValue ;
110
- }
111
- T deprecatedValue = getter .apply (registration .getIdentityprovider ());
112
- if (deprecatedValue != null ) {
113
- logger .warn (String .format (
114
- "Property 'spring.security.saml2.relyingparty.registration.identityprovider.%1$s.%2$s' is deprecated, please use 'spring.security.saml2.relyingparty.registration.asserting-party.%1$s.%2$s' instead" ,
115
- id , name ));
116
- return deprecatedValue ;
117
- }
118
- return newValue ;
119
- }
120
-
121
- private Consumer <AssertingPartyDetails .Builder > mapAssertingParty (Registration registration , String id ,
96
+ private Consumer <AssertingPartyDetails .Builder > mapAssertingParty (AssertingParty assertingParty ,
122
97
boolean usingMetadata ) {
123
98
PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
124
99
return (details ) -> {
125
- map .from (() -> getFromAssertingParty (registration , id , "entity-id" , AssertingParty ::getEntityId ))
126
- .to (details ::entityId );
127
- map .from (() -> getFromAssertingParty (registration , id , "singlesignon.binding" ,
128
- (property ) -> property .getSinglesignon ().getBinding ())).to (details ::singleSignOnServiceBinding );
129
- map .from (() -> getFromAssertingParty (registration , id , "singlesignon.url" ,
130
- (property ) -> property .getSinglesignon ().getUrl ())).to (details ::singleSignOnServiceLocation );
131
- map .from (() -> getFromAssertingParty (registration , id , "singlesignon.sign-request" ,
132
- (property ) -> property .getSinglesignon ().getSignRequest ())).when ((ignored ) -> !usingMetadata )
100
+ map .from (assertingParty ::getEntityId ).to (details ::entityId );
101
+ map .from (assertingParty .getSinglesignon ()::getBinding ).to (details ::singleSignOnServiceBinding );
102
+ map .from (assertingParty .getSinglesignon ()::getUrl ).to (details ::singleSignOnServiceLocation );
103
+ map .from (assertingParty .getSinglesignon ()::isSignRequest ).when ((signRequest ) -> !usingMetadata )
133
104
.to (details ::wantAuthnRequestsSigned );
134
105
};
135
106
}
0 commit comments