From 07ccbdc3db827a180cfda9926f23bd0c596e2d37 Mon Sep 17 00:00:00 2001 From: stianst Date: Wed, 2 Jan 2019 11:49:28 +0100 Subject: [PATCH] KEYCLOAK-9182 --- .../oidc/endpoints/UserInfoEndpoint.java | 2 +- .../keycloak/testsuite/oidc/UserInfoTest.java | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/UserInfoEndpoint.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/UserInfoEndpoint.java index a486aa8fb4..40c4d767b5 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/UserInfoEndpoint.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/UserInfoEndpoint.java @@ -132,7 +132,7 @@ public class UserInfoEndpoint { AccessToken token; try { - TokenVerifier verifier = TokenVerifier.create(tokenString, AccessToken.class) + TokenVerifier verifier = TokenVerifier.create(tokenString, AccessToken.class).withDefaultChecks() .realmUrl(Urls.realmIssuer(session.getContext().getUri().getBaseUri(), realm.getName())); SignatureVerifierContext verifierContext = session.getProvider(SignatureProvider.class, verifier.getHeader().getAlgorithm().name()).verifier(verifier.getHeader().getKeyId()); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/UserInfoTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/UserInfoTest.java index 8d4ed90d34..9ac31c696d 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/UserInfoTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/oidc/UserInfoTest.java @@ -25,6 +25,7 @@ import org.keycloak.admin.client.resource.ClientResource; import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.UserResource; import org.keycloak.common.util.PemUtils; +import org.keycloak.common.util.Time; import org.keycloak.events.Details; import org.keycloak.events.Errors; import org.keycloak.events.EventType; @@ -338,7 +339,7 @@ public class UserInfoTest extends AbstractKeycloakTest { } @Test - public void testSessionExpired() throws Exception { + public void testSessionExpired() { Client client = ClientBuilder.newClient(); try { @@ -364,6 +365,33 @@ public class UserInfoTest extends AbstractKeycloakTest { } } + @Test + public void testAccessTokenExpired() { + Client client = ClientBuilder.newClient(); + + try { + AccessTokenResponse accessTokenResponse = executeGrantAccessTokenRequest(client); + + setTimeOffset(600); + + Response response = UserInfoClientUtil.executeUserInfoRequest_getMethod(client, accessTokenResponse.getToken()); + + assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); + + response.close(); + + events.expect(EventType.USER_INFO_REQUEST_ERROR) + .error(Errors.INVALID_TOKEN) + .user(Matchers.nullValue(String.class)) + .session(Matchers.nullValue(String.class)) + .detail(Details.AUTH_METHOD, Details.VALIDATE_ACCESS_TOKEN) + .client((String) null) + .assertEvent(); + } finally { + client.close(); + } + } + @Test public void testSessionExpiredOfflineAccess() throws Exception { Client client = ClientBuilder.newClient();