| 
42 | 42 | import com.nimbusds.jose.JWSSigner;  | 
43 | 43 | import com.nimbusds.jose.crypto.MACSigner;  | 
44 | 44 | import com.nimbusds.jose.crypto.RSASSASigner;  | 
 | 45 | +import com.nimbusds.jose.jwk.JWKSet;  | 
45 | 46 | import com.nimbusds.jose.jwk.source.JWKSource;  | 
46 | 47 | import com.nimbusds.jose.proc.BadJOSEException;  | 
47 | 48 | import com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier;  | 
 | 
75 | 76 | import org.springframework.web.client.RestClientException;  | 
76 | 77 | import org.springframework.web.client.RestOperations;  | 
77 | 78 | 
 
  | 
78 |  | -import static org.assertj.core.api.Assertions.assertThat;  | 
79 |  | -import static org.assertj.core.api.Assertions.assertThatExceptionOfType;  | 
80 |  | -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;  | 
81 |  | -import static org.assertj.core.api.Assertions.assertThatIllegalStateException;  | 
 | 79 | +import javax.crypto.SecretKey;  | 
 | 80 | +import java.security.KeyFactory;  | 
 | 81 | +import java.security.NoSuchAlgorithmException;  | 
 | 82 | +import java.security.PrivateKey;  | 
 | 83 | +import java.security.interfaces.RSAPrivateKey;  | 
 | 84 | +import java.security.interfaces.RSAPublicKey;  | 
 | 85 | +import java.security.spec.EncodedKeySpec;  | 
 | 86 | +import java.security.spec.InvalidKeySpecException;  | 
 | 87 | +import java.security.spec.X509EncodedKeySpec;  | 
 | 88 | +import java.text.ParseException;  | 
 | 89 | +import java.time.Instant;  | 
 | 90 | +import java.util.*;  | 
 | 91 | + | 
 | 92 | +import static org.assertj.core.api.Assertions.*;  | 
82 | 93 | import static org.mockito.ArgumentMatchers.any;  | 
83 | 94 | import static org.mockito.ArgumentMatchers.eq;  | 
84 | 95 | import static org.mockito.BDDMockito.given;  | 
85 |  | -import static org.mockito.Mockito.mock;  | 
86 |  | -import static org.mockito.Mockito.times;  | 
87 |  | -import static org.mockito.Mockito.verify;  | 
88 |  | -import static org.mockito.Mockito.verifyNoInteractions;  | 
89 |  | -import static org.mockito.Mockito.verifyNoMoreInteractions;  | 
 | 96 | +import static org.mockito.Mockito.*;  | 
90 | 97 | 
 
  | 
91 | 98 | /**  | 
92 | 99 |  * Tests for {@link NimbusJwtDecoder}  | 
@@ -559,6 +566,22 @@ public void decodeWhenUsingSecretKeyWithKidThenStillUsesKey() throws Exception {  | 
559 | 566 | 		// @formatter:on  | 
560 | 567 | 	}  | 
561 | 568 | 
 
  | 
 | 569 | +	// gh-7056  | 
 | 570 | +	@Test  | 
 | 571 | +	public void decodeWhenUsingJwkSource() throws Exception {  | 
 | 572 | +		JWKSource<SecurityContext> source = (a, b) -> {  | 
 | 573 | +			try {  | 
 | 574 | +				return JWKSet.parse(JWK_SET).getKeys();  | 
 | 575 | +			}  | 
 | 576 | +			catch (ParseException e) {  | 
 | 577 | +				throw new RuntimeException(e);  | 
 | 578 | +			}  | 
 | 579 | +		};  | 
 | 580 | +		NimbusJwtDecoder decoder = NimbusJwtDecoder.withJwkSource(source).build();  | 
 | 581 | +		Jwt jwt = decoder.decode(SIGNED_JWT);  | 
 | 582 | +		assertThat(jwt.getClaimAsString("sub")).isEqualTo("test-subject");  | 
 | 583 | +	}  | 
 | 584 | + | 
562 | 585 | 	// gh-8730  | 
563 | 586 | 	@Test  | 
564 | 587 | 	public void withSecretKeyWhenUsingCustomTypeHeaderThenSuccessfullyDecodes() throws Exception {  | 
 | 
0 commit comments