| 
26 | 26 | import java.util.Map;  | 
27 | 27 | import java.util.UUID;  | 
28 | 28 | 
 
  | 
 | 29 | +import com.nimbusds.jose.jwk.JWK;  | 
29 | 30 | import com.nimbusds.jose.jwk.JWKSet;  | 
30 | 31 | import com.nimbusds.jose.jwk.source.JWKSource;  | 
31 | 32 | import com.nimbusds.jose.proc.SecurityContext;  | 
@@ -218,8 +219,8 @@ public void authenticateWhenJktMissingThenThrowOAuth2AuthenticationException() t  | 
218 | 219 | 
 
  | 
219 | 220 | 	@Test  | 
220 | 221 | 	public void authenticateWhenJktDoesNotMatchThenThrowOAuth2AuthenticationException() throws Exception {  | 
221 |  | -		// Use different client public key  | 
222 |  | -		Jwt accessToken = generateAccessToken(TestKeys.DEFAULT_EC_KEY_PAIR.getPublic());  | 
 | 222 | +		// Use different jwk to make it not match  | 
 | 223 | +		Jwt accessToken = generateAccessToken(TestJwks.DEFAULT_EC_JWK);  | 
223 | 224 | 		JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken(accessToken);  | 
224 | 225 | 		given(this.tokenAuthenticationManager.authenticate(any())).willReturn(jwtAuthenticationToken);  | 
225 | 226 | 
 
  | 
@@ -285,14 +286,14 @@ public void authenticateWhenDPoPProofValidThenSuccess() throws Exception {  | 
285 | 286 | 	}  | 
286 | 287 | 
 
  | 
287 | 288 | 	private Jwt generateAccessToken() {  | 
288 |  | -		return generateAccessToken(TestKeys.DEFAULT_PUBLIC_KEY);  | 
 | 289 | +		return generateAccessToken(TestJwks.DEFAULT_RSA_JWK);  | 
289 | 290 | 	}  | 
290 | 291 | 
 
  | 
291 |  | -	private Jwt generateAccessToken(PublicKey clientPublicKey) {  | 
 | 292 | +	private Jwt generateAccessToken(JWK clientJwk) {  | 
292 | 293 | 		Map<String, Object> jktClaim = null;  | 
293 |  | -		if (clientPublicKey != null) {  | 
 | 294 | +		if (clientJwk != null) {  | 
294 | 295 | 			try {  | 
295 |  | -				String sha256Thumbprint = computeSHA256(clientPublicKey);  | 
 | 296 | +				String sha256Thumbprint = clientJwk.computeThumbprint().toString();  | 
296 | 297 | 				jktClaim = new HashMap<>();  | 
297 | 298 | 				jktClaim.put("jkt", sha256Thumbprint);  | 
298 | 299 | 			}  | 
@@ -321,11 +322,4 @@ private static String computeSHA256(String value) throws Exception {  | 
321 | 322 | 		byte[] digest = md.digest(value.getBytes(StandardCharsets.UTF_8));  | 
322 | 323 | 		return Base64.getUrlEncoder().withoutPadding().encodeToString(digest);  | 
323 | 324 | 	}  | 
324 |  | - | 
325 |  | -	private static String computeSHA256(PublicKey publicKey) throws Exception {  | 
326 |  | -		MessageDigest md = MessageDigest.getInstance("SHA-256");  | 
327 |  | -		byte[] digest = md.digest(publicKey.getEncoded());  | 
328 |  | -		return Base64.getUrlEncoder().withoutPadding().encodeToString(digest);  | 
329 |  | -	}  | 
330 |  | - | 
331 | 325 | }  | 
0 commit comments