Skip to content

Commit c4ccc96

Browse files
committed
Polish Error Messages for OpaqueTokenIntrospectors
1 parent 6c31021 commit c4ccc96

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ public void getWhenIntrospectionFailsThenUnauthorized() throws Exception {
11271127
.with(bearerToken("token")))
11281128
.andExpect(status().isUnauthorized())
11291129
.andExpect(header().string(HttpHeaders.WWW_AUTHENTICATE,
1130-
containsString("Provided token [token] isn't active")));
1130+
containsString("Provided token isn't active")));
11311131
}
11321132

11331133
@Test

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private MultiValueMap<String, String> requestBody(String token) {
133133
public OAuth2AuthenticatedPrincipal introspect(String token) {
134134
RequestEntity<?> requestEntity = this.requestEntityConverter.convert(token);
135135
if (requestEntity == null) {
136-
throw new OAuth2IntrospectionException("Provided token [" + token + "] isn't active");
136+
throw new OAuth2IntrospectionException("requestEntityConverter returned a null entity");
137137
}
138138

139139
ResponseEntity<String> responseEntity = makeRequest(requestEntity);
@@ -143,7 +143,7 @@ public OAuth2AuthenticatedPrincipal introspect(String token) {
143143

144144
// relying solely on the authorization server to validate this token (not checking 'exp', for example)
145145
if (!introspectionSuccessResponse.isActive()) {
146-
throw new OAuth2IntrospectionException("Provided token [" + token + "] isn't active");
146+
throw new OAuth2IntrospectionException("Provided token isn't active");
147147
}
148148

149149
return convertClaimsSet(introspectionSuccessResponse);

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusReactiveOpaqueTokenIntrospector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private TokenIntrospectionSuccessResponse castToNimbusSuccess(TokenIntrospection
154154
private void validate(String token, TokenIntrospectionSuccessResponse response) {
155155
// relying solely on the authorization server to validate this token (not checking 'exp', for example)
156156
if (!response.isActive()) {
157-
throw new OAuth2IntrospectionException("Provided token [" + token + "] isn't active");
157+
throw new OAuth2IntrospectionException("Provided token isn't active");
158158
}
159159
}
160160

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospectorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void introspectWhenInactiveTokenThenInvalidToken() {
168168
assertThatCode(() -> introspectionClient.introspect("token"))
169169
.isInstanceOf(OAuth2IntrospectionException.class)
170170
.extracting("message")
171-
.containsExactly("Provided token [token] isn't active");
171+
.containsExactly("Provided token isn't active");
172172
}
173173

174174
@Test

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/introspection/NimbusReactiveOpaqueTokenIntrospectorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void authenticateWhenInactiveTokenThenInvalidToken() {
142142
assertThatCode(() -> introspectionClient.introspect("token").block())
143143
.isInstanceOf(OAuth2IntrospectionException.class)
144144
.extracting("message")
145-
.containsExactly("Provided token [token] isn't active");
145+
.containsExactly("Provided token isn't active");
146146
}
147147

148148
@Test

0 commit comments

Comments
 (0)