Skip to content

Commit b58d5bd

Browse files
committed
Fixes #328
1 parent 5d67d14 commit b58d5bd

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

oidc/src/main/java/oidc/endpoints/UserInfoEndpoint.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ private ResponseEntity<Map<String, Object>> userInfo(HttpServletRequest request)
5656
String accessTokenValue = userInfoRequest.getAccessToken().getValue();
5757

5858
MDCContext.mdcContext("action", "Userinfo", "accessTokenValue", accessTokenValue);
59+
Optional<SignedJWT> optionalSignedJWT;
60+
try {
61+
optionalSignedJWT = tokenGenerator.parseAndValidateSignedJWT(accessTokenValue);
62+
} catch (IllegalArgumentException e) {
63+
//Thrown when the signing key has been deleted, which only happens when all access_tokens with that key are gone
64+
return errorResponse("Access Token not found");
65+
}
5966

60-
Optional<SignedJWT> optionalSignedJWT = tokenGenerator.parseAndValidateSignedJWT(accessTokenValue);
6167
if (!optionalSignedJWT.isPresent()) {
6268
return errorResponse("Access Token not found");
6369
}

oidc/src/test/java/oidc/AbstractIntegrationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import oidc.endpoints.MapTypeReference;
2929
import oidc.model.*;
3030
import oidc.repository.SequenceRepository;
31+
import oidc.repository.SigningKeyRepository;
3132
import oidc.secure.TokenGenerator;
3233
import org.junit.Before;
3334
import org.junit.runner.RunWith;
@@ -99,6 +100,9 @@ public abstract class AbstractIntegrationTest implements TestUtils, MapTypeRefer
99100
@Autowired
100101
protected SequenceRepository sequenceRepository;
101102

103+
@Autowired
104+
protected SigningKeyRepository signingKeyRepository;
105+
102106
private List<OpenIDClient> openIDClients;
103107

104108
@Before

oidc/src/test/java/oidc/endpoints/UserInfoEndpointTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import oidc.web.CustomErrorController;
1111
import org.junit.Test;
1212
import org.slf4j.LoggerFactory;
13+
import org.springframework.http.HttpStatus;
1314

1415
import java.io.IOException;
1516
import java.text.ParseException;
@@ -32,6 +33,22 @@ public void postUserInfo() throws IOException {
3233
userInfo("POST");
3334
}
3435

36+
@Test
37+
public void signingKeyNotFound() throws IOException {
38+
String accessToken = getAccessToken();
39+
40+
signingKeyRepository.deleteAll();
41+
sequenceRepository.updateSigningKeyId("test");
42+
43+
given()
44+
.when()
45+
.header("Content-type", "application/x-www-form-urlencoded")
46+
.queryParams("access_token", accessToken)
47+
.get("oidc/userinfo")
48+
.then()
49+
.statusCode(HttpStatus.UNAUTHORIZED.value());
50+
}
51+
3552
@Test
3653
public void userInfoExpired() throws IOException, ParseException {
3754
String token = getAccessToken();
@@ -132,4 +149,4 @@ private void assertResponse(Response response) {
132149
assertTrue(result.containsKey("sub"));
133150
assertTrue(result.containsKey("acr"));
134151
}
135-
}
152+
}

0 commit comments

Comments
 (0)