Skip to content

Commit bdc0b4d

Browse files
committed
Polish gh-1233
1 parent 6e1ed9f commit bdc0b4d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.security.core.AuthenticationException;
3737
import org.springframework.security.core.session.SessionInformation;
3838
import org.springframework.security.core.session.SessionRegistry;
39-
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
4039
import org.springframework.security.oauth2.core.AuthorizationGrantType;
4140
import org.springframework.security.oauth2.core.ClaimAccessor;
4241
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
@@ -155,7 +154,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
155154

156155
if (!authorizationCode.isActive()) {
157156
if (authorizationCode.isInvalidated()) {
158-
OAuth2Authorization.Token<? extends AbstractOAuth2Token> token = authorization.getRefreshToken() != null ?
157+
OAuth2Authorization.Token<? extends OAuth2Token> token = authorization.getRefreshToken() != null ?
159158
authorization.getRefreshToken() :
160159
authorization.getAccessToken();
161160
if (token != null) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import static org.mockito.ArgumentMatchers.eq;
8686
import static org.mockito.Mockito.doAnswer;
8787
import static org.mockito.Mockito.mock;
88+
import static org.mockito.Mockito.never;
8889
import static org.mockito.Mockito.spy;
8990
import static org.mockito.Mockito.times;
9091
import static org.mockito.Mockito.verify;
@@ -283,16 +284,15 @@ public void authenticateWhenInvalidatedCodeThenThrowOAuth2AuthenticationExceptio
283284
assertThat(updatedAuthorization.getRefreshToken().isInvalidated()).isTrue();
284285
}
285286

286-
// gh PR 1233
287+
// gh-1233
287288
@Test
288-
public void authenticateWhenInvalidatedCodeAndNullRefreshAndAccessTokensThenThrowOAuth2AuthenticationException() {
289+
public void authenticateWhenInvalidatedCodeAndAccessTokenNullThenThrowOAuth2AuthenticationException() {
289290
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
290291
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode(
291292
AUTHORIZATION_CODE, Instant.now(), Instant.now().plusSeconds(120));
292293
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient, authorizationCode)
293294
.token(authorizationCode, (metadata) -> metadata.put(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME, true))
294295
.build();
295-
296296
when(this.authorizationService.findByToken(eq(AUTHORIZATION_CODE), eq(AUTHORIZATION_CODE_TOKEN_TYPE)))
297297
.thenReturn(authorization);
298298

@@ -308,6 +308,8 @@ public void authenticateWhenInvalidatedCodeAndNullRefreshAndAccessTokensThenThro
308308
.extracting(ex -> ((OAuth2AuthenticationException) ex).getError())
309309
.extracting("errorCode")
310310
.isEqualTo(OAuth2ErrorCodes.INVALID_GRANT);
311+
312+
verify(this.authorizationService, never()).save(any());
311313
}
312314

313315
// gh-290

0 commit comments

Comments
 (0)