|
30 | 30 | import org.junit.jupiter.api.Test;
|
31 | 31 |
|
32 | 32 | import org.springframework.security.authentication.TestingAuthenticationToken;
|
| 33 | +import org.springframework.security.core.Authentication; |
33 | 34 | import org.springframework.security.core.session.SessionInformation;
|
34 | 35 | import org.springframework.security.core.session.SessionRegistry;
|
35 | 36 | import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
@@ -134,7 +135,7 @@ public void authenticateWhenIdTokenNotFoundThenThrowOAuth2AuthenticationExceptio
|
134 | 135 | }
|
135 | 136 |
|
136 | 137 | @Test
|
137 |
| - public void authenticateWhenIdTokenNotActiveThenThrowOAuth2AuthenticationException() { |
| 138 | + public void authenticateWhenIdTokenInvalidatedThenThrowOAuth2AuthenticationException() { |
138 | 139 | TestingAuthenticationToken principal = new TestingAuthenticationToken("principal", "credentials");
|
139 | 140 | RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
140 | 141 | OidcIdToken idToken = OidcIdToken.withTokenValue("id-token")
|
@@ -501,6 +502,28 @@ public void authenticateWhenValidIdTokenThenAuthenticated() throws Exception {
|
501 | 502 | .expiresAt(Instant.now().plusSeconds(60).truncatedTo(ChronoUnit.MILLIS))
|
502 | 503 | .claim("sid", createHash(sessionId))
|
503 | 504 | .build();
|
| 505 | + authenticateValidIdToken(principal, registeredClient, sessionId, idToken); |
| 506 | + } |
| 507 | + |
| 508 | + // gh-1440 |
| 509 | + @Test |
| 510 | + public void authenticateWhenValidExpiredIdTokenThenAuthenticated() throws Exception { |
| 511 | + TestingAuthenticationToken principal = new TestingAuthenticationToken("principal", "credentials"); |
| 512 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build(); |
| 513 | + String sessionId = "session-1"; |
| 514 | + OidcIdToken idToken = OidcIdToken.withTokenValue("id-token") |
| 515 | + .issuer("https://provider.com") |
| 516 | + .subject(principal.getName()) |
| 517 | + .audience(Collections.singleton(registeredClient.getClientId())) |
| 518 | + .issuedAt(Instant.now().minusSeconds(60).truncatedTo(ChronoUnit.MILLIS)) |
| 519 | + .expiresAt(Instant.now().minusSeconds(30).truncatedTo(ChronoUnit.MILLIS)) // Expired |
| 520 | + .claim("sid", createHash(sessionId)) |
| 521 | + .build(); |
| 522 | + authenticateValidIdToken(principal, registeredClient, sessionId, idToken); |
| 523 | + } |
| 524 | + |
| 525 | + private void authenticateValidIdToken(Authentication principal, RegisteredClient registeredClient, |
| 526 | + String sessionId, OidcIdToken idToken) { |
504 | 527 | OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
505 | 528 | .principalName(principal.getName())
|
506 | 529 | .token(idToken,
|
|
0 commit comments