15
15
*/
16
16
package org .springframework .security .oauth2 .server .authorization ;
17
17
18
- import java .nio .charset .StandardCharsets ;
19
18
import java .sql .PreparedStatement ;
20
19
import java .sql .ResultSet ;
21
20
import java .sql .SQLException ;
@@ -232,21 +231,21 @@ public OAuth2Authorization findByToken(String token, @Nullable OAuth2TokenType t
232
231
List <SqlParameterValue > parameters = new ArrayList <>();
233
232
if (tokenType == null ) {
234
233
parameters .add (new SqlParameterValue (Types .VARCHAR , token ));
235
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
236
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
237
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
234
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
235
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
236
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
238
237
return findBy (UNKNOWN_TOKEN_TYPE_FILTER , parameters );
239
238
} else if (OAuth2ParameterNames .STATE .equals (tokenType .getValue ())) {
240
239
parameters .add (new SqlParameterValue (Types .VARCHAR , token ));
241
240
return findBy (STATE_FILTER , parameters );
242
241
} else if (OAuth2ParameterNames .CODE .equals (tokenType .getValue ())) {
243
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
242
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
244
243
return findBy (AUTHORIZATION_CODE_FILTER , parameters );
245
244
} else if (OAuth2TokenType .ACCESS_TOKEN .equals (tokenType )) {
246
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
245
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
247
246
return findBy (ACCESS_TOKEN_FILTER , parameters );
248
247
} else if (OAuth2TokenType .REFRESH_TOKEN .equals (tokenType )) {
249
- parameters .add (new SqlParameterValue (Types .BLOB , token . getBytes ( StandardCharsets . UTF_8 ) ));
248
+ parameters .add (new SqlParameterValue (Types .CLOB , token ));
250
249
return findBy (REFRESH_TOKEN_FILTER , parameters );
251
250
}
252
251
return null ;
@@ -352,22 +351,20 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
352
351
String tokenValue ;
353
352
Instant tokenIssuedAt ;
354
353
Instant tokenExpiresAt ;
355
- byte [] authorizationCodeValue = this .lobHandler .getBlobAsBytes (rs , "authorization_code_value" );
354
+ String authorizationCodeValue = this .lobHandler .getClobAsString (rs , "authorization_code_value" );
356
355
357
- if (authorizationCodeValue != null ) {
358
- tokenValue = new String (authorizationCodeValue , StandardCharsets .UTF_8 );
356
+ if (StringUtils .hasText (authorizationCodeValue )) {
359
357
tokenIssuedAt = rs .getTimestamp ("authorization_code_issued_at" ).toInstant ();
360
358
tokenExpiresAt = rs .getTimestamp ("authorization_code_expires_at" ).toInstant ();
361
359
Map <String , Object > authorizationCodeMetadata = parseMap (rs .getString ("authorization_code_metadata" ));
362
360
363
361
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode (
364
- tokenValue , tokenIssuedAt , tokenExpiresAt );
362
+ authorizationCodeValue , tokenIssuedAt , tokenExpiresAt );
365
363
builder .token (authorizationCode , (metadata ) -> metadata .putAll (authorizationCodeMetadata ));
366
364
}
367
365
368
- byte [] accessTokenValue = this .lobHandler .getBlobAsBytes (rs , "access_token_value" );
369
- if (accessTokenValue != null ) {
370
- tokenValue = new String (accessTokenValue , StandardCharsets .UTF_8 );
366
+ String accessTokenValue = this .lobHandler .getClobAsString (rs , "access_token_value" );
367
+ if (StringUtils .hasText (accessTokenValue )) {
371
368
tokenIssuedAt = rs .getTimestamp ("access_token_issued_at" ).toInstant ();
372
369
tokenExpiresAt = rs .getTimestamp ("access_token_expires_at" ).toInstant ();
373
370
Map <String , Object > accessTokenMetadata = parseMap (rs .getString ("access_token_metadata" ));
@@ -381,25 +378,23 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
381
378
if (accessTokenScopes != null ) {
382
379
scopes = StringUtils .commaDelimitedListToSet (accessTokenScopes );
383
380
}
384
- OAuth2AccessToken accessToken = new OAuth2AccessToken (tokenType , tokenValue , tokenIssuedAt , tokenExpiresAt , scopes );
381
+ OAuth2AccessToken accessToken = new OAuth2AccessToken (tokenType , accessTokenValue , tokenIssuedAt , tokenExpiresAt , scopes );
385
382
builder .token (accessToken , (metadata ) -> metadata .putAll (accessTokenMetadata ));
386
383
}
387
384
388
- byte [] oidcIdTokenValue = this .lobHandler .getBlobAsBytes (rs , "oidc_id_token_value" );
389
- if (oidcIdTokenValue != null ) {
390
- tokenValue = new String (oidcIdTokenValue , StandardCharsets .UTF_8 );
385
+ String oidcIdTokenValue = this .lobHandler .getClobAsString (rs , "oidc_id_token_value" );
386
+ if (StringUtils .hasText (oidcIdTokenValue )) {
391
387
tokenIssuedAt = rs .getTimestamp ("oidc_id_token_issued_at" ).toInstant ();
392
388
tokenExpiresAt = rs .getTimestamp ("oidc_id_token_expires_at" ).toInstant ();
393
389
Map <String , Object > oidcTokenMetadata = parseMap (rs .getString ("oidc_id_token_metadata" ));
394
390
395
391
OidcIdToken oidcToken = new OidcIdToken (
396
- tokenValue , tokenIssuedAt , tokenExpiresAt , (Map <String , Object >) oidcTokenMetadata .get (OAuth2Authorization .Token .CLAIMS_METADATA_NAME ));
392
+ oidcIdTokenValue , tokenIssuedAt , tokenExpiresAt , (Map <String , Object >) oidcTokenMetadata .get (OAuth2Authorization .Token .CLAIMS_METADATA_NAME ));
397
393
builder .token (oidcToken , (metadata ) -> metadata .putAll (oidcTokenMetadata ));
398
394
}
399
395
400
- byte [] refreshTokenValue = this .lobHandler .getBlobAsBytes (rs , "refresh_token_value" );
401
- if (refreshTokenValue != null ) {
402
- tokenValue = new String (refreshTokenValue , StandardCharsets .UTF_8 );
396
+ String refreshTokenValue = this .lobHandler .getClobAsString (rs , "refresh_token_value" );
397
+ if (StringUtils .hasText (refreshTokenValue )) {
403
398
tokenIssuedAt = rs .getTimestamp ("refresh_token_issued_at" ).toInstant ();
404
399
tokenExpiresAt = null ;
405
400
Timestamp refreshTokenExpiresAt = rs .getTimestamp ("refresh_token_expires_at" );
@@ -409,7 +404,7 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
409
404
Map <String , Object > refreshTokenMetadata = parseMap (rs .getString ("refresh_token_metadata" ));
410
405
411
406
OAuth2RefreshToken refreshToken = new OAuth2RefreshToken (
412
- tokenValue , tokenIssuedAt , tokenExpiresAt );
407
+ refreshTokenValue , tokenIssuedAt , tokenExpiresAt );
413
408
builder .token (refreshToken , (metadata ) -> metadata .putAll (refreshTokenMetadata ));
414
409
}
415
410
return builder .build ();
@@ -520,12 +515,12 @@ protected final ObjectMapper getObjectMapper() {
520
515
521
516
private <T extends AbstractOAuth2Token > List <SqlParameterValue > toSqlParameterList (OAuth2Authorization .Token <T > token ) {
522
517
List <SqlParameterValue > parameters = new ArrayList <>();
523
- byte [] tokenValue = null ;
518
+ String tokenValue = null ;
524
519
Timestamp tokenIssuedAt = null ;
525
520
Timestamp tokenExpiresAt = null ;
526
521
String metadata = null ;
527
522
if (token != null ) {
528
- tokenValue = token .getToken ().getTokenValue (). getBytes ( StandardCharsets . UTF_8 ) ;
523
+ tokenValue = token .getToken ().getTokenValue ();
529
524
if (token .getToken ().getIssuedAt () != null ) {
530
525
tokenIssuedAt = Timestamp .from (token .getToken ().getIssuedAt ());
531
526
}
@@ -534,7 +529,7 @@ private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterLi
534
529
}
535
530
metadata = writeMap (token .getMetadata ());
536
531
}
537
- parameters .add (new SqlParameterValue (Types .BLOB , tokenValue ));
532
+ parameters .add (new SqlParameterValue (Types .CLOB , tokenValue ));
538
533
parameters .add (new SqlParameterValue (Types .TIMESTAMP , tokenIssuedAt ));
539
534
parameters .add (new SqlParameterValue (Types .TIMESTAMP , tokenExpiresAt ));
540
535
parameters .add (new SqlParameterValue (Types .VARCHAR , metadata ));
@@ -563,13 +558,13 @@ private LobCreatorArgumentPreparedStatementSetter(LobCreator lobCreator, Object[
563
558
protected void doSetValue (PreparedStatement ps , int parameterPosition , Object argValue ) throws SQLException {
564
559
if (argValue instanceof SqlParameterValue ) {
565
560
SqlParameterValue paramValue = (SqlParameterValue ) argValue ;
566
- if (paramValue .getSqlType () == Types .BLOB ) {
561
+ if (paramValue .getSqlType () == Types .CLOB ) {
567
562
if (paramValue .getValue () != null ) {
568
- Assert .isInstanceOf (byte [] .class , paramValue .getValue (),
569
- "Value of blob parameter must be byte[] " );
563
+ Assert .isInstanceOf (String .class , paramValue .getValue (),
564
+ "Value of clob parameter must be String " );
570
565
}
571
- byte [] valueBytes = (byte [] ) paramValue .getValue ();
572
- this .lobCreator .setBlobAsBytes (ps , parameterPosition , valueBytes );
566
+ String valueString = (String ) paramValue .getValue ();
567
+ this .lobCreator .setClobAsString (ps , parameterPosition , valueString );
573
568
return ;
574
569
}
575
570
}
0 commit comments