Skip to content

Commit 583abe2

Browse files
author
Steve Riesenberg
committed
1 parent 22fa26d commit 583abe2

6 files changed

+20
-12
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.security.core.AuthenticationException;
3030
import org.springframework.security.core.GrantedAuthority;
3131
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
32-
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
3332
import org.springframework.security.oauth2.core.OAuth2DeviceCode;
3433
import org.springframework.security.oauth2.core.OAuth2Error;
3534
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
@@ -63,7 +62,7 @@
6362
public final class OAuth2DeviceAuthorizationConsentAuthenticationProvider implements AuthenticationProvider {
6463

6564
private static final String DEFAULT_ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1";
66-
private static final OAuth2TokenType STATE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.STATE);
65+
static final OAuth2TokenType STATE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.STATE);
6766

6867
private final Log logger = LogFactory.getLog(getClass());
6968
private final RegisteredClientRepository registeredClientRepository;
@@ -261,7 +260,7 @@ public void setAuthorizationConsentCustomizer(Consumer<OAuth2AuthorizationConsen
261260

262261
private static void throwError(String errorCode, String parameterName) {
263262
OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, DEFAULT_ERROR_URI);
264-
throw new OAuth2AuthorizationException(error);
263+
throw new OAuth2AuthenticationException(error);
265264
}
266265

267266
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
public final class OAuth2DeviceAuthorizationRequestAuthenticationProvider implements AuthenticationProvider {
7070

7171
private static final String ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc6749#section-5.2";
72-
private static final OAuth2TokenType DEVICE_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.DEVICE_CODE);
73-
private static final OAuth2TokenType USER_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.USER_CODE);
72+
static final OAuth2TokenType DEVICE_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.DEVICE_CODE);
73+
static final OAuth2TokenType USER_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.USER_CODE);
7474

7575
private final Log logger = LogFactory.getLog(getClass());
7676
private final OAuth2AuthorizationService authorizationService;

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public final class OAuth2DeviceCodeAuthenticationProvider implements Authenticat
6666

6767
private static final String DEFAULT_ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc6749#section-5.2";
6868
private static final String DEVICE_ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc8628#section-3.5";
69-
private static final OAuth2TokenType DEVICE_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.DEVICE_CODE);
69+
static final OAuth2TokenType DEVICE_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.DEVICE_CODE);
70+
static final String EXPIRED_TOKEN = "expired_token";
71+
static final String AUTHORIZATION_PENDING = "authorization_pending";
7072

7173
private final Log logger = LogFactory.getLog(getClass());
7274
private final OAuth2AuthorizationService authorizationService;
@@ -134,7 +136,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
134136
// access_denied
135137
// The authorization request was denied.
136138
if (Boolean.TRUE.equals(deviceCode.getMetadata(OAuth2Authorization.Token.ACCESS_DENIED_METADATA_NAME))) {
137-
OAuth2Error error = new OAuth2Error("access_denied", null, DEVICE_ERROR_URI);
139+
OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.ACCESS_DENIED, null, DEVICE_ERROR_URI);
138140
throw new OAuth2AuthenticationException(error);
139141
}
140142

@@ -144,7 +146,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
144146
// authorization request but SHOULD wait for user interaction before
145147
// restarting to avoid unnecessary polling.
146148
if (deviceCode.isExpired()) {
147-
OAuth2Error error = new OAuth2Error("expired_token", null, DEVICE_ERROR_URI);
149+
OAuth2Error error = new OAuth2Error(EXPIRED_TOKEN, null, DEVICE_ERROR_URI);
148150
throw new OAuth2AuthenticationException(error);
149151
}
150152

@@ -165,7 +167,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
165167
// increase in the polling interval required by the "slow_down"
166168
// error.
167169
if (!Boolean.TRUE.equals(deviceCode.getMetadata(OAuth2Authorization.Token.ACCESS_GRANTED_METADATA_NAME))) {
168-
OAuth2Error error = new OAuth2Error("authorization_pending", null, DEVICE_ERROR_URI);
170+
OAuth2Error error = new OAuth2Error(AUTHORIZATION_PENDING, null, DEVICE_ERROR_URI);
169171
throw new OAuth2AuthenticationException(error);
170172
}
171173

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public Authentication convert(HttpServletRequest request) {
7575
// client_id (REQUIRED)
7676
String clientId = parameters.getFirst(OAuth2ParameterNames.CLIENT_ID);
7777
if (!StringUtils.hasText(clientId) || parameters.get(OAuth2ParameterNames.CLIENT_ID).size() != 1) {
78-
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.CLIENT_ID, DEFAULT_ERROR_URI);
78+
OAuth2EndpointUtils.throwError(
79+
OAuth2ErrorCodes.INVALID_REQUEST,
80+
OAuth2ParameterNames.CLIENT_ID,
81+
DEFAULT_ERROR_URI);
7982
}
8083

8184
Authentication principal = SecurityContextHolder.getContext().getAuthentication();

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

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
2929
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
3030
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2DeviceAuthorizationRequestAuthenticationToken;
31+
import org.springframework.security.oauth2.server.authorization.web.OAuth2DeviceAuthorizationEndpointFilter;
3132
import org.springframework.security.web.authentication.AuthenticationConverter;
3233
import org.springframework.util.MultiValueMap;
3334
import org.springframework.util.StringUtils;
@@ -40,6 +41,9 @@
4041
*
4142
* @author Steve Riesenberg
4243
* @since 1.1
44+
* @see AuthenticationConverter
45+
* @see OAuth2DeviceAuthorizationRequestAuthenticationToken
46+
* @see OAuth2DeviceAuthorizationEndpointFilter
4347
*/
4448
public final class OAuth2DeviceAuthorizationRequestAuthenticationConverter implements AuthenticationConverter {
4549

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
2727
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
2828
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2DeviceCodeAuthenticationToken;
29-
import org.springframework.security.oauth2.server.authorization.web.OAuth2DeviceAuthorizationEndpointFilter;
29+
import org.springframework.security.oauth2.server.authorization.web.OAuth2TokenEndpointFilter;
3030
import org.springframework.security.web.authentication.AuthenticationConverter;
3131
import org.springframework.util.MultiValueMap;
3232
import org.springframework.util.StringUtils;
@@ -41,7 +41,7 @@
4141
* @since 1.1
4242
* @see AuthenticationConverter
4343
* @see OAuth2DeviceCodeAuthenticationToken
44-
* @see OAuth2DeviceAuthorizationEndpointFilter
44+
* @see OAuth2TokenEndpointFilter
4545
*/
4646
public final class OAuth2DeviceCodeAuthenticationConverter implements AuthenticationConverter {
4747

0 commit comments

Comments
 (0)