@@ -189,6 +189,7 @@ public JdbcOAuth2AuthorizationService(JdbcOperations jdbcOperations,
189
189
this .authorizationParametersMapper = new OAuth2AuthorizationParametersMapper (objectMapper );
190
190
}
191
191
192
+
192
193
@ Override
193
194
public void save (OAuth2Authorization authorization ) {
194
195
Assert .notNull (authorization , "authorization cannot be null" );
@@ -310,6 +311,7 @@ public static class OAuth2AuthorizationRowMapper implements RowMapper<OAuth2Auth
310
311
private final ObjectMapper objectMapper ;
311
312
private LobHandler lobHandler = new DefaultLobHandler ();
312
313
314
+
313
315
public OAuth2AuthorizationRowMapper (RegisteredClientRepository registeredClientRepository , ObjectMapper objectMapper ) {
314
316
Assert .notNull (registeredClientRepository , "registeredClientRepository cannot be null" );
315
317
Assert .notNull (objectMapper , "objectMapper cannot be null" );
@@ -322,7 +324,8 @@ public OAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientR
322
324
public OAuth2Authorization mapRow (ResultSet rs , int rowNum ) throws SQLException {
323
325
try {
324
326
String registeredClientId = rs .getString ("registered_client_id" );
325
- RegisteredClient registeredClient = this .registeredClientRepository .findById (registeredClientId );
327
+ RegisteredClient registeredClient = this .registeredClientRepository
328
+ .findById (registeredClientId );
326
329
if (registeredClient == null ) {
327
330
throw new DataRetrievalFailureException (
328
331
"The RegisteredClient with id '" + registeredClientId + "' it was not found in the RegisteredClientRepository." );
@@ -337,7 +340,7 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
337
340
builder .id (id )
338
341
.principalName (principalName )
339
342
.authorizationGrantType (new AuthorizationGrantType (authorizationGrantType ))
340
- .attributes (( attrs ) -> attrs .putAll (attributes ));
343
+ .attributes (attrs -> attrs .putAll (attributes ));
341
344
342
345
String state = rs .getString ("state" );
343
346
if (StringUtils .hasText (state )) {
@@ -350,19 +353,22 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
350
353
byte [] authorizationCodeValue = this .lobHandler .getBlobAsBytes (rs , "authorization_code_value" );
351
354
352
355
if (authorizationCodeValue != null ) {
353
- tokenValue = new String (authorizationCodeValue , StandardCharsets .UTF_8 );
356
+ tokenValue = new String (authorizationCodeValue ,
357
+ StandardCharsets .UTF_8 );
354
358
tokenIssuedAt = rs .getTimestamp ("authorization_code_issued_at" ).toInstant ();
355
359
tokenExpiresAt = rs .getTimestamp ("authorization_code_expires_at" ).toInstant ();
356
360
Map <String , Object > authorizationCodeMetadata = this .objectMapper .readValue (rs .getString ("authorization_code_metadata" ), Map .class );
357
361
358
362
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode (
359
363
tokenValue , tokenIssuedAt , tokenExpiresAt );
360
- builder .token (authorizationCode , (metadata ) -> metadata .putAll (authorizationCodeMetadata ));
364
+ builder
365
+ .token (authorizationCode , (metadata ) -> metadata .putAll (authorizationCodeMetadata ));
361
366
}
362
367
363
368
byte [] accessTokenValue = this .lobHandler .getBlobAsBytes (rs , "access_token_value" );
364
369
if (accessTokenValue != null ) {
365
- tokenValue = new String (accessTokenValue , StandardCharsets .UTF_8 );
370
+ tokenValue = new String (accessTokenValue ,
371
+ StandardCharsets .UTF_8 );
366
372
tokenIssuedAt = rs .getTimestamp ("access_token_issued_at" ).toInstant ();
367
373
tokenExpiresAt = rs .getTimestamp ("access_token_expires_at" ).toInstant ();
368
374
Map <String , Object > accessTokenMetadata = this .objectMapper .readValue (rs .getString ("access_token_metadata" ), Map .class );
@@ -377,24 +383,29 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
377
383
scopes = StringUtils .commaDelimitedListToSet (accessTokenScopes );
378
384
}
379
385
OAuth2AccessToken accessToken = new OAuth2AccessToken (tokenType , tokenValue , tokenIssuedAt , tokenExpiresAt , scopes );
380
- builder .token (accessToken , (metadata ) -> metadata .putAll (accessTokenMetadata ));
386
+ builder
387
+ .token (accessToken , (metadata ) -> metadata .putAll (accessTokenMetadata ));
381
388
}
382
389
383
390
byte [] oidcIdTokenValue = this .lobHandler .getBlobAsBytes (rs , "oidc_id_token_value" );
391
+
384
392
if (oidcIdTokenValue != null ) {
385
- tokenValue = new String (oidcIdTokenValue , StandardCharsets .UTF_8 );
393
+ tokenValue = new String (oidcIdTokenValue ,
394
+ StandardCharsets .UTF_8 );
386
395
tokenIssuedAt = rs .getTimestamp ("oidc_id_token_issued_at" ).toInstant ();
387
396
tokenExpiresAt = rs .getTimestamp ("oidc_id_token_expires_at" ).toInstant ();
388
397
Map <String , Object > oidcTokenMetadata = this .objectMapper .readValue (rs .getString ("oidc_id_token_metadata" ), Map .class );
389
398
390
399
OidcIdToken oidcToken = new OidcIdToken (
391
400
tokenValue , tokenIssuedAt , tokenExpiresAt , (Map <String , Object >) oidcTokenMetadata .get (OAuth2Authorization .Token .CLAIMS_METADATA_NAME ));
392
- builder .token (oidcToken , (metadata ) -> metadata .putAll (oidcTokenMetadata ));
401
+ builder
402
+ .token (oidcToken , (metadata ) -> metadata .putAll (oidcTokenMetadata ));
393
403
}
394
404
395
405
byte [] refreshTokenValue = this .lobHandler .getBlobAsBytes (rs , "refresh_token_value" );
396
406
if (refreshTokenValue != null ) {
397
- tokenValue = new String (refreshTokenValue , StandardCharsets .UTF_8 );
407
+ tokenValue = new String (refreshTokenValue ,
408
+ StandardCharsets .UTF_8 );
398
409
tokenIssuedAt = rs .getTimestamp ("refresh_token_issued_at" ).toInstant ();
399
410
tokenExpiresAt = null ;
400
411
Timestamp refreshTokenExpiresAt = rs .getTimestamp ("refresh_token_expires_at" );
@@ -405,7 +416,8 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
405
416
406
417
OAuth2RefreshToken refreshToken = new OAuth2RefreshToken2 (
407
418
tokenValue , tokenIssuedAt , tokenExpiresAt );
408
- builder .token (refreshToken , (metadata ) -> metadata .putAll (refreshTokenMetadata ));
419
+ builder
420
+ .token (refreshToken , (metadata ) -> metadata .putAll (refreshTokenMetadata ));
409
421
}
410
422
return builder .build ();
411
423
} catch (JsonProcessingException e ) {
@@ -417,15 +429,13 @@ public final void setLobHandler(LobHandler lobHandler) {
417
429
Assert .notNull (lobHandler , "lobHandler cannot be null" );
418
430
this .lobHandler = lobHandler ;
419
431
}
420
-
421
432
}
422
433
423
434
/**
424
435
* The default {@code Function} that maps {@link OAuth2Authorization} to a
425
436
* {@code List} of {@link SqlParameterValue}.
426
437
*/
427
438
public static class OAuth2AuthorizationParametersMapper implements Function <OAuth2Authorization , List <SqlParameterValue >> {
428
-
429
439
private final ObjectMapper objectMapper ;
430
440
431
441
public OAuth2AuthorizationParametersMapper (ObjectMapper objectMapper ) {
@@ -435,6 +445,7 @@ public OAuth2AuthorizationParametersMapper(ObjectMapper objectMapper) {
435
445
436
446
@ Override
437
447
public List <SqlParameterValue > apply (OAuth2Authorization authorization ) {
448
+
438
449
try {
439
450
List <SqlParameterValue > parameters = new ArrayList <>();
440
451
parameters .add (new SqlParameterValue (Types .VARCHAR , authorization .getId ()));
@@ -485,6 +496,7 @@ public List<SqlParameterValue> apply(OAuth2Authorization authorization) {
485
496
} catch (JsonProcessingException e ) {
486
497
throw new IllegalArgumentException (e .getMessage (), e );
487
498
}
499
+
488
500
}
489
501
490
502
private <T extends AbstractOAuth2Token > List <SqlParameterValue > toSqlParameterList (OAuth2Authorization .Token <T > token ) throws JsonProcessingException {
@@ -494,6 +506,7 @@ private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterLi
494
506
Timestamp tokenExpiresAt = null ;
495
507
String codeMetadata = null ;
496
508
if (token != null ) {
509
+
497
510
tokenValue = token .getToken ().getTokenValue ().getBytes (StandardCharsets .UTF_8 );
498
511
if (token .getToken ().getIssuedAt () != null ) {
499
512
tokenIssuedAt = Timestamp .from (token .getToken ().getIssuedAt ());
@@ -510,7 +523,6 @@ private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterLi
510
523
parameters .add (new SqlParameterValue (Types .VARCHAR , codeMetadata ));
511
524
return parameters ;
512
525
}
513
-
514
526
}
515
527
516
528
private static final class LobCreatorArgumentPreparedStatementSetter extends ArgumentPreparedStatementSetter {
@@ -540,5 +552,4 @@ protected void doSetValue(PreparedStatement ps, int parameterPosition, Object ar
540
552
}
541
553
542
554
}
543
-
544
555
}
0 commit comments