2525import  java .util .List ;
2626import  java .util .function .Function ;
2727
28- import  org .apache .commons .logging .Log ;
29- import  org .apache .commons .logging .LogFactory ;
30- 
31- import  org .springframework .core .log .LogMessage ;
3228import  org .springframework .core .serializer .DefaultDeserializer ;
3329import  org .springframework .core .serializer .DefaultSerializer ;
3430import  org .springframework .core .serializer .Deserializer ;
@@ -53,8 +49,7 @@ public final class JdbcAssertingPartyMetadataRepository implements AssertingPart
5349
5450	private  final  JdbcOperations  jdbcOperations ;
5551
56- 	private  RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper  = new  AssertingPartyMetadataRowMapper (
57- 			ResultSet ::getBytes );
52+ 	private  final  RowMapper <AssertingPartyMetadata > assertingPartyMetadataRowMapper  = new  AssertingPartyMetadataRowMapper ();
5853
5954	private  final  AssertingPartyMetadataParametersMapper  assertingPartyMetadataParametersMapper  = new  AssertingPartyMetadataParametersMapper ();
6055
@@ -113,18 +108,6 @@ public JdbcAssertingPartyMetadataRepository(JdbcOperations jdbcOperations) {
113108		this .jdbcOperations  = jdbcOperations ;
114109	}
115110
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- 
128111	@ Override 
129112	public  AssertingPartyMetadata  findByEntityId (String  entityId ) {
130113		Assert .hasText (entityId , "entityId cannot be empty" );
@@ -172,16 +155,8 @@ private int updateCredentialRecord(AssertingPartyMetadata metadata) {
172155	 */ 
173156	private  static  final  class  AssertingPartyMetadataRowMapper  implements  RowMapper <AssertingPartyMetadata > {
174157
175- 		private  final  Log  logger  = LogFactory .getLog (AssertingPartyMetadataRowMapper .class );
176- 
177158		private  final  Deserializer <Object > deserializer  = new  DefaultDeserializer ();
178159
179- 		private  final  GetBytes  getBytes ;
180- 
181- 		AssertingPartyMetadataRowMapper (GetBytes  getBytes ) {
182- 			this .getBytes  = getBytes ;
183- 		}
184- 
185160		@ Override 
186161		public  AssertingPartyMetadata  mapRow (ResultSet  rs , int  rowNum ) throws  SQLException  {
187162			String  entityId  = rs .getString ("entity_id" );
@@ -191,41 +166,26 @@ public AssertingPartyMetadata mapRow(ResultSet rs, int rowNum) throws SQLExcepti
191166			String  singleLogoutUrl  = rs .getString ("singlelogout_url" );
192167			String  singleLogoutResponseUrl  = rs .getString ("singlelogout_response_url" );
193168			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 );
198174			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 ();
221178
222179			builder .entityId (entityId )
223180				.wantAuthnRequestsSigned (singleSignOnSignRequest )
224181				.singleSignOnServiceLocation (singleSignOnUrl )
225182				.singleSignOnServiceBinding (singleSignOnBinding )
226183				.singleLogoutServiceLocation (singleLogoutUrl )
227184				.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 ));
229189			return  builder .build ();
230190		}
231191
@@ -244,8 +204,7 @@ public List<SqlParameterValue> apply(AssertingPartyMetadata record) {
244204			parameters .add (new  SqlParameterValue (Types .VARCHAR , record .getSingleSignOnServiceLocation ()));
245205			parameters .add (new  SqlParameterValue (Types .VARCHAR , record .getSingleSignOnServiceBinding ().getUrn ()));
246206			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 ())));
249208			ThrowingFunction <Collection <Saml2X509Credential >, byte []> credentials  = this .serializer ::serializeToByteArray ;
250209			parameters 
251210				.add (new  SqlParameterValue (Types .BLOB , credentials .apply (record .getVerificationX509Credentials ())));
@@ -259,10 +218,4 @@ public List<SqlParameterValue> apply(AssertingPartyMetadata record) {
259218
260219	}
261220
262- 	private  interface  GetBytes  {
263- 
264- 		byte [] getBytes (ResultSet  rs , String  columnName ) throws  SQLException ;
265- 
266- 	}
267- 
268221}
0 commit comments