Skip to content

Commit b02fd96

Browse files
committed
Polish Cursor code
Issue gh-17820
1 parent 266e0c1 commit b02fd96

File tree

5 files changed

+16
-26
lines changed

5 files changed

+16
-26
lines changed

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/OAuth2AuthorizationRequest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public class OAuth2AuthorizationRequest implements Serializable {
8080
private final Map<String, Object> attributes;
8181

8282
protected OAuth2AuthorizationRequest(AbstractBuilder<?, ?> builder) {
83-
Assert.hasText(builder.authorizationUri, "authorizationUri cannot be empty");
84-
Assert.hasText(builder.clientId, "clientId cannot be empty");
8583
Assert.notNull(builder.authorizationUri, "authorizationUri cannot be null");
8684
Assert.notNull(builder.clientId, "clientId cannot be null");
85+
Assert.hasText(builder.authorizationUri, "authorizationUri cannot be empty");
86+
Assert.hasText(builder.clientId, "clientId cannot be empty");
8787
this.authorizationUri = builder.authorizationUri;
8888
this.authorizationGrantType = builder.authorizationGrantType;
8989
this.responseType = builder.responseType;
@@ -93,9 +93,9 @@ protected OAuth2AuthorizationRequest(AbstractBuilder<?, ?> builder) {
9393
CollectionUtils.isEmpty(builder.scopes) ? Collections.emptySet() : new LinkedHashSet<>(builder.scopes));
9494
this.state = builder.state;
9595
this.additionalParameters = Collections.unmodifiableMap(builder.additionalParameters);
96-
String builderUri = builder.authorizationRequestUri;
97-
this.authorizationRequestUri = StringUtils.hasText(builderUri) ? builderUri
98-
: builder.buildAuthorizationRequestUri();
96+
String builderAuthorizationRequestUri = builder.authorizationRequestUri;
97+
this.authorizationRequestUri = StringUtils.hasText(builderAuthorizationRequestUri)
98+
? builderAuthorizationRequestUri : builder.buildAuthorizationRequestUri();
9999
this.attributes = Collections.unmodifiableMap(builder.attributes);
100100
}
101101

@@ -507,9 +507,8 @@ else if (v != null && v.getClass().isArray()) {
507507
queryParams.set(key, encodeQueryParam(String.valueOf(v)));
508508
}
509509
});
510-
String uri = this.authorizationUri;
511-
Assert.notNull(uri, "authorizationUri cannot be null");
512-
UriBuilder uriBuilder = this.uriBuilderFactory.uriString(uri).queryParams(queryParams);
510+
Assert.notNull(this.authorizationUri, "authorizationUri cannot be null");
511+
UriBuilder uriBuilder = this.uriBuilderFactory.uriString(this.authorizationUri).queryParams(queryParams);
513512
return this.authorizationRequestUriFunction.apply(uriBuilder).toString();
514513
}
515514

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/OAuth2AuthorizationResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public OAuth2AuthorizationResponse build() {
222222
authorizationResponse.code = this.code;
223223
}
224224
else {
225+
Assert.notNull(this.errorCode, "errorCode cannot be null when code is not present");
225226
Assert.hasText(this.errorCode, "errorCode cannot be empty when code is not present");
226227
authorizationResponse.error = new OAuth2Error(this.errorCode, this.errorDescription, this.errorUri);
227228
}

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/OAuth2DeviceAuthorizationResponseHttpMessageConverter.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,11 @@ private static final class DefaultMapOAuth2DeviceAuthorizationResponseConverter
146146
@Override
147147
public OAuth2DeviceAuthorizationResponse convert(Map<String, Object> parameters) {
148148
String deviceCode = getParameterValue(parameters, OAuth2ParameterNames.DEVICE_CODE);
149-
if (deviceCode == null) {
150-
throw new IllegalArgumentException("Missing required parameter: " + OAuth2ParameterNames.DEVICE_CODE);
151-
}
149+
Assert.notNull(deviceCode, "Missing required parameter: " + OAuth2ParameterNames.DEVICE_CODE);
152150
String userCode = getParameterValue(parameters, OAuth2ParameterNames.USER_CODE);
153-
if (userCode == null) {
154-
throw new IllegalArgumentException("Missing required parameter: " + OAuth2ParameterNames.USER_CODE);
155-
}
151+
Assert.notNull(userCode, "Missing required parameter: " + OAuth2ParameterNames.USER_CODE);
156152
String verificationUri = getParameterValue(parameters, OAuth2ParameterNames.VERIFICATION_URI);
157-
if (verificationUri == null) {
158-
throw new IllegalArgumentException(
159-
"Missing required parameter: " + OAuth2ParameterNames.VERIFICATION_URI);
160-
}
153+
Assert.notNull(verificationUri, "Missing required parameter: " + OAuth2ParameterNames.VERIFICATION_URI);
161154
String verificationUriComplete = getParameterValue(parameters,
162155
OAuth2ParameterNames.VERIFICATION_URI_COMPLETE);
163156
long expiresIn = getParameterValue(parameters, OAuth2ParameterNames.EXPIRES_IN, 0L);

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/oidc/OidcIdToken.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,8 @@ public Builder subject(String subject) {
250250
* @return The constructed {@link OidcIdToken}
251251
*/
252252
public OidcIdToken build() {
253-
Object iatObj = this.claims.get(IdTokenClaimNames.IAT);
254-
Object expObj = this.claims.get(IdTokenClaimNames.EXP);
255-
Instant iat = toInstant(iatObj);
256-
Instant exp = toInstant(expObj);
253+
Instant iat = toInstant(this.claims.get(IdTokenClaimNames.IAT));
254+
Instant exp = toInstant(this.claims.get(IdTokenClaimNames.EXP));
257255
return new OidcIdToken(this.tokenValue, iat, exp, this.claims);
258256
}
259257

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/user/DefaultOAuth2User.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public DefaultOAuth2User(@Nullable Collection<? extends GrantedAuthority> author
7070
Map<String, Object> attributes, String nameAttributeKey) {
7171
Assert.notEmpty(attributes, "attributes cannot be empty");
7272
Assert.hasText(nameAttributeKey, "nameAttributeKey cannot be empty");
73-
Object nameAttributeValue = attributes.get(nameAttributeKey);
74-
Assert.notNull(nameAttributeValue, "Attribute value for '" + nameAttributeKey + "' cannot be null");
75-
73+
Assert.notNull(attributes.get(nameAttributeKey),
74+
"Attribute value for '" + nameAttributeKey + "' cannot be null");
7675
this.authorities = (authorities != null)
7776
? Collections.unmodifiableSet(new LinkedHashSet<>(this.sortAuthorities(authorities)))
7877
: Collections.unmodifiableSet(new LinkedHashSet<>(AuthorityUtils.NO_AUTHORITIES));
@@ -83,7 +82,7 @@ public DefaultOAuth2User(@Nullable Collection<? extends GrantedAuthority> author
8382
@Override
8483
public String getName() {
8584
Object nameAttributeValue = this.getAttribute(this.nameAttributeKey);
86-
Assert.notNull(nameAttributeValue, "Name attribute value cannot be null");
85+
Assert.notNull(nameAttributeValue, "name attribute value cannot be null");
8786
return nameAttributeValue.toString();
8887
}
8988

0 commit comments

Comments
 (0)