2222import java .util .Collection ;
2323import java .util .Iterator ;
2424import java .util .List ;
25- import java .util .function .Consumer ;
2625
2726import org .apache .commons .logging .Log ;
2827import org .apache .commons .logging .LogFactory ;
3736import org .springframework .security .saml2 .core .Saml2X509Credential ;
3837import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration .AssertingPartyDetails ;
3938import org .springframework .util .Assert ;
40- import org .springframework .util .StringUtils ;
4139
4240/**
4341 * A JDBC implementation of {@link AssertingPartyMetadataRepository}.
@@ -54,7 +52,6 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
5452
5553 // @formatter:off
5654 static final String COLUMN_NAMES = "entity_id, "
57- + "metadata_uri, "
5855 + "singlesignon_url, "
5956 + "singlesignon_binding, "
6057 + "singlesignon_sign_request, "
@@ -141,7 +138,6 @@ private final static class AssertingPartyMetadataRowMapper implements RowMapper<
141138 @ Override
142139 public AssertingPartyMetadata mapRow (ResultSet rs , int rowNum ) throws SQLException {
143140 String entityId = rs .getString ("entity_id" );
144- String metadataUri = rs .getString ("metadata_uri" );
145141 String singleSignOnUrl = rs .getString ("singlesignon_url" );
146142 Saml2MessageBinding singleSignOnBinding = Saml2MessageBinding .from (rs .getString ("singlesignon_binding" ));
147143 boolean singleSignOnSignRequest = rs .getBoolean ("singlesignon_sign_request" );
@@ -152,57 +148,41 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
152148 byte [] verificationCredentialsBytes = this .getBytes .getBytes (rs , "verification_credentials" );
153149 byte [] encryptionCredentialsBytes = this .getBytes .getBytes (rs , "encryption_credentials" );
154150
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 ();
158152 try {
159153 if (signingAlgorithmsBytes != null ) {
160- List <String > signingAlgorithms = (List <String >) deserializer .deserializeFromByteArray (signingAlgorithmsBytes );
154+ List <String > signingAlgorithms = (List <String >)
155+ this .deserializer .deserializeFromByteArray (signingAlgorithmsBytes );
161156 builder .signingAlgorithms (algorithms -> algorithms .addAll (signingAlgorithms ));
162157 }
163158 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 ));
166163 }
167164 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 ));
170169 }
171170 } catch (Exception ex ) {
172171 this .logger .debug (
173172 LogMessage .format ("Parsing serialized credentials for entity %s failed" , entityId ), ex );
174173 return null ;
175174 }
176175
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 );
183184 return builder .build ();
184185 }
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- }
206186 }
207187
208188 private interface GetBytes {
0 commit comments