|
|
|
@ -85,6 +85,7 @@ import static org.mockito.ArgumentMatchers.any; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.Mockito.doAnswer; |
|
|
|
import static org.mockito.Mockito.doAnswer; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.never; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
@ -283,16 +284,15 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests { |
|
|
|
assertThat(updatedAuthorization.getRefreshToken().isInvalidated()).isTrue(); |
|
|
|
assertThat(updatedAuthorization.getRefreshToken().isInvalidated()).isTrue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// gh PR 1233
|
|
|
|
// gh-1233
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void authenticateWhenInvalidatedCodeAndNullRefreshAndAccessTokensThenThrowOAuth2AuthenticationException() { |
|
|
|
public void authenticateWhenInvalidatedCodeAndAccessTokenNullThenThrowOAuth2AuthenticationException() { |
|
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build(); |
|
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build(); |
|
|
|
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode( |
|
|
|
OAuth2AuthorizationCode authorizationCode = new OAuth2AuthorizationCode( |
|
|
|
AUTHORIZATION_CODE, Instant.now(), Instant.now().plusSeconds(120)); |
|
|
|
AUTHORIZATION_CODE, Instant.now(), Instant.now().plusSeconds(120)); |
|
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient, authorizationCode) |
|
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient, authorizationCode) |
|
|
|
.token(authorizationCode, (metadata) -> metadata.put(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME, true)) |
|
|
|
.token(authorizationCode, (metadata) -> metadata.put(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME, true)) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
when(this.authorizationService.findByToken(eq(AUTHORIZATION_CODE), eq(AUTHORIZATION_CODE_TOKEN_TYPE))) |
|
|
|
when(this.authorizationService.findByToken(eq(AUTHORIZATION_CODE), eq(AUTHORIZATION_CODE_TOKEN_TYPE))) |
|
|
|
.thenReturn(authorization); |
|
|
|
.thenReturn(authorization); |
|
|
|
|
|
|
|
|
|
|
|
@ -308,6 +308,8 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests { |
|
|
|
.extracting(ex -> ((OAuth2AuthenticationException) ex).getError()) |
|
|
|
.extracting(ex -> ((OAuth2AuthenticationException) ex).getError()) |
|
|
|
.extracting("errorCode") |
|
|
|
.extracting("errorCode") |
|
|
|
.isEqualTo(OAuth2ErrorCodes.INVALID_GRANT); |
|
|
|
.isEqualTo(OAuth2ErrorCodes.INVALID_GRANT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(this.authorizationService, never()).save(any()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// gh-290
|
|
|
|
// gh-290
|
|
|
|
|