Skip to content

Commit 566064b

Browse files
author
Steve Riesenberg
committed
Revert "Polish gh-313"
This reverts commit 7f095e0
1 parent 7f095e0 commit 566064b

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/JdbcOAuth2AuthorizationService.java

+25-14
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public JdbcOAuth2AuthorizationService(JdbcOperations jdbcOperations,
189189
this.authorizationParametersMapper = new OAuth2AuthorizationParametersMapper(objectMapper);
190190
}
191191

192+
192193
@Override
193194
public void save(OAuth2Authorization authorization) {
194195
Assert.notNull(authorization, "authorization cannot be null");
@@ -310,6 +311,7 @@ public static class OAuth2AuthorizationRowMapper implements RowMapper<OAuth2Auth
310311
private final ObjectMapper objectMapper;
311312
private LobHandler lobHandler = new DefaultLobHandler();
312313

314+
313315
public OAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientRepository, ObjectMapper objectMapper) {
314316
Assert.notNull(registeredClientRepository, "registeredClientRepository cannot be null");
315317
Assert.notNull(objectMapper, "objectMapper cannot be null");
@@ -322,7 +324,8 @@ public OAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientR
322324
public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException {
323325
try {
324326
String registeredClientId = rs.getString("registered_client_id");
325-
RegisteredClient registeredClient = this.registeredClientRepository.findById(registeredClientId);
327+
RegisteredClient registeredClient = this.registeredClientRepository
328+
.findById(registeredClientId);
326329
if (registeredClient == null) {
327330
throw new DataRetrievalFailureException(
328331
"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
337340
builder.id(id)
338341
.principalName(principalName)
339342
.authorizationGrantType(new AuthorizationGrantType(authorizationGrantType))
340-
.attributes((attrs) -> attrs.putAll(attributes));
343+
.attributes(attrs -> attrs.putAll(attributes));
341344

342345
String state = rs.getString("state");
343346
if (StringUtils.hasText(state)) {
@@ -350,19 +353,22 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
350353
byte[] authorizationCodeValue = this.lobHandler.getBlobAsBytes(rs, "authorization_code_value");
351354

352355
if (authorizationCodeValue != null) {
353-
tokenValue = new String(authorizationCodeValue, StandardCharsets.UTF_8);
356+
tokenValue = new String(authorizationCodeValue,
357+
StandardCharsets.UTF_8);
354358
tokenIssuedAt = rs.getTimestamp("authorization_code_issued_at").toInstant();
355359
tokenExpiresAt = rs.getTimestamp("authorization_code_expires_at").toInstant();
356360
Map<String, Object> authorizationCodeMetadata = this.objectMapper.readValue(rs.getString("authorization_code_metadata"), Map.class);
357361

358362
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode(
359363
tokenValue, tokenIssuedAt, tokenExpiresAt);
360-
builder.token(authorizationCode, (metadata) -> metadata.putAll(authorizationCodeMetadata));
364+
builder
365+
.token(authorizationCode, (metadata) -> metadata.putAll(authorizationCodeMetadata));
361366
}
362367

363368
byte[] accessTokenValue = this.lobHandler.getBlobAsBytes(rs, "access_token_value");
364369
if (accessTokenValue != null) {
365-
tokenValue = new String(accessTokenValue, StandardCharsets.UTF_8);
370+
tokenValue = new String(accessTokenValue,
371+
StandardCharsets.UTF_8);
366372
tokenIssuedAt = rs.getTimestamp("access_token_issued_at").toInstant();
367373
tokenExpiresAt = rs.getTimestamp("access_token_expires_at").toInstant();
368374
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
377383
scopes = StringUtils.commaDelimitedListToSet(accessTokenScopes);
378384
}
379385
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));
381388
}
382389

383390
byte[] oidcIdTokenValue = this.lobHandler.getBlobAsBytes(rs, "oidc_id_token_value");
391+
384392
if (oidcIdTokenValue != null) {
385-
tokenValue = new String(oidcIdTokenValue, StandardCharsets.UTF_8);
393+
tokenValue = new String(oidcIdTokenValue,
394+
StandardCharsets.UTF_8);
386395
tokenIssuedAt = rs.getTimestamp("oidc_id_token_issued_at").toInstant();
387396
tokenExpiresAt = rs.getTimestamp("oidc_id_token_expires_at").toInstant();
388397
Map<String, Object> oidcTokenMetadata = this.objectMapper.readValue(rs.getString("oidc_id_token_metadata"), Map.class);
389398

390399
OidcIdToken oidcToken = new OidcIdToken(
391400
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));
393403
}
394404

395405
byte[] refreshTokenValue = this.lobHandler.getBlobAsBytes(rs, "refresh_token_value");
396406
if (refreshTokenValue != null) {
397-
tokenValue = new String(refreshTokenValue, StandardCharsets.UTF_8);
407+
tokenValue = new String(refreshTokenValue,
408+
StandardCharsets.UTF_8);
398409
tokenIssuedAt = rs.getTimestamp("refresh_token_issued_at").toInstant();
399410
tokenExpiresAt = null;
400411
Timestamp refreshTokenExpiresAt = rs.getTimestamp("refresh_token_expires_at");
@@ -405,7 +416,8 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
405416

406417
OAuth2RefreshToken refreshToken = new OAuth2RefreshToken2(
407418
tokenValue, tokenIssuedAt, tokenExpiresAt);
408-
builder.token(refreshToken, (metadata) -> metadata.putAll(refreshTokenMetadata));
419+
builder
420+
.token(refreshToken, (metadata) -> metadata.putAll(refreshTokenMetadata));
409421
}
410422
return builder.build();
411423
} catch (JsonProcessingException e) {
@@ -417,15 +429,13 @@ public final void setLobHandler(LobHandler lobHandler) {
417429
Assert.notNull(lobHandler, "lobHandler cannot be null");
418430
this.lobHandler = lobHandler;
419431
}
420-
421432
}
422433

423434
/**
424435
* The default {@code Function} that maps {@link OAuth2Authorization} to a
425436
* {@code List} of {@link SqlParameterValue}.
426437
*/
427438
public static class OAuth2AuthorizationParametersMapper implements Function<OAuth2Authorization, List<SqlParameterValue>> {
428-
429439
private final ObjectMapper objectMapper;
430440

431441
public OAuth2AuthorizationParametersMapper(ObjectMapper objectMapper) {
@@ -435,6 +445,7 @@ public OAuth2AuthorizationParametersMapper(ObjectMapper objectMapper) {
435445

436446
@Override
437447
public List<SqlParameterValue> apply(OAuth2Authorization authorization) {
448+
438449
try {
439450
List<SqlParameterValue> parameters = new ArrayList<>();
440451
parameters.add(new SqlParameterValue(Types.VARCHAR, authorization.getId()));
@@ -485,6 +496,7 @@ public List<SqlParameterValue> apply(OAuth2Authorization authorization) {
485496
} catch (JsonProcessingException e) {
486497
throw new IllegalArgumentException(e.getMessage(), e);
487498
}
499+
488500
}
489501

490502
private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterList(OAuth2Authorization.Token<T> token) throws JsonProcessingException {
@@ -494,6 +506,7 @@ private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterLi
494506
Timestamp tokenExpiresAt = null;
495507
String codeMetadata = null;
496508
if (token != null) {
509+
497510
tokenValue = token.getToken().getTokenValue().getBytes(StandardCharsets.UTF_8);
498511
if (token.getToken().getIssuedAt() != null) {
499512
tokenIssuedAt = Timestamp.from(token.getToken().getIssuedAt());
@@ -510,7 +523,6 @@ private <T extends AbstractOAuth2Token> List<SqlParameterValue> toSqlParameterLi
510523
parameters.add(new SqlParameterValue(Types.VARCHAR, codeMetadata));
511524
return parameters;
512525
}
513-
514526
}
515527

516528
private static final class LobCreatorArgumentPreparedStatementSetter extends ArgumentPreparedStatementSetter {
@@ -540,5 +552,4 @@ protected void doSetValue(PreparedStatement ps, int parameterPosition, Object ar
540552
}
541553

542554
}
543-
544555
}

0 commit comments

Comments
 (0)