Skip to content

Commit 9219125

Browse files
committed
Apply Spring formatting
Issue gh-1616
1 parent 9e8d7fc commit 9219125

File tree

255 files changed

+11264
-9798
lines changed

Some content is hidden

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

255 files changed

+11264
-9798
lines changed

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

Lines changed: 204 additions & 119 deletions
Large diffs are not rendered by default.

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import org.springframework.util.Assert;
2727

2828
/**
29-
* An {@link OAuth2AuthorizationConsentService} that stores {@link OAuth2AuthorizationConsent}'s in-memory.
29+
* An {@link OAuth2AuthorizationConsentService} that stores
30+
* {@link OAuth2AuthorizationConsent}'s in-memory.
3031
*
3132
* <p>
3233
* <b>NOTE:</b> This implementation should ONLY be used during development/testing.
@@ -36,6 +37,7 @@
3637
* @see OAuth2AuthorizationConsentService
3738
*/
3839
public final class InMemoryOAuth2AuthorizationConsentService implements OAuth2AuthorizationConsentService {
40+
3941
private final Map<Integer, OAuth2AuthorizationConsent> authorizationConsents = new ConcurrentHashMap<>();
4042

4143
/**
@@ -46,17 +48,17 @@ public InMemoryOAuth2AuthorizationConsentService() {
4648
}
4749

4850
/**
49-
* Constructs an {@code InMemoryOAuth2AuthorizationConsentService} using the provided parameters.
50-
*
51+
* Constructs an {@code InMemoryOAuth2AuthorizationConsentService} using the provided
52+
* parameters.
5153
* @param authorizationConsents the authorization consent(s)
5254
*/
5355
public InMemoryOAuth2AuthorizationConsentService(OAuth2AuthorizationConsent... authorizationConsents) {
5456
this(Arrays.asList(authorizationConsents));
5557
}
5658

5759
/**
58-
* Constructs an {@code InMemoryOAuth2AuthorizationConsentService} using the provided parameters.
59-
*
60+
* Constructs an {@code InMemoryOAuth2AuthorizationConsentService} using the provided
61+
* parameters.
6062
* @param authorizationConsents the authorization consent(s)
6163
*/
6264
public InMemoryOAuth2AuthorizationConsentService(List<OAuth2AuthorizationConsent> authorizationConsents) {
@@ -66,8 +68,8 @@ public InMemoryOAuth2AuthorizationConsentService(List<OAuth2AuthorizationConsent
6668
int id = getId(authorizationConsent);
6769
Assert.isTrue(!this.authorizationConsents.containsKey(id),
6870
"The authorizationConsent must be unique. Found duplicate, with registered client id: ["
69-
+ authorizationConsent.getRegisteredClientId()
70-
+ "] and principal name: [" + authorizationConsent.getPrincipalName() + "]");
71+
+ authorizationConsent.getRegisteredClientId() + "] and principal name: ["
72+
+ authorizationConsent.getPrincipalName() + "]");
7173
this.authorizationConsents.put(id, authorizationConsent);
7274
});
7375
}

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

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import org.springframework.util.Assert;
3434

3535
/**
36-
* An {@link OAuth2AuthorizationService} that stores {@link OAuth2Authorization}'s in-memory.
36+
* An {@link OAuth2AuthorizationService} that stores {@link OAuth2Authorization}'s
37+
* in-memory.
3738
*
3839
* <p>
3940
* <b>NOTE:</b> This implementation should ONLY be used during development/testing.
@@ -44,15 +45,17 @@
4445
* @see OAuth2AuthorizationService
4546
*/
4647
public final class InMemoryOAuth2AuthorizationService implements OAuth2AuthorizationService {
48+
4749
private int maxInitializedAuthorizations = 100;
4850

4951
/*
50-
* Stores "initialized" (uncompleted) authorizations, where an access token has not yet been granted.
51-
* This state occurs with the authorization_code grant flow during the user consent step OR
52-
* when the code is returned in the authorization response but the access token request is not yet initiated.
52+
* Stores "initialized" (uncompleted) authorizations, where an access token has not
53+
* yet been granted. This state occurs with the authorization_code grant flow during
54+
* the user consent step OR when the code is returned in the authorization response
55+
* but the access token request is not yet initiated.
5356
*/
54-
private Map<String, OAuth2Authorization> initializedAuthorizations =
55-
Collections.synchronizedMap(new MaxSizeHashMap<>(this.maxInitializedAuthorizations));
57+
private Map<String, OAuth2Authorization> initializedAuthorizations = Collections
58+
.synchronizedMap(new MaxSizeHashMap<>(this.maxInitializedAuthorizations));
5659

5760
/*
5861
* Stores "completed" authorizations, where an access token has been granted.
@@ -64,7 +67,8 @@ public final class InMemoryOAuth2AuthorizationService implements OAuth2Authoriza
6467
*/
6568
InMemoryOAuth2AuthorizationService(int maxInitializedAuthorizations) {
6669
this.maxInitializedAuthorizations = maxInitializedAuthorizations;
67-
this.initializedAuthorizations = Collections.synchronizedMap(new MaxSizeHashMap<>(this.maxInitializedAuthorizations));
70+
this.initializedAuthorizations = Collections
71+
.synchronizedMap(new MaxSizeHashMap<>(this.maxInitializedAuthorizations));
6872
}
6973

7074
/**
@@ -75,17 +79,17 @@ public InMemoryOAuth2AuthorizationService() {
7579
}
7680

7781
/**
78-
* Constructs an {@code InMemoryOAuth2AuthorizationService} using the provided parameters.
79-
*
82+
* Constructs an {@code InMemoryOAuth2AuthorizationService} using the provided
83+
* parameters.
8084
* @param authorizations the authorization(s)
8185
*/
8286
public InMemoryOAuth2AuthorizationService(OAuth2Authorization... authorizations) {
8387
this(Arrays.asList(authorizations));
8488
}
8589

8690
/**
87-
* Constructs an {@code InMemoryOAuth2AuthorizationService} using the provided parameters.
88-
*
91+
* Constructs an {@code InMemoryOAuth2AuthorizationService} using the provided
92+
* parameters.
8993
* @param authorizations the authorization(s)
9094
*/
9195
public InMemoryOAuth2AuthorizationService(List<OAuth2Authorization> authorizations) {
@@ -103,7 +107,8 @@ public void save(OAuth2Authorization authorization) {
103107
Assert.notNull(authorization, "authorization cannot be null");
104108
if (isComplete(authorization)) {
105109
this.authorizations.put(authorization.getId(), authorization);
106-
} else {
110+
}
111+
else {
107112
this.initializedAuthorizations.put(authorization.getId(), authorization);
108113
}
109114
}
@@ -113,7 +118,8 @@ public void remove(OAuth2Authorization authorization) {
113118
Assert.notNull(authorization, "authorization cannot be null");
114119
if (isComplete(authorization)) {
115120
this.authorizations.remove(authorization.getId(), authorization);
116-
} else {
121+
}
122+
else {
117123
this.initializedAuthorizations.remove(authorization.getId(), authorization);
118124
}
119125
}
@@ -123,9 +129,7 @@ public void remove(OAuth2Authorization authorization) {
123129
public OAuth2Authorization findById(String id) {
124130
Assert.hasText(id, "id cannot be empty");
125131
OAuth2Authorization authorization = this.authorizations.get(id);
126-
return authorization != null ?
127-
authorization :
128-
this.initializedAuthorizations.get(id);
132+
return authorization != null ? authorization : this.initializedAuthorizations.get(id);
129133
}
130134

131135
@Nullable
@@ -149,7 +153,8 @@ private static boolean isComplete(OAuth2Authorization authorization) {
149153
return authorization.getAccessToken() != null;
150154
}
151155

152-
private static boolean hasToken(OAuth2Authorization authorization, String token, @Nullable OAuth2TokenType tokenType) {
156+
private static boolean hasToken(OAuth2Authorization authorization, String token,
157+
@Nullable OAuth2TokenType tokenType) {
153158
// @formatter:off
154159
if (tokenType == null) {
155160
return matchesState(authorization, token) ||
@@ -183,42 +188,38 @@ private static boolean matchesState(OAuth2Authorization authorization, String to
183188
}
184189

185190
private static boolean matchesAuthorizationCode(OAuth2Authorization authorization, String token) {
186-
OAuth2Authorization.Token<OAuth2AuthorizationCode> authorizationCode =
187-
authorization.getToken(OAuth2AuthorizationCode.class);
191+
OAuth2Authorization.Token<OAuth2AuthorizationCode> authorizationCode = authorization
192+
.getToken(OAuth2AuthorizationCode.class);
188193
return authorizationCode != null && authorizationCode.getToken().getTokenValue().equals(token);
189194
}
190195

191196
private static boolean matchesAccessToken(OAuth2Authorization authorization, String token) {
192-
OAuth2Authorization.Token<OAuth2AccessToken> accessToken =
193-
authorization.getToken(OAuth2AccessToken.class);
197+
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getToken(OAuth2AccessToken.class);
194198
return accessToken != null && accessToken.getToken().getTokenValue().equals(token);
195199
}
196200

197201
private static boolean matchesRefreshToken(OAuth2Authorization authorization, String token) {
198-
OAuth2Authorization.Token<OAuth2RefreshToken> refreshToken =
199-
authorization.getToken(OAuth2RefreshToken.class);
202+
OAuth2Authorization.Token<OAuth2RefreshToken> refreshToken = authorization.getToken(OAuth2RefreshToken.class);
200203
return refreshToken != null && refreshToken.getToken().getTokenValue().equals(token);
201204
}
202205

203206
private static boolean matchesIdToken(OAuth2Authorization authorization, String token) {
204-
OAuth2Authorization.Token<OidcIdToken> idToken =
205-
authorization.getToken(OidcIdToken.class);
207+
OAuth2Authorization.Token<OidcIdToken> idToken = authorization.getToken(OidcIdToken.class);
206208
return idToken != null && idToken.getToken().getTokenValue().equals(token);
207209
}
208210

209211
private static boolean matchesDeviceCode(OAuth2Authorization authorization, String token) {
210-
OAuth2Authorization.Token<OAuth2DeviceCode> deviceCode =
211-
authorization.getToken(OAuth2DeviceCode.class);
212+
OAuth2Authorization.Token<OAuth2DeviceCode> deviceCode = authorization.getToken(OAuth2DeviceCode.class);
212213
return deviceCode != null && deviceCode.getToken().getTokenValue().equals(token);
213214
}
214215

215216
private static boolean matchesUserCode(OAuth2Authorization authorization, String token) {
216-
OAuth2Authorization.Token<OAuth2UserCode> userCode =
217-
authorization.getToken(OAuth2UserCode.class);
217+
OAuth2Authorization.Token<OAuth2UserCode> userCode = authorization.getToken(OAuth2UserCode.class);
218218
return userCode != null && userCode.getToken().getTokenValue().equals(token);
219219
}
220220

221221
private static final class MaxSizeHashMap<K, V> extends LinkedHashMap<K, V> {
222+
222223
private final int maxSize;
223224

224225
private MaxSizeHashMap(int maxSize) {

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

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@
4343
* {@link JdbcOperations} for {@link OAuth2AuthorizationConsent} persistence.
4444
*
4545
* <p>
46-
* <b>IMPORTANT:</b> This {@code OAuth2AuthorizationConsentService} depends on the table definition
47-
* described in
48-
* "classpath:org/springframework/security/oauth2/server/authorization/oauth2-authorization-consent-schema.sql" and
49-
* therefore MUST be defined in the database schema.
46+
* <b>IMPORTANT:</b> This {@code OAuth2AuthorizationConsentService} depends on the table
47+
* definition described in
48+
* "classpath:org/springframework/security/oauth2/server/authorization/oauth2-authorization-consent-schema.sql"
49+
* and therefore MUST be defined in the database schema.
5050
*
5151
* <p>
52-
* <b>NOTE:</b> This {@code OAuth2AuthorizationConsentService} is a simplified JDBC implementation that MAY be used in a production environment.
53-
* However, it does have limitations as it likely won't perform well in an environment requiring high throughput.
54-
* The expectation is that the consuming application will provide their own implementation of {@code OAuth2AuthorizationConsentService}
55-
* that meets the performance requirements for its deployment environment.
52+
* <b>NOTE:</b> This {@code OAuth2AuthorizationConsentService} is a simplified JDBC
53+
* implementation that MAY be used in a production environment. However, it does have
54+
* limitations as it likely won't perform well in an environment requiring high
55+
* throughput. The expectation is that the consuming application will provide their own
56+
* implementation of {@code OAuth2AuthorizationConsentService} that meets the performance
57+
* requirements for its deployment environment.
5658
*
5759
* @author Ovidiu Popa
5860
* @since 0.1.2
@@ -93,13 +95,15 @@ public class JdbcOAuth2AuthorizationConsentService implements OAuth2Authorizatio
9395
private static final String REMOVE_AUTHORIZATION_CONSENT_SQL = "DELETE FROM " + TABLE_NAME + " WHERE " + PK_FILTER;
9496

9597
private final JdbcOperations jdbcOperations;
98+
9699
private RowMapper<OAuth2AuthorizationConsent> authorizationConsentRowMapper;
100+
97101
private Function<OAuth2AuthorizationConsent, List<SqlParameterValue>> authorizationConsentParametersMapper;
98102

99103
/**
100-
* Constructs a {@code JdbcOAuth2AuthorizationConsentService} using the provided parameters.
101-
*
102-
* @param jdbcOperations the JDBC operations
104+
* Constructs a {@code JdbcOAuth2AuthorizationConsentService} using the provided
105+
* parameters.
106+
* @param jdbcOperations the JDBC operations
103107
* @param registeredClientRepository the registered client repository
104108
*/
105109
public JdbcOAuth2AuthorizationConsentService(JdbcOperations jdbcOperations,
@@ -114,11 +118,12 @@ public JdbcOAuth2AuthorizationConsentService(JdbcOperations jdbcOperations,
114118
@Override
115119
public void save(OAuth2AuthorizationConsent authorizationConsent) {
116120
Assert.notNull(authorizationConsent, "authorizationConsent cannot be null");
117-
OAuth2AuthorizationConsent existingAuthorizationConsent = findById(
118-
authorizationConsent.getRegisteredClientId(), authorizationConsent.getPrincipalName());
121+
OAuth2AuthorizationConsent existingAuthorizationConsent = findById(authorizationConsent.getRegisteredClientId(),
122+
authorizationConsent.getPrincipalName());
119123
if (existingAuthorizationConsent == null) {
120124
insertAuthorizationConsent(authorizationConsent);
121-
} else {
125+
}
126+
else {
122127
updateAuthorizationConsent(authorizationConsent);
123128
}
124129
}
@@ -144,8 +149,7 @@ public void remove(OAuth2AuthorizationConsent authorizationConsent) {
144149
Assert.notNull(authorizationConsent, "authorizationConsent cannot be null");
145150
SqlParameterValue[] parameters = new SqlParameterValue[] {
146151
new SqlParameterValue(Types.VARCHAR, authorizationConsent.getRegisteredClientId()),
147-
new SqlParameterValue(Types.VARCHAR, authorizationConsent.getPrincipalName())
148-
};
152+
new SqlParameterValue(Types.VARCHAR, authorizationConsent.getPrincipalName()) };
149153
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters);
150154
this.jdbcOperations.update(REMOVE_AUTHORIZATION_CONSENT_SQL, pss);
151155
}
@@ -157,7 +161,7 @@ public OAuth2AuthorizationConsent findById(String registeredClientId, String pri
157161
Assert.hasText(principalName, "principalName cannot be empty");
158162
SqlParameterValue[] parameters = new SqlParameterValue[] {
159163
new SqlParameterValue(Types.VARCHAR, registeredClientId),
160-
new SqlParameterValue(Types.VARCHAR, principalName)};
164+
new SqlParameterValue(Types.VARCHAR, principalName) };
161165
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters);
162166
List<OAuth2AuthorizationConsent> result = this.jdbcOperations.query(LOAD_AUTHORIZATION_CONSENT_SQL, pss,
163167
this.authorizationConsentRowMapper);
@@ -168,22 +172,21 @@ public OAuth2AuthorizationConsent findById(String registeredClientId, String pri
168172
* Sets the {@link RowMapper} used for mapping the current row in
169173
* {@code java.sql.ResultSet} to {@link OAuth2AuthorizationConsent}. The default is
170174
* {@link OAuth2AuthorizationConsentRowMapper}.
171-
*
172-
* @param authorizationConsentRowMapper the {@link RowMapper} used for mapping the current
173-
* row in {@code ResultSet} to {@link OAuth2AuthorizationConsent}
175+
* @param authorizationConsentRowMapper the {@link RowMapper} used for mapping the
176+
* current row in {@code ResultSet} to {@link OAuth2AuthorizationConsent}
174177
*/
175-
public final void setAuthorizationConsentRowMapper(RowMapper<OAuth2AuthorizationConsent> authorizationConsentRowMapper) {
178+
public final void setAuthorizationConsentRowMapper(
179+
RowMapper<OAuth2AuthorizationConsent> authorizationConsentRowMapper) {
176180
Assert.notNull(authorizationConsentRowMapper, "authorizationConsentRowMapper cannot be null");
177181
this.authorizationConsentRowMapper = authorizationConsentRowMapper;
178182
}
179183

180184
/**
181-
* Sets the {@code Function} used for mapping {@link OAuth2AuthorizationConsent} to
182-
* a {@code List} of {@link SqlParameterValue}. The default is
185+
* Sets the {@code Function} used for mapping {@link OAuth2AuthorizationConsent} to a
186+
* {@code List} of {@link SqlParameterValue}. The default is
183187
* {@link OAuth2AuthorizationConsentParametersMapper}.
184-
*
185188
* @param authorizationConsentParametersMapper the {@code Function} used for mapping
186-
* {@link OAuth2AuthorizationConsent} to a {@code List} of {@link SqlParameterValue}
189+
* {@link OAuth2AuthorizationConsent} to a {@code List} of {@link SqlParameterValue}
187190
*/
188191
public final void setAuthorizationConsentParametersMapper(
189192
Function<OAuth2AuthorizationConsent, List<SqlParameterValue>> authorizationConsentParametersMapper) {
@@ -204,10 +207,11 @@ protected final Function<OAuth2AuthorizationConsent, List<SqlParameterValue>> ge
204207
}
205208

206209
/**
207-
* The default {@link RowMapper} that maps the current row in
208-
* {@code ResultSet} to {@link OAuth2AuthorizationConsent}.
210+
* The default {@link RowMapper} that maps the current row in {@code ResultSet} to
211+
* {@link OAuth2AuthorizationConsent}.
209212
*/
210213
public static class OAuth2AuthorizationConsentRowMapper implements RowMapper<OAuth2AuthorizationConsent> {
214+
211215
private final RegisteredClientRepository registeredClientRepository;
212216

213217
public OAuth2AuthorizationConsentRowMapper(RegisteredClientRepository registeredClientRepository) {
@@ -220,13 +224,14 @@ public OAuth2AuthorizationConsent mapRow(ResultSet rs, int rowNum) throws SQLExc
220224
String registeredClientId = rs.getString("registered_client_id");
221225
RegisteredClient registeredClient = this.registeredClientRepository.findById(registeredClientId);
222226
if (registeredClient == null) {
223-
throw new DataRetrievalFailureException(
224-
"The RegisteredClient with id '" + registeredClientId + "' was not found in the RegisteredClientRepository.");
227+
throw new DataRetrievalFailureException("The RegisteredClient with id '" + registeredClientId
228+
+ "' was not found in the RegisteredClientRepository.");
225229
}
226230

227231
String principalName = rs.getString("principal_name");
228232

229-
OAuth2AuthorizationConsent.Builder builder = OAuth2AuthorizationConsent.withId(registeredClientId, principalName);
233+
OAuth2AuthorizationConsent.Builder builder = OAuth2AuthorizationConsent.withId(registeredClientId,
234+
principalName);
230235
String authorizationConsentAuthorities = rs.getString("authorities");
231236
if (authorizationConsentAuthorities != null) {
232237
for (String authority : StringUtils.commaDelimitedListToSet(authorizationConsentAuthorities)) {
@@ -246,7 +251,8 @@ protected final RegisteredClientRepository getRegisteredClientRepository() {
246251
* The default {@code Function} that maps {@link OAuth2AuthorizationConsent} to a
247252
* {@code List} of {@link SqlParameterValue}.
248253
*/
249-
public static class OAuth2AuthorizationConsentParametersMapper implements Function<OAuth2AuthorizationConsent, List<SqlParameterValue>> {
254+
public static class OAuth2AuthorizationConsentParametersMapper
255+
implements Function<OAuth2AuthorizationConsent, List<SqlParameterValue>> {
250256

251257
@Override
252258
public List<SqlParameterValue> apply(OAuth2AuthorizationConsent authorizationConsent) {
@@ -258,7 +264,8 @@ public List<SqlParameterValue> apply(OAuth2AuthorizationConsent authorizationCon
258264
for (GrantedAuthority authority : authorizationConsent.getAuthorities()) {
259265
authorities.add(authority.getAuthority());
260266
}
261-
parameters.add(new SqlParameterValue(Types.VARCHAR, StringUtils.collectionToDelimitedString(authorities, ",")));
267+
parameters
268+
.add(new SqlParameterValue(Types.VARCHAR, StringUtils.collectionToDelimitedString(authorities, ",")));
262269
return parameters;
263270
}
264271

0 commit comments

Comments
 (0)