25
25
import java .util .List ;
26
26
import java .util .function .Function ;
27
27
28
- import org .apache .commons .logging .Log ;
29
- import org .apache .commons .logging .LogFactory ;
30
-
31
- import org .springframework .core .log .LogMessage ;
32
28
import org .springframework .core .serializer .DefaultDeserializer ;
33
29
import org .springframework .core .serializer .DefaultSerializer ;
34
30
import org .springframework .core .serializer .Deserializer ;
@@ -53,8 +49,7 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
53
49
54
50
private final JdbcOperations jdbcOperations ;
55
51
56
- private RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper = new AssertingPartyMetadataRowMapper (
57
- ResultSet ::getBytes );
52
+ private final RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper = new AssertingPartyMetadataRowMapper ();
58
53
59
54
private final AssertingPartyMetadataParametersMapper assertingPartyMetadataParametersMapper = new AssertingPartyMetadataParametersMapper ();
60
55
@@ -113,18 +108,6 @@ public JdbcAssertingPartyMetadataRepository(JdbcOperations jdbcOperations) {
113
108
this .jdbcOperations = jdbcOperations ;
114
109
}
115
110
116
- /**
117
- * Sets the {@link RowMapper} used for mapping the current row in
118
- * {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}. The default is
119
- * {@link AssertingPartyMetadataRowMapper}.
120
- * @param assertingPartyMetadataRowMapper the {@link RowMapper} used for mapping the
121
- * current row in {@code java.sql.ResultSet} to {@link AssertingPartyMetadata}
122
- */
123
- public void setAssertingPartyMetadataRowMapper (RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper ) {
124
- Assert .notNull (assertingPartyMetadataRowMapper , "assertingPartyMetadataRowMapper cannot be null" );
125
- this .assertingPartyMetadataRowMapper = assertingPartyMetadataRowMapper ;
126
- }
127
-
128
111
@ Override
129
112
public AssertingPartyMetadata findByEntityId (String entityId ) {
130
113
Assert .hasText (entityId , "entityId cannot be empty" );
@@ -172,16 +155,8 @@ private int updateCredentialRecord(AssertingPartyMetadata metadata) {
172
155
*/
173
156
private static final class AssertingPartyMetadataRowMapper implements RowMapper <AssertingPartyMetadata > {
174
157
175
- private final Log logger = LogFactory .getLog (AssertingPartyMetadataRowMapper .class );
176
-
177
158
private final Deserializer <Object > deserializer = new DefaultDeserializer ();
178
159
179
- private final GetBytes getBytes ;
180
-
181
- AssertingPartyMetadataRowMapper (GetBytes getBytes ) {
182
- this .getBytes = getBytes ;
183
- }
184
-
185
160
@ Override
186
161
public AssertingPartyMetadata mapRow (ResultSet rs , int rowNum ) throws SQLException {
187
162
String entityId = rs .getString ("entity_id" );
@@ -191,41 +166,26 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
191
166
String singleLogoutUrl = rs .getString ("singlelogout_url" );
192
167
String singleLogoutResponseUrl = rs .getString ("singlelogout_response_url" );
193
168
Saml2MessageBinding singleLogoutBinding = Saml2MessageBinding .from (rs .getString ("singlelogout_binding" ));
194
- byte [] signingAlgorithmsBytes = this .getBytes .getBytes (rs , "signing_algorithms" );
195
- byte [] verificationCredentialsBytes = this .getBytes .getBytes (rs , "verification_credentials" );
196
- byte [] encryptionCredentialsBytes = this .getBytes .getBytes (rs , "encryption_credentials" );
197
-
169
+ List <String > algorithms = List .of (rs .getString ("signing_algorithms" ).split ("," ));
170
+ byte [] verificationCredentialsBytes = rs .getBytes ("verification_credentials" );
171
+ byte [] encryptionCredentialsBytes = rs .getBytes ("encryption_credentials" );
172
+ ThrowingFunction <byte [], Collection <Saml2X509Credential >> credentials = (
173
+ bytes ) -> (Collection <Saml2X509Credential >) this .deserializer .deserializeFromByteArray (bytes );
198
174
AssertingPartyMetadata .Builder <?> builder = new AssertingPartyDetails .Builder ();
199
- try {
200
- if (signingAlgorithmsBytes != null ) {
201
- List <String > signingAlgorithms = (List <String >) this .deserializer
202
- .deserializeFromByteArray (signingAlgorithmsBytes );
203
- builder .signingAlgorithms ((algorithms ) -> algorithms .addAll (signingAlgorithms ));
204
- }
205
- if (verificationCredentialsBytes != null ) {
206
- Collection <Saml2X509Credential > verificationCredentials = (Collection <Saml2X509Credential >) this .deserializer
207
- .deserializeFromByteArray (verificationCredentialsBytes );
208
- builder .verificationX509Credentials ((credentials ) -> credentials .addAll (verificationCredentials ));
209
- }
210
- if (encryptionCredentialsBytes != null ) {
211
- Collection <Saml2X509Credential > encryptionCredentials = (Collection <Saml2X509Credential >) this .deserializer
212
- .deserializeFromByteArray (encryptionCredentialsBytes );
213
- builder .encryptionX509Credentials ((credentials ) -> credentials .addAll (encryptionCredentials ));
214
- }
215
- }
216
- catch (Exception ex ) {
217
- this .logger .debug (LogMessage .format ("Parsing serialized credentials for entity %s failed" , entityId ),
218
- ex );
219
- return null ;
220
- }
175
+ Collection <Saml2X509Credential > verificationCredentials = credentials .apply (verificationCredentialsBytes );
176
+ Collection <Saml2X509Credential > encryptionCredentials = (encryptionCredentialsBytes != null )
177
+ ? credentials .apply (encryptionCredentialsBytes ) : List .of ();
221
178
222
179
builder .entityId (entityId )
223
180
.wantAuthnRequestsSigned (singleSignOnSignRequest )
224
181
.singleSignOnServiceLocation (singleSignOnUrl )
225
182
.singleSignOnServiceBinding (singleSignOnBinding )
226
183
.singleLogoutServiceLocation (singleLogoutUrl )
227
184
.singleLogoutServiceBinding (singleLogoutBinding )
228
- .singleLogoutServiceResponseLocation (singleLogoutResponseUrl );
185
+ .singleLogoutServiceResponseLocation (singleLogoutResponseUrl )
186
+ .signingAlgorithms ((a ) -> a .addAll (algorithms ))
187
+ .verificationX509Credentials ((c ) -> c .addAll (verificationCredentials ))
188
+ .encryptionX509Credentials ((c ) -> c .addAll (encryptionCredentials ));
229
189
return builder .build ();
230
190
}
231
191
@@ -244,8 +204,7 @@ public List<SqlParameterValue> apply(AssertingPartyMetadata record) {
244
204
parameters .add (new SqlParameterValue (Types .VARCHAR , record .getSingleSignOnServiceLocation ()));
245
205
parameters .add (new SqlParameterValue (Types .VARCHAR , record .getSingleSignOnServiceBinding ().getUrn ()));
246
206
parameters .add (new SqlParameterValue (Types .BOOLEAN , record .getWantAuthnRequestsSigned ()));
247
- ThrowingFunction <List <String >, byte []> algorithms = this .serializer ::serializeToByteArray ;
248
- parameters .add (new SqlParameterValue (Types .BLOB , algorithms .apply (record .getSigningAlgorithms ())));
207
+ parameters .add (new SqlParameterValue (Types .BLOB , String .join ("," , record .getSigningAlgorithms ())));
249
208
ThrowingFunction <Collection <Saml2X509Credential >, byte []> credentials = this .serializer ::serializeToByteArray ;
250
209
parameters
251
210
.add (new SqlParameterValue (Types .BLOB , credentials .apply (record .getVerificationX509Credentials ())));
@@ -259,10 +218,4 @@ public List<SqlParameterValue> apply(AssertingPartyMetadata record) {
259
218
260
219
}
261
220
262
- private interface GetBytes {
263
-
264
- byte [] getBytes (ResultSet rs , String columnName ) throws SQLException ;
265
-
266
- }
267
-
268
221
}
0 commit comments