22
22
import java .util .Collection ;
23
23
import java .util .Iterator ;
24
24
import java .util .List ;
25
- import java .util .function .Consumer ;
26
25
27
26
import org .apache .commons .logging .Log ;
28
27
import org .apache .commons .logging .LogFactory ;
37
36
import org .springframework .security .saml2 .core .Saml2X509Credential ;
38
37
import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration .AssertingPartyDetails ;
39
38
import org .springframework .util .Assert ;
40
- import org .springframework .util .StringUtils ;
41
39
42
40
/**
43
41
* A JDBC implementation of {@link AssertingPartyMetadataRepository}.
@@ -54,7 +52,6 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
54
52
55
53
// @formatter:off
56
54
static final String COLUMN_NAMES = "entity_id, "
57
- + "metadata_uri, "
58
55
+ "singlesignon_url, "
59
56
+ "singlesignon_binding, "
60
57
+ "singlesignon_sign_request, "
@@ -141,7 +138,6 @@ private final static class AssertingPartyMetadataRowMapper implements RowMapper<
141
138
@ Override
142
139
public AssertingPartyMetadata mapRow (ResultSet rs , int rowNum ) throws SQLException {
143
140
String entityId = rs .getString ("entity_id" );
144
- String metadataUri = rs .getString ("metadata_uri" );
145
141
String singleSignOnUrl = rs .getString ("singlesignon_url" );
146
142
Saml2MessageBinding singleSignOnBinding = Saml2MessageBinding .from (rs .getString ("singlesignon_binding" ));
147
143
boolean singleSignOnSignRequest = rs .getBoolean ("singlesignon_sign_request" );
@@ -152,57 +148,41 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
152
148
byte [] verificationCredentialsBytes = this .getBytes .getBytes (rs , "verification_credentials" );
153
149
byte [] encryptionCredentialsBytes = this .getBytes .getBytes (rs , "encryption_credentials" );
154
150
155
- boolean usingMetadata = StringUtils .hasText (metadataUri );
156
- AssertingPartyMetadata .Builder <?> builder = (!usingMetadata ) ? new AssertingPartyDetails .Builder ().entityId (entityId )
157
- : createBuilderUsingMetadata (entityId , metadataUri );
151
+ AssertingPartyMetadata .Builder <?> builder = new AssertingPartyDetails .Builder ();
158
152
try {
159
153
if (signingAlgorithmsBytes != null ) {
160
- List <String > signingAlgorithms = (List <String >) deserializer .deserializeFromByteArray (signingAlgorithmsBytes );
154
+ List <String > signingAlgorithms = (List <String >)
155
+ this .deserializer .deserializeFromByteArray (signingAlgorithmsBytes );
161
156
builder .signingAlgorithms (algorithms -> algorithms .addAll (signingAlgorithms ));
162
157
}
163
158
if (verificationCredentialsBytes != null ) {
164
- Collection <Saml2X509Credential > verificationCredentials = (Collection <Saml2X509Credential >) deserializer .deserializeFromByteArray (verificationCredentialsBytes );
165
- builder .verificationX509Credentials (credentials -> credentials .addAll (verificationCredentials ));
159
+ Collection <Saml2X509Credential > verificationCredentials = (Collection <Saml2X509Credential >)
160
+ this .deserializer .deserializeFromByteArray (verificationCredentialsBytes );
161
+ builder .verificationX509Credentials (
162
+ credentials -> credentials .addAll (verificationCredentials ));
166
163
}
167
164
if (encryptionCredentialsBytes != null ) {
168
- Collection <Saml2X509Credential > encryptionCredentials = (Collection <Saml2X509Credential >) deserializer .deserializeFromByteArray (encryptionCredentialsBytes );
169
- builder .encryptionX509Credentials (credentials -> credentials .addAll (encryptionCredentials ));
165
+ Collection <Saml2X509Credential > encryptionCredentials = (Collection <Saml2X509Credential >)
166
+ this .deserializer .deserializeFromByteArray (encryptionCredentialsBytes );
167
+ builder .encryptionX509Credentials (
168
+ credentials -> credentials .addAll (encryptionCredentials ));
170
169
}
171
170
} catch (Exception ex ) {
172
171
this .logger .debug (
173
172
LogMessage .format ("Parsing serialized credentials for entity %s failed" , entityId ), ex );
174
173
return null ;
175
174
}
176
175
177
- applyingWhenNonNull (singleSignOnUrl , builder ::singleSignOnServiceLocation );
178
- applyingWhenNonNull (singleSignOnBinding , builder ::singleSignOnServiceBinding );
179
- applyingWhenNonNull (singleSignOnSignRequest , builder ::wantAuthnRequestsSigned );
180
- applyingWhenNonNull (singleLogoutUrl , builder ::singleLogoutServiceLocation );
181
- applyingWhenNonNull (singleLogoutResponseUrl , builder ::singleLogoutServiceResponseLocation );
182
- applyingWhenNonNull (singleLogoutBinding , builder ::singleLogoutServiceBinding );
176
+ builder
177
+ .entityId (entityId )
178
+ .wantAuthnRequestsSigned (singleSignOnSignRequest )
179
+ .singleSignOnServiceLocation (singleSignOnUrl )
180
+ .singleSignOnServiceBinding (singleSignOnBinding )
181
+ .singleLogoutServiceLocation (singleLogoutUrl )
182
+ .singleLogoutServiceBinding (singleLogoutBinding )
183
+ .singleLogoutServiceResponseLocation (singleLogoutResponseUrl );
183
184
return builder .build ();
184
185
}
185
-
186
- private <T > void applyingWhenNonNull (T value , Consumer <T > consumer ) {
187
- if (value != null ) {
188
- consumer .accept (value );
189
- }
190
- }
191
-
192
- private AssertingPartyMetadata .Builder <?> createBuilderUsingMetadata (String entityId , String metadataUri ) {
193
- Collection <AssertingPartyMetadata .Builder <?>> candidates = AssertingPartyMetadata
194
- .collectionFromMetadataLocation (metadataUri );
195
- for (AssertingPartyMetadata .Builder <?> candidate : candidates ) {
196
- if (entityId == null || entityId .equals (getEntityId (candidate ))) {
197
- return candidate ;
198
- }
199
- }
200
- throw new IllegalStateException ("No asserting party metadata with Entity ID '" + entityId + "' found" );
201
- }
202
-
203
- private Object getEntityId (AssertingPartyMetadata .Builder <?> candidate ) {
204
- return candidate .build ().getEntityId ();
205
- }
206
186
}
207
187
208
188
private interface GetBytes {
0 commit comments