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 ;
28+
2929import org .springframework .core .log .LogMessage ;
3030import org .springframework .core .serializer .DefaultDeserializer ;
3131import org .springframework .core .serializer .Deserializer ;
3737import org .springframework .security .saml2 .core .Saml2X509Credential ;
3838import org .springframework .security .saml2 .provider .service .registration .RelyingPartyRegistration .AssertingPartyDetails ;
3939import org .springframework .util .Assert ;
40- import org .springframework .util .StringUtils ;
4140
4241/**
4342 * A JDBC implementation of {@link AssertingPartyMetadataRepository}.
@@ -49,12 +48,11 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
4948
5049 private final JdbcOperations jdbcOperations ;
5150
52- private RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper =
53- new AssertingPartyMetadataRowMapper ( ResultSet ::getBytes );
51+ private RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper = new AssertingPartyMetadataRowMapper (
52+ ResultSet ::getBytes );
5453
5554 // @formatter:off
5655 static final String COLUMN_NAMES = "entity_id, "
57- + "metadata_uri, "
5856 + "singlesignon_url, "
5957 + "singlesignon_binding, "
6058 + "singlesignon_sign_request, "
@@ -82,7 +80,6 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
8280 /**
8381 * Constructs a {@code JdbcRelyingPartyRegistrationRepository} using the provided
8482 * parameters.
85- *
8683 * @param jdbcOperations the JDBC operations
8784 */
8885 public JdbcAssertingPartyMetadataRepository (JdbcOperations jdbcOperations ) {
@@ -94,21 +91,18 @@ public JdbcAssertingPartyMetadataRepository(JdbcOperations jdbcOperations) {
9491 * Sets the {@link RowMapper} used for mapping the current row in
9592 * {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}. The default is
9693 * {@link AssertingPartyMetadataRowMapper}.
97- *
9894 * @param assertingPartyMetadataRowMapper the {@link RowMapper} used for mapping the
99- * current row in {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}
95+ * current row in {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}
10096 */
101- public void setAssertingPartyMetadataRowMapper (
102- RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper ) {
97+ public void setAssertingPartyMetadataRowMapper (RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper ) {
10398 Assert .notNull (assertingPartyMetadataRowMapper , "assertingPartyMetadataRowMapper cannot be null" );
10499 this .assertingPartyMetadataRowMapper = assertingPartyMetadataRowMapper ;
105100 }
106101
107102 @ Override
108103 public AssertingPartyMetadata findByEntityId (String entityId ) {
109104 Assert .hasText (entityId , "entityId cannot be empty" );
110- SqlParameterValue [] parameters = new SqlParameterValue []{
111- new SqlParameterValue (Types .VARCHAR , entityId )};
105+ SqlParameterValue [] parameters = new SqlParameterValue [] { new SqlParameterValue (Types .VARCHAR , entityId ) };
112106 PreparedStatementSetter pss = new ArgumentPreparedStatementSetter (parameters );
113107 List <AssertingPartyMetadata > result = this .jdbcOperations .query (LOAD_BY_ID_SQL , pss ,
114108 this .assertingPartyMetadataRowMapper );
@@ -126,7 +120,7 @@ public Iterator<AssertingPartyMetadata> iterator() {
126120 * The default {@link RowMapper} that maps the current row in
127121 * {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}.
128122 */
129- private final static class AssertingPartyMetadataRowMapper implements RowMapper <AssertingPartyMetadata > {
123+ private static final class AssertingPartyMetadataRowMapper implements RowMapper <AssertingPartyMetadata > {
130124
131125 private final Log logger = LogFactory .getLog (AssertingPartyMetadataRowMapper .class );
132126
@@ -141,7 +135,6 @@ private final static class AssertingPartyMetadataRowMapper implements RowMapper<
141135 @ Override
142136 public AssertingPartyMetadata mapRow (ResultSet rs , int rowNum ) throws SQLException {
143137 String entityId = rs .getString ("entity_id" );
144- String metadataUri = rs .getString ("metadata_uri" );
145138 String singleSignOnUrl = rs .getString ("singlesignon_url" );
146139 Saml2MessageBinding singleSignOnBinding = Saml2MessageBinding .from (rs .getString ("singlesignon_binding" ));
147140 boolean singleSignOnSignRequest = rs .getBoolean ("singlesignon_sign_request" );
@@ -152,57 +145,40 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
152145 byte [] verificationCredentialsBytes = this .getBytes .getBytes (rs , "verification_credentials" );
153146 byte [] encryptionCredentialsBytes = this .getBytes .getBytes (rs , "encryption_credentials" );
154147
155- boolean usingMetadata = StringUtils .hasText (metadataUri );
156- AssertingPartyMetadata .Builder <?> builder = (!usingMetadata ) ? new AssertingPartyDetails .Builder ().entityId (entityId )
157- : createBuilderUsingMetadata (entityId , metadataUri );
148+ AssertingPartyMetadata .Builder <?> builder = new AssertingPartyDetails .Builder ();
158149 try {
159150 if (signingAlgorithmsBytes != null ) {
160- List <String > signingAlgorithms = (List <String >) deserializer .deserializeFromByteArray (signingAlgorithmsBytes );
161- builder .signingAlgorithms (algorithms -> algorithms .addAll (signingAlgorithms ));
151+ List <String > signingAlgorithms = (List <String >) this .deserializer
152+ .deserializeFromByteArray (signingAlgorithmsBytes );
153+ builder .signingAlgorithms ((algorithms ) -> algorithms .addAll (signingAlgorithms ));
162154 }
163155 if (verificationCredentialsBytes != null ) {
164- Collection <Saml2X509Credential > verificationCredentials = (Collection <Saml2X509Credential >) deserializer .deserializeFromByteArray (verificationCredentialsBytes );
165- builder .verificationX509Credentials (credentials -> credentials .addAll (verificationCredentials ));
156+ Collection <Saml2X509Credential > verificationCredentials = (Collection <Saml2X509Credential >) this .deserializer
157+ .deserializeFromByteArray (verificationCredentialsBytes );
158+ builder .verificationX509Credentials ((credentials ) -> credentials .addAll (verificationCredentials ));
166159 }
167160 if (encryptionCredentialsBytes != null ) {
168- Collection <Saml2X509Credential > encryptionCredentials = (Collection <Saml2X509Credential >) deserializer .deserializeFromByteArray (encryptionCredentialsBytes );
169- builder .encryptionX509Credentials (credentials -> credentials .addAll (encryptionCredentials ));
161+ Collection <Saml2X509Credential > encryptionCredentials = (Collection <Saml2X509Credential >) this .deserializer
162+ .deserializeFromByteArray (encryptionCredentialsBytes );
163+ builder .encryptionX509Credentials ((credentials ) -> credentials .addAll (encryptionCredentials ));
170164 }
171- } catch (Exception ex ) {
172- this .logger .debug (
173- LogMessage .format ("Parsing serialized credentials for entity %s failed" , entityId ), ex );
165+ }
166+ catch (Exception ex ) {
167+ this .logger .debug (LogMessage .format ("Parsing serialized credentials for entity %s failed" , entityId ),
168+ ex );
174169 return null ;
175170 }
176171
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 );
172+ builder .entityId (entityId )
173+ .wantAuthnRequestsSigned (singleSignOnSignRequest )
174+ .singleSignOnServiceLocation (singleSignOnUrl )
175+ .singleSignOnServiceBinding (singleSignOnBinding )
176+ .singleLogoutServiceLocation (singleLogoutUrl )
177+ .singleLogoutServiceBinding (singleLogoutBinding )
178+ .singleLogoutServiceResponseLocation (singleLogoutResponseUrl );
183179 return builder .build ();
184180 }
185181
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- }
206182 }
207183
208184 private interface GetBytes {
0 commit comments