Skip to content

Commit 77a9b2e

Browse files
committed
Add temporary OAuth2ErrorCodes2
Issue spring-projects/spring-security#9184
1 parent d76d209 commit 77a9b2e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.core;
17+
18+
/**
19+
* TODO
20+
* This class is temporary and will be removed after upgrading to Spring Security 5.5.0 GA.
21+
*
22+
* @author Joe Grandja
23+
* @since 0.0.3
24+
* @see <a target="_blank" href="https://github.com/spring-projects/spring-security/issues/9184">Issue gh-9184</a>
25+
*/
26+
public interface OAuth2ErrorCodes2 extends OAuth2ErrorCodes {
27+
28+
String UNSUPPORTED_TOKEN_TYPE = "unsupported_token_type";
29+
30+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
2323
import org.springframework.security.oauth2.core.OAuth2Error;
2424
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
25+
import org.springframework.security.oauth2.core.OAuth2ErrorCodes2;
2526
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
2627
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
2728
import org.springframework.security.oauth2.server.authorization.TokenType;
@@ -71,7 +72,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
7172
} else if (TokenType.ACCESS_TOKEN.getValue().equals(tokenTypeHint)) {
7273
tokenType = TokenType.ACCESS_TOKEN;
7374
} else {
74-
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.UNSUPPORTED_TOKEN_TYPE));
75+
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes2.UNSUPPORTED_TOKEN_TYPE));
7576
}
7677
}
7778

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2TokenRevocationAuthenticationProviderTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.security.oauth2.core.OAuth2AccessToken;
2323
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
2424
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
25+
import org.springframework.security.oauth2.core.OAuth2ErrorCodes2;
2526
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
2627
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
2728
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
@@ -100,12 +101,12 @@ public void authenticateWhenInvalidTokenTypeThenThrowOAuth2AuthenticationExcepti
100101
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
101102
OAuth2ClientAuthenticationToken clientPrincipal = new OAuth2ClientAuthenticationToken(registeredClient);
102103
OAuth2TokenRevocationAuthenticationToken authentication = new OAuth2TokenRevocationAuthenticationToken(
103-
"token", clientPrincipal, OAuth2ErrorCodes.UNSUPPORTED_TOKEN_TYPE);
104+
"token", clientPrincipal, OAuth2ErrorCodes2.UNSUPPORTED_TOKEN_TYPE);
104105
assertThatThrownBy(() -> this.authenticationProvider.authenticate(authentication))
105106
.isInstanceOf(OAuth2AuthenticationException.class)
106107
.extracting(ex -> ((OAuth2AuthenticationException) ex).getError())
107108
.extracting("errorCode")
108-
.isEqualTo(OAuth2ErrorCodes.UNSUPPORTED_TOKEN_TYPE);
109+
.isEqualTo(OAuth2ErrorCodes2.UNSUPPORTED_TOKEN_TYPE);
109110
}
110111

111112
@Test

0 commit comments

Comments
 (0)