Skip to content

Commit 9c45484

Browse files
committed
Fix checkstyle violations for main module
Issue gh-1624
1 parent 1dd0ab0 commit 9c45484

File tree

76 files changed

+283
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+283
-253
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* describes about its configuration.
3636
*
3737
* @author Daniel Garnier-Moiroux
38-
* @see OAuth2AuthorizationServerMetadataClaimAccessor
3938
* @since 0.1.1
39+
* @see OAuth2AuthorizationServerMetadataClaimAccessor
4040
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc8414#section-3.2">3.2.
4141
* Authorization Server Metadata Response</a>
4242
* @see <a target="_blank" href=
@@ -68,8 +68,11 @@ public Map<String, Object> getClaims() {
6868

6969
/**
7070
* A builder for subclasses of {@link AbstractOAuth2AuthorizationServerMetadata}.
71+
*
72+
* @param <T> the type of object
73+
* @param <B> the type of the builder
7174
*/
72-
protected static abstract class AbstractBuilder<T extends AbstractOAuth2AuthorizationServerMetadata, B extends AbstractBuilder<T, B>> {
75+
protected abstract static class AbstractBuilder<T extends AbstractOAuth2AuthorizationServerMetadata, B extends AbstractBuilder<T, B>> {
7376

7477
private final Map<String, Object> claims = new LinkedHashMap<>();
7578

@@ -492,15 +495,15 @@ protected void validate() {
492495
private void addClaimToClaimList(String name, String value) {
493496
Assert.hasText(name, "name cannot be empty");
494497
Assert.notNull(value, "value cannot be null");
495-
getClaims().computeIfAbsent(name, k -> new LinkedList<String>());
498+
getClaims().computeIfAbsent(name, (k) -> new LinkedList<String>());
496499
((List<String>) getClaims().get(name)).add(value);
497500
}
498501

499502
@SuppressWarnings("unchecked")
500503
private void acceptClaimValues(String name, Consumer<List<String>> valuesConsumer) {
501504
Assert.hasText(name, "name cannot be empty");
502505
Assert.notNull(valuesConsumer, "valuesConsumer cannot be null");
503-
getClaims().computeIfAbsent(name, k -> new LinkedList<String>());
506+
getClaims().computeIfAbsent(name, (k) -> new LinkedList<String>());
504507
List<String> values = (List<String>) getClaims().get(name);
505508
valuesConsumer.accept(values);
506509
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public InMemoryOAuth2AuthorizationConsentService(OAuth2AuthorizationConsent... a
6363
*/
6464
public InMemoryOAuth2AuthorizationConsentService(List<OAuth2AuthorizationConsent> authorizationConsents) {
6565
Assert.notNull(authorizationConsents, "authorizationConsents cannot be null");
66-
authorizationConsents.forEach(authorizationConsent -> {
66+
authorizationConsents.forEach((authorizationConsent) -> {
6767
Assert.notNull(authorizationConsent, "authorizationConsent cannot be null");
6868
int id = getId(authorizationConsent);
6969
Assert.isTrue(!this.authorizationConsents.containsKey(id),

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public InMemoryOAuth2AuthorizationService(OAuth2Authorization... authorizations)
9494
*/
9595
public InMemoryOAuth2AuthorizationService(List<OAuth2Authorization> authorizations) {
9696
Assert.notNull(authorizations, "authorizations cannot be null");
97-
authorizations.forEach(authorization -> {
97+
authorizations.forEach((authorization) -> {
9898
Assert.notNull(authorization, "authorization cannot be null");
9999
Assert.isTrue(!this.authorizations.containsKey(authorization.getId()),
100100
"The authorization must be unique. Found duplicate identifier: " + authorization.getId());
@@ -129,7 +129,7 @@ public void remove(OAuth2Authorization authorization) {
129129
public OAuth2Authorization findById(String id) {
130130
Assert.hasText(id, "id cannot be empty");
131131
OAuth2Authorization authorization = this.authorizations.get(id);
132-
return authorization != null ? authorization : this.initializedAuthorizations.get(id);
132+
return (authorization != null) ? authorization : this.initializedAuthorizations.get(id);
133133
}
134134

135135
@Nullable
@@ -164,19 +164,26 @@ private static boolean hasToken(OAuth2Authorization authorization, String token,
164164
matchesRefreshToken(authorization, token) ||
165165
matchesDeviceCode(authorization, token) ||
166166
matchesUserCode(authorization, token);
167-
} else if (OAuth2ParameterNames.STATE.equals(tokenType.getValue())) {
167+
}
168+
else if (OAuth2ParameterNames.STATE.equals(tokenType.getValue())) {
168169
return matchesState(authorization, token);
169-
} else if (OAuth2ParameterNames.CODE.equals(tokenType.getValue())) {
170+
}
171+
else if (OAuth2ParameterNames.CODE.equals(tokenType.getValue())) {
170172
return matchesAuthorizationCode(authorization, token);
171-
} else if (OAuth2TokenType.ACCESS_TOKEN.equals(tokenType)) {
173+
}
174+
else if (OAuth2TokenType.ACCESS_TOKEN.equals(tokenType)) {
172175
return matchesAccessToken(authorization, token);
173-
} else if (OidcParameterNames.ID_TOKEN.equals(tokenType.getValue())) {
176+
}
177+
else if (OidcParameterNames.ID_TOKEN.equals(tokenType.getValue())) {
174178
return matchesIdToken(authorization, token);
175-
} else if (OAuth2TokenType.REFRESH_TOKEN.equals(tokenType)) {
179+
}
180+
else if (OAuth2TokenType.REFRESH_TOKEN.equals(tokenType)) {
176181
return matchesRefreshToken(authorization, token);
177-
} else if (OAuth2ParameterNames.DEVICE_CODE.equals(tokenType.getValue())) {
182+
}
183+
else if (OAuth2ParameterNames.DEVICE_CODE.equals(tokenType.getValue())) {
178184
return matchesDeviceCode(authorization, token);
179-
} else if (OAuth2ParameterNames.USER_CODE.equals(tokenType.getValue())) {
185+
}
186+
else if (OAuth2ParameterNames.USER_CODE.equals(tokenType.getValue())) {
180187
return matchesUserCode(authorization, token);
181188
}
182189
// @formatter:on

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

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,70 @@ protected final Function<OAuth2Authorization, List<SqlParameterValue>> getAuthor
362362
return this.authorizationParametersMapper;
363363
}
364364

365+
private static void initColumnMetadata(JdbcOperations jdbcOperations) {
366+
columnMetadataMap = new HashMap<>();
367+
ColumnMetadata columnMetadata;
368+
369+
columnMetadata = getColumnMetadata(jdbcOperations, "attributes", Types.BLOB);
370+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
371+
columnMetadata = getColumnMetadata(jdbcOperations, "authorization_code_value", Types.BLOB);
372+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
373+
columnMetadata = getColumnMetadata(jdbcOperations, "authorization_code_metadata", Types.BLOB);
374+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
375+
columnMetadata = getColumnMetadata(jdbcOperations, "access_token_value", Types.BLOB);
376+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
377+
columnMetadata = getColumnMetadata(jdbcOperations, "access_token_metadata", Types.BLOB);
378+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
379+
columnMetadata = getColumnMetadata(jdbcOperations, "oidc_id_token_value", Types.BLOB);
380+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
381+
columnMetadata = getColumnMetadata(jdbcOperations, "oidc_id_token_metadata", Types.BLOB);
382+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
383+
columnMetadata = getColumnMetadata(jdbcOperations, "refresh_token_value", Types.BLOB);
384+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
385+
columnMetadata = getColumnMetadata(jdbcOperations, "refresh_token_metadata", Types.BLOB);
386+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
387+
columnMetadata = getColumnMetadata(jdbcOperations, "user_code_value", Types.BLOB);
388+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
389+
columnMetadata = getColumnMetadata(jdbcOperations, "user_code_metadata", Types.BLOB);
390+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
391+
columnMetadata = getColumnMetadata(jdbcOperations, "device_code_value", Types.BLOB);
392+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
393+
columnMetadata = getColumnMetadata(jdbcOperations, "device_code_metadata", Types.BLOB);
394+
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
395+
}
396+
397+
private static ColumnMetadata getColumnMetadata(JdbcOperations jdbcOperations, String columnName,
398+
int defaultDataType) {
399+
Integer dataType = jdbcOperations.execute((ConnectionCallback<Integer>) (conn) -> {
400+
DatabaseMetaData databaseMetaData = conn.getMetaData();
401+
ResultSet rs = databaseMetaData.getColumns(null, null, TABLE_NAME, columnName);
402+
if (rs.next()) {
403+
return rs.getInt("DATA_TYPE");
404+
}
405+
// NOTE: (Applies to HSQL)
406+
// When a database object is created with one of the CREATE statements or
407+
// renamed with the ALTER statement,
408+
// if the name is enclosed in double quotes, the exact name is used as the
409+
// case-normal form.
410+
// But if it is not enclosed in double quotes,
411+
// the name is converted to uppercase and this uppercase version is stored in
412+
// the database as the case-normal form.
413+
rs = databaseMetaData.getColumns(null, null, TABLE_NAME.toUpperCase(), columnName.toUpperCase());
414+
if (rs.next()) {
415+
return rs.getInt("DATA_TYPE");
416+
}
417+
return null;
418+
});
419+
return new ColumnMetadata(columnName, (dataType != null) ? dataType : defaultDataType);
420+
}
421+
422+
private static SqlParameterValue mapToSqlParameter(String columnName, String value) {
423+
ColumnMetadata columnMetadata = columnMetadataMap.get(columnName);
424+
return (Types.BLOB == columnMetadata.getDataType() && StringUtils.hasText(value))
425+
? new SqlParameterValue(Types.BLOB, value.getBytes(StandardCharsets.UTF_8))
426+
: new SqlParameterValue(columnMetadata.getDataType(), value);
427+
}
428+
365429
/**
366430
* The default {@link RowMapper} that maps the current row in
367431
* {@code java.sql.ResultSet} to {@link OAuth2Authorization}.
@@ -741,68 +805,4 @@ private int getDataType() {
741805

742806
}
743807

744-
private static void initColumnMetadata(JdbcOperations jdbcOperations) {
745-
columnMetadataMap = new HashMap<>();
746-
ColumnMetadata columnMetadata;
747-
748-
columnMetadata = getColumnMetadata(jdbcOperations, "attributes", Types.BLOB);
749-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
750-
columnMetadata = getColumnMetadata(jdbcOperations, "authorization_code_value", Types.BLOB);
751-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
752-
columnMetadata = getColumnMetadata(jdbcOperations, "authorization_code_metadata", Types.BLOB);
753-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
754-
columnMetadata = getColumnMetadata(jdbcOperations, "access_token_value", Types.BLOB);
755-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
756-
columnMetadata = getColumnMetadata(jdbcOperations, "access_token_metadata", Types.BLOB);
757-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
758-
columnMetadata = getColumnMetadata(jdbcOperations, "oidc_id_token_value", Types.BLOB);
759-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
760-
columnMetadata = getColumnMetadata(jdbcOperations, "oidc_id_token_metadata", Types.BLOB);
761-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
762-
columnMetadata = getColumnMetadata(jdbcOperations, "refresh_token_value", Types.BLOB);
763-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
764-
columnMetadata = getColumnMetadata(jdbcOperations, "refresh_token_metadata", Types.BLOB);
765-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
766-
columnMetadata = getColumnMetadata(jdbcOperations, "user_code_value", Types.BLOB);
767-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
768-
columnMetadata = getColumnMetadata(jdbcOperations, "user_code_metadata", Types.BLOB);
769-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
770-
columnMetadata = getColumnMetadata(jdbcOperations, "device_code_value", Types.BLOB);
771-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
772-
columnMetadata = getColumnMetadata(jdbcOperations, "device_code_metadata", Types.BLOB);
773-
columnMetadataMap.put(columnMetadata.getColumnName(), columnMetadata);
774-
}
775-
776-
private static ColumnMetadata getColumnMetadata(JdbcOperations jdbcOperations, String columnName,
777-
int defaultDataType) {
778-
Integer dataType = jdbcOperations.execute((ConnectionCallback<Integer>) conn -> {
779-
DatabaseMetaData databaseMetaData = conn.getMetaData();
780-
ResultSet rs = databaseMetaData.getColumns(null, null, TABLE_NAME, columnName);
781-
if (rs.next()) {
782-
return rs.getInt("DATA_TYPE");
783-
}
784-
// NOTE: (Applies to HSQL)
785-
// When a database object is created with one of the CREATE statements or
786-
// renamed with the ALTER statement,
787-
// if the name is enclosed in double quotes, the exact name is used as the
788-
// case-normal form.
789-
// But if it is not enclosed in double quotes,
790-
// the name is converted to uppercase and this uppercase version is stored in
791-
// the database as the case-normal form.
792-
rs = databaseMetaData.getColumns(null, null, TABLE_NAME.toUpperCase(), columnName.toUpperCase());
793-
if (rs.next()) {
794-
return rs.getInt("DATA_TYPE");
795-
}
796-
return null;
797-
});
798-
return new ColumnMetadata(columnName, dataType != null ? dataType : defaultDataType);
799-
}
800-
801-
private static SqlParameterValue mapToSqlParameter(String columnName, String value) {
802-
ColumnMetadata columnMetadata = columnMetadataMap.get(columnName);
803-
return Types.BLOB == columnMetadata.getDataType() && StringUtils.hasText(value)
804-
? new SqlParameterValue(Types.BLOB, value.getBytes(StandardCharsets.UTF_8))
805-
: new SqlParameterValue(columnMetadata.getDataType(), value);
806-
}
807-
808808
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Token<OAuth2RefreshToken> getRefreshToken() {
144144
public <T extends OAuth2Token> Token<T> getToken(Class<T> tokenType) {
145145
Assert.notNull(tokenType, "tokenType cannot be null");
146146
Token<?> token = this.tokens.get(tokenType);
147-
return token != null ? (Token<T>) token : null;
147+
return (token != null) ? (Token<T>) token : null;
148148
}
149149

150150
/**
@@ -234,12 +234,13 @@ public static Builder from(OAuth2Authorization authorization) {
234234
.authorizationGrantType(authorization.getAuthorizationGrantType())
235235
.authorizedScopes(authorization.getAuthorizedScopes())
236236
.tokens(authorization.tokens)
237-
.attributes(attrs -> attrs.putAll(authorization.getAttributes()));
237+
.attributes((attrs) -> attrs.putAll(authorization.getAttributes()));
238238
}
239239

240240
/**
241241
* A holder of an OAuth 2.0 Token and it's associated metadata.
242242
*
243+
* @param <T> the type of the {@link OAuth2Token}
243244
* @author Joe Grandja
244245
* @since 0.1.0
245246
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.security.Principal;
19+
1820
import org.springframework.lang.Nullable;
1921
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
2022

21-
import java.security.Principal;
22-
2323
/**
2424
* Implementations of this interface are responsible for the management of
2525
* {@link OAuth2AuthorizationConsent OAuth 2.0 Authorization Consent(s)}.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public static Builder builder() {
5252
*/
5353
public static Builder withClaims(Map<String, Object> claims) {
5454
Assert.notEmpty(claims, "claims cannot be empty");
55-
return new Builder().claims(c -> c.putAll(claims));
55+
return new Builder().claims((c) -> c.putAll(claims));
5656
}
5757

5858
/**
5959
* Helps configure an {@link OAuth2AuthorizationServerMetadata}.
6060
*/
61-
public static class Builder extends AbstractBuilder<OAuth2AuthorizationServerMetadata, Builder> {
61+
public static final class Builder extends AbstractBuilder<OAuth2AuthorizationServerMetadata, Builder> {
6262

6363
private Builder() {
6464
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public static Builder builder(boolean active) {
8888
*/
8989
public static Builder withClaims(Map<String, Object> claims) {
9090
Assert.notEmpty(claims, "claims cannot be empty");
91-
return builder().claims(c -> c.putAll(claims));
91+
return builder().claims((c) -> c.putAll(claims));
9292
}
9393

9494
/**
9595
* A builder for {@link OAuth2TokenIntrospection}.
9696
*/
97-
public static class Builder {
97+
public static final class Builder {
9898

9999
private final Map<String, Object> claims = new LinkedHashMap<>();
100100

@@ -312,15 +312,15 @@ private void validate() {
312312
private void addClaimToClaimList(String name, String value) {
313313
Assert.hasText(name, "name cannot be empty");
314314
Assert.notNull(value, "value cannot be null");
315-
this.claims.computeIfAbsent(name, k -> new LinkedList<String>());
315+
this.claims.computeIfAbsent(name, (k) -> new LinkedList<String>());
316316
((List<String>) this.claims.get(name)).add(value);
317317
}
318318

319319
@SuppressWarnings("unchecked")
320320
private void acceptClaimValues(String name, Consumer<List<String>> valuesConsumer) {
321321
Assert.hasText(name, "name cannot be empty");
322322
Assert.notNull(valuesConsumer, "valuesConsumer cannot be null");
323-
this.claims.computeIfAbsent(name, k -> new LinkedList<String>());
323+
this.claims.computeIfAbsent(name, (k) -> new LinkedList<String>());
324324
List<String> values = (List<String>) this.claims.get(name);
325325
valuesConsumer.accept(values);
326326
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ public final class OAuth2TokenType implements Serializable {
3232

3333
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
3434

35+
/**
36+
* {@code access_token} token type.
37+
*/
3538
public static final OAuth2TokenType ACCESS_TOKEN = new OAuth2TokenType("access_token");
3639

40+
/**
41+
* {@code refresh_token} token type.
42+
*/
3743
public static final OAuth2TokenType REFRESH_TOKEN = new OAuth2TokenType("refresh_token");
3844

3945
private final String value;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
128128

129129
// @formatter:off
130130
ClientAuthenticationMethod clientAuthenticationMethod =
131-
registeredClient.getClientSettings().getTokenEndpointAuthenticationSigningAlgorithm() instanceof SignatureAlgorithm ?
131+
(registeredClient.getClientSettings().getTokenEndpointAuthenticationSigningAlgorithm() instanceof SignatureAlgorithm) ?
132132
ClientAuthenticationMethod.PRIVATE_KEY_JWT :
133133
ClientAuthenticationMethod.CLIENT_SECRET_JWT;
134134
// @formatter:on

0 commit comments

Comments
 (0)