|
@@ -15,6 +15,8 @@
|
|
*/
|
|
*/
|
|
package org.springframework.security.oauth2.server.authorization.authentication;
|
|
package org.springframework.security.oauth2.server.authorization.authentication;
|
|
|
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -182,6 +184,26 @@ public class ClientSecretAuthenticationProviderTests {
|
|
verify(this.passwordEncoder).matches(any(), any());
|
|
verify(this.passwordEncoder).matches(any(), any());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void authenticateWhenExpiredClientSecretThenThrowOAuth2AuthenticationException() {
|
|
|
|
+ RegisteredClient registeredClient = TestRegisteredClients.registeredClient()
|
|
|
|
+ .clientSecretExpiresAt(Instant.now().minus(1, ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS))
|
|
|
|
+ .build();
|
|
|
|
+ when(this.registeredClientRepository.findByClientId(eq(registeredClient.getClientId())))
|
|
|
|
+ .thenReturn(registeredClient);
|
|
|
|
+
|
|
|
|
+ OAuth2ClientAuthenticationToken authentication = new OAuth2ClientAuthenticationToken(
|
|
|
|
+ registeredClient.getClientId(), ClientAuthenticationMethod.CLIENT_SECRET_BASIC, registeredClient.getClientSecret(), null);
|
|
|
|
+ assertThatThrownBy(() -> this.authenticationProvider.authenticate(authentication))
|
|
|
|
+ .isInstanceOf(OAuth2AuthenticationException.class)
|
|
|
|
+ .extracting(ex -> ((OAuth2AuthenticationException) ex).getError())
|
|
|
|
+ .satisfies(error -> {
|
|
|
|
+ assertThat(error.getErrorCode()).isEqualTo(OAuth2ErrorCodes.INVALID_CLIENT);
|
|
|
|
+ assertThat(error.getDescription()).contains("client_secret_expires_at");
|
|
|
|
+ });
|
|
|
|
+ verify(this.passwordEncoder).matches(any(), any());
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void authenticateWhenValidCredentialsThenAuthenticated() {
|
|
public void authenticateWhenValidCredentialsThenAuthenticated() {
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|