Skip to content

Commit d76d209

Browse files
committed
Add temporary OAuth2ParameterNames2
Issue spring-projects/spring-security#9183
1 parent 58ad2d2 commit d76d209

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.endpoint;
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/9183">Issue gh-9183</a>
25+
*/
26+
public interface OAuth2ParameterNames2 extends OAuth2ParameterNames {
27+
28+
String TOKEN = "token";
29+
30+
String TOKEN_TYPE_HINT = "token_type_hint";
31+
32+
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
2727
import org.springframework.security.oauth2.core.OAuth2Error;
2828
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
29-
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
29+
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames2;
3030
import org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter;
3131
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenRevocationAuthenticationProvider;
3232
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenRevocationAuthenticationToken;
@@ -131,17 +131,17 @@ public Authentication convert(HttpServletRequest request) {
131131
MultiValueMap<String, String> parameters = OAuth2EndpointUtils.getParameters(request);
132132

133133
// token (REQUIRED)
134-
String token = parameters.getFirst(OAuth2ParameterNames.TOKEN);
134+
String token = parameters.getFirst(OAuth2ParameterNames2.TOKEN);
135135
if (!StringUtils.hasText(token) ||
136-
parameters.get(OAuth2ParameterNames.TOKEN).size() != 1) {
137-
throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.TOKEN);
136+
parameters.get(OAuth2ParameterNames2.TOKEN).size() != 1) {
137+
throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames2.TOKEN);
138138
}
139139

140140
// token_type_hint (OPTIONAL)
141-
String tokenTypeHint = parameters.getFirst(OAuth2ParameterNames.TOKEN_TYPE_HINT);
141+
String tokenTypeHint = parameters.getFirst(OAuth2ParameterNames2.TOKEN_TYPE_HINT);
142142
if (StringUtils.hasText(tokenTypeHint) &&
143-
parameters.get(OAuth2ParameterNames.TOKEN_TYPE_HINT).size() != 1) {
144-
throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.TOKEN_TYPE_HINT);
143+
parameters.get(OAuth2ParameterNames2.TOKEN_TYPE_HINT).size() != 1) {
144+
throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames2.TOKEN_TYPE_HINT);
145145
}
146146

147147
return new OAuth2TokenRevocationAuthenticationToken(token, clientPrincipal, tokenTypeHint);

oauth2-authorization-server/src/test/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/authorization/OAuth2TokenRevocationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
3333
import org.springframework.security.oauth2.core.OAuth2AccessToken;
3434
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
35-
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
35+
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames2;
3636
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
3737
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
3838
import org.springframework.security.oauth2.server.authorization.TestOAuth2Authorizations;
@@ -153,8 +153,8 @@ public void requestWhenRevokeAccessTokenThenRevoked() throws Exception {
153153

154154
private static MultiValueMap<String, String> getTokenRevocationRequestParameters(AbstractOAuth2Token token, TokenType tokenType) {
155155
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
156-
parameters.set(OAuth2ParameterNames.TOKEN, token.getTokenValue());
157-
parameters.set(OAuth2ParameterNames.TOKEN_TYPE_HINT, tokenType.getValue());
156+
parameters.set(OAuth2ParameterNames2.TOKEN, token.getTokenValue());
157+
parameters.set(OAuth2ParameterNames2.TOKEN_TYPE_HINT, tokenType.getValue());
158158
return parameters;
159159
}
160160

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/web/OAuth2TokenRevocationEndpointFilterTests.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.security.oauth2.core.OAuth2AccessToken;
3131
import org.springframework.security.oauth2.core.OAuth2Error;
3232
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
33-
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
33+
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames2;
3434
import org.springframework.security.oauth2.core.http.converter.OAuth2ErrorHttpMessageConverter;
3535
import org.springframework.security.oauth2.server.authorization.TokenType;
3636
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;
@@ -121,25 +121,25 @@ public void doFilterWhenTokenRevocationRequestGetThenNotProcessed() throws Excep
121121
@Test
122122
public void doFilterWhenTokenRevocationRequestMissingTokenThenInvalidRequestError() throws Exception {
123123
doFilterWhenTokenRevocationRequestInvalidParameterThenError(
124-
OAuth2ParameterNames.TOKEN,
124+
OAuth2ParameterNames2.TOKEN,
125125
OAuth2ErrorCodes.INVALID_REQUEST,
126-
request -> request.removeParameter(OAuth2ParameterNames.TOKEN));
126+
request -> request.removeParameter(OAuth2ParameterNames2.TOKEN));
127127
}
128128

129129
@Test
130130
public void doFilterWhenTokenRevocationRequestMultipleTokenThenInvalidRequestError() throws Exception {
131131
doFilterWhenTokenRevocationRequestInvalidParameterThenError(
132-
OAuth2ParameterNames.TOKEN,
132+
OAuth2ParameterNames2.TOKEN,
133133
OAuth2ErrorCodes.INVALID_REQUEST,
134-
request -> request.addParameter(OAuth2ParameterNames.TOKEN, "token-2"));
134+
request -> request.addParameter(OAuth2ParameterNames2.TOKEN, "token-2"));
135135
}
136136

137137
@Test
138138
public void doFilterWhenTokenRevocationRequestMultipleTokenTypeHintThenInvalidRequestError() throws Exception {
139139
doFilterWhenTokenRevocationRequestInvalidParameterThenError(
140-
OAuth2ParameterNames.TOKEN_TYPE_HINT,
140+
OAuth2ParameterNames2.TOKEN_TYPE_HINT,
141141
OAuth2ErrorCodes.INVALID_REQUEST,
142-
request -> request.addParameter(OAuth2ParameterNames.TOKEN_TYPE_HINT, TokenType.ACCESS_TOKEN.getValue()));
142+
request -> request.addParameter(OAuth2ParameterNames2.TOKEN_TYPE_HINT, TokenType.ACCESS_TOKEN.getValue()));
143143
}
144144

145145
@Test
@@ -201,8 +201,8 @@ private static MockHttpServletRequest createTokenRevocationRequest() {
201201
MockHttpServletRequest request = new MockHttpServletRequest("POST", requestUri);
202202
request.setServletPath(requestUri);
203203

204-
request.addParameter(OAuth2ParameterNames.TOKEN, "token");
205-
request.addParameter(OAuth2ParameterNames.TOKEN_TYPE_HINT, TokenType.ACCESS_TOKEN.getValue());
204+
request.addParameter(OAuth2ParameterNames2.TOKEN, "token");
205+
request.addParameter(OAuth2ParameterNames2.TOKEN_TYPE_HINT, TokenType.ACCESS_TOKEN.getValue());
206206

207207
return request;
208208
}

0 commit comments

Comments
 (0)