Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void revokeClient() {
private void revokeAccessToken() {
SingleUseObjectProvider singleUseStore = session.singleUseObjects();
int currentTime = Time.currentTime();
long lifespanInSecs = Math.max(token.getExp() - currentTime, 10);
long lifespanInSecs = Math.max(token.getExp() - currentTime + 1, 10);
singleUseStore.put(token.getId() + SingleUseObjectProvider.REVOKED_KEY, lifespanInSecs, Collections.emptyMap());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.keycloak.testsuite.util.OAuthClient.AccessTokenResponse;
import org.keycloak.testsuite.util.RealmBuilder;
import org.keycloak.testsuite.util.UserInfoClientUtil;
import org.keycloak.testsuite.util.InfinispanTestTimeServiceRule;
import org.keycloak.util.JsonSerialization;

/**
Expand All @@ -84,6 +85,9 @@ public class TokenRevocationTest extends AbstractKeycloakTest {
@Rule
public AssertEvents events = new AssertEvents(this);

@Rule
public InfinispanTestTimeServiceRule ispnTestTimeService = new InfinispanTestTimeServiceRule(this);

@Override
public void beforeAbstractKeycloakTest() throws Exception {
super.beforeAbstractKeycloakTest();
Expand Down Expand Up @@ -171,6 +175,23 @@ public void testRevokeAccessToken() throws Exception {
isAccessTokenDisabled(tokenResponse.getAccessToken(), "test-app");
}

@Test
public void testRevokedAccessTokenCacheLifespan() throws Exception {
oauth.clientId("test-app");
OAuthClient.AccessTokenResponse tokenResponse = oauth.doGrantAccessTokenRequest("password", "test-user@localhost", "password");

isTokenEnabled(tokenResponse, "test-app");

CloseableHttpResponse response = oauth.doTokenRevoke(tokenResponse.getAccessToken(), "access_token", "password");
assertThat(response, Matchers.statusCodeIsHC(Status.OK));

setTimeOffset(adminClient.realm(oauth.getRealm()).toRepresentation().getAccessTokenLifespan());

isAccessTokenDisabled(tokenResponse.getAccessToken(), "test-app");

setTimeOffset(0);
}

@Test
public void testRevokeOfflineToken() throws Exception {
oauth.scope(OAuth2Constants.OFFLINE_ACCESS);
Expand Down