3333import org .springframework .jdbc .core .PreparedStatementSetter ;
3434import org .springframework .jdbc .core .RowMapper ;
3535import org .springframework .jdbc .core .SqlParameterValue ;
36- import org .springframework .jdbc .support .lob .DefaultLobHandler ;
3736import org .springframework .jdbc .support .lob .LobCreator ;
3837import org .springframework .jdbc .support .lob .LobHandler ;
3938import org .springframework .security .web .webauthn .api .AuthenticatorTransport ;
6261 */
6362public final class JdbcUserCredentialRepository implements UserCredentialRepository {
6463
65- private RowMapper <CredentialRecord > credentialRecordRowMapper = new CredentialRecordRowMapper ();
64+ private RowMapper <CredentialRecord > credentialRecordRowMapper = new CredentialRecordRowMapper (ResultSet :: getBytes );
6665
6766 private Function <CredentialRecord , List <SqlParameterValue >> credentialRecordParametersMapper = new CredentialRecordParametersMapper ();
6867
69- private LobHandler lobHandler = new DefaultLobHandler () ;
68+ private SetBytes setBytes = PreparedStatement :: setBytes ;
7069
7170 private final JdbcOperations jdbcOperations ;
7271
@@ -159,22 +158,16 @@ public void save(CredentialRecord record) {
159158
160159 private void insertCredentialRecord (CredentialRecord record ) {
161160 List <SqlParameterValue > parameters = this .credentialRecordParametersMapper .apply (record );
162- try (LobCreator lobCreator = this .lobHandler .getLobCreator ()) {
163- PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter (lobCreator ,
164- parameters .toArray ());
165- this .jdbcOperations .update (SAVE_CREDENTIAL_RECORD_SQL , pss );
166- }
161+ PreparedStatementSetter pss = new BlobArgumentPreparedStatementSetter (this .setBytes , parameters .toArray ());
162+ this .jdbcOperations .update (SAVE_CREDENTIAL_RECORD_SQL , pss );
167163 }
168164
169165 private int updateCredentialRecord (CredentialRecord record ) {
170166 List <SqlParameterValue > parameters = this .credentialRecordParametersMapper .apply (record );
171167 SqlParameterValue credentialId = parameters .remove (0 );
172168 parameters .add (credentialId );
173- try (LobCreator lobCreator = this .lobHandler .getLobCreator ()) {
174- PreparedStatementSetter pss = new LobCreatorArgumentPreparedStatementSetter (lobCreator ,
175- parameters .toArray ());
176- return this .jdbcOperations .update (UPDATE_CREDENTIAL_RECORD_SQL , pss );
177- }
169+ PreparedStatementSetter pss = new BlobArgumentPreparedStatementSetter (this .setBytes , parameters .toArray ());
170+ return this .jdbcOperations .update (UPDATE_CREDENTIAL_RECORD_SQL , pss );
178171 }
179172
180173 @ Override
@@ -195,10 +188,18 @@ public List<CredentialRecord> findByUserId(Bytes userId) {
195188 /**
196189 * Sets a {@link LobHandler} for large binary fields and large text field parameters.
197190 * @param lobHandler the lob handler
191+ * @deprecated {@link LobHandler} is deprecated without replacement, as such this
192+ * method will also be removed without replacement
198193 */
194+ @ Deprecated (since = "6.5" , forRemoval = true )
199195 public void setLobHandler (LobHandler lobHandler ) {
200196 Assert .notNull (lobHandler , "lobHandler cannot be null" );
201- this .lobHandler = lobHandler ;
197+ this .setBytes = (ps , index , bytes ) -> {
198+ try (LobCreator creator = lobHandler .getLobCreator ()) {
199+ creator .setBlobAsBytes (ps , index , bytes );
200+ }
201+ };
202+ this .credentialRecordRowMapper = new CredentialRecordRowMapper (lobHandler ::getBlobAsBytes );
202203 }
203204
204205 private static class CredentialRecordParametersMapper
@@ -246,13 +247,25 @@ private Timestamp fromInstant(Instant instant) {
246247
247248 }
248249
249- private static final class LobCreatorArgumentPreparedStatementSetter extends ArgumentPreparedStatementSetter {
250+ private interface SetBytes {
251+
252+ void setBytes (PreparedStatement ps , int index , byte [] bytes ) throws SQLException ;
253+
254+ }
255+
256+ private interface GetBytes {
250257
251- private final LobCreator lobCreator ;
258+ byte [] getBytes ( ResultSet rs , String columnName ) throws SQLException ;
252259
253- private LobCreatorArgumentPreparedStatementSetter (LobCreator lobCreator , Object [] args ) {
260+ }
261+
262+ private static final class BlobArgumentPreparedStatementSetter extends ArgumentPreparedStatementSetter {
263+
264+ private final SetBytes setBytes ;
265+
266+ private BlobArgumentPreparedStatementSetter (SetBytes setBytes , Object [] args ) {
254267 super (args );
255- this .lobCreator = lobCreator ;
268+ this .setBytes = setBytes ;
256269 }
257270
258271 @ Override
@@ -264,7 +277,7 @@ protected void doSetValue(PreparedStatement ps, int parameterPosition, Object ar
264277 "Value of blob parameter must be byte[]" );
265278 }
266279 byte [] valueBytes = (byte []) paramValue .getValue ();
267- this .lobCreator . setBlobAsBytes (ps , parameterPosition , valueBytes );
280+ this .setBytes . setBytes (ps , parameterPosition , valueBytes );
268281 return ;
269282 }
270283 }
@@ -275,14 +288,17 @@ protected void doSetValue(PreparedStatement ps, int parameterPosition, Object ar
275288
276289 private static class CredentialRecordRowMapper implements RowMapper <CredentialRecord > {
277290
278- private LobHandler lobHandler = new DefaultLobHandler ();
291+ private final GetBytes getBytes ;
292+
293+ CredentialRecordRowMapper (GetBytes getBytes ) {
294+ this .getBytes = getBytes ;
295+ }
279296
280297 @ Override
281298 public CredentialRecord mapRow (ResultSet rs , int rowNum ) throws SQLException {
282299 Bytes credentialId = Bytes .fromBase64 (new String (rs .getString ("credential_id" ).getBytes ()));
283300 Bytes userEntityUserId = Bytes .fromBase64 (new String (rs .getString ("user_entity_user_id" ).getBytes ()));
284- ImmutablePublicKeyCose publicKey = new ImmutablePublicKeyCose (
285- this .lobHandler .getBlobAsBytes (rs , "public_key" ));
301+ ImmutablePublicKeyCose publicKey = new ImmutablePublicKeyCose (this .getBytes .getBytes (rs , "public_key" ));
286302 long signatureCount = rs .getLong ("signature_count" );
287303 boolean uvInitialized = rs .getBoolean ("uv_initialized" );
288304 boolean backupEligible = rs .getBoolean ("backup_eligible" );
@@ -291,13 +307,13 @@ public CredentialRecord mapRow(ResultSet rs, int rowNum) throws SQLException {
291307 boolean backupState = rs .getBoolean ("backup_state" );
292308
293309 Bytes attestationObject = null ;
294- byte [] rawAttestationObject = this .lobHandler . getBlobAsBytes (rs , "attestation_object" );
310+ byte [] rawAttestationObject = this .getBytes . getBytes (rs , "attestation_object" );
295311 if (rawAttestationObject != null ) {
296312 attestationObject = new Bytes (rawAttestationObject );
297313 }
298314
299315 Bytes attestationClientDataJson = null ;
300- byte [] rawAttestationClientDataJson = this .lobHandler . getBlobAsBytes (rs , "attestation_client_data_json" );
316+ byte [] rawAttestationClientDataJson = this .getBytes . getBytes (rs , "attestation_client_data_json" );
301317 if (rawAttestationClientDataJson != null ) {
302318 attestationClientDataJson = new Bytes (rawAttestationClientDataJson );
303319 }
0 commit comments