|
32 | 32 | import org.slf4j.LoggerFactory;
|
33 | 33 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
34 | 34 | import org.springframework.stereotype.Service;
|
| 35 | +import org.springframework.web.client.RestClientException; |
35 | 36 | import org.springframework.web.client.RestTemplate;
|
36 | 37 |
|
37 | 38 | import com.google.common.cache.CacheBuilder;
|
38 | 39 | import com.google.common.cache.CacheLoader;
|
39 | 40 | import com.google.common.cache.LoadingCache;
|
40 | 41 | import com.google.common.util.concurrent.UncheckedExecutionException;
|
| 42 | +import com.google.gson.JsonParseException; |
41 | 43 | import com.nimbusds.jose.jwk.JWKSet;
|
42 | 44 |
|
43 | 45 | /**
|
@@ -136,14 +138,18 @@ private class JWKSetEncryptorFetcher extends CacheLoader<String, JWTEncryptionAn
|
136 | 138 | */
|
137 | 139 | @Override
|
138 | 140 | public JWTEncryptionAndDecryptionService load(String key) throws Exception {
|
139 |
| -String jsonString = restTemplate.getForObject(key, String.class); |
140 |
| -JWKSet jwkSet = JWKSet.parse(jsonString); |
141 |
| - |
142 |
| -JWKSetKeyStore keyStore = new JWKSetKeyStore(jwkSet); |
143 |
| - |
144 |
| -JWTEncryptionAndDecryptionService service = new DefaultJWTEncryptionAndDecryptionService(keyStore); |
145 |
| - |
146 |
| -return service; |
| 141 | +try { |
| 142 | +String jsonString = restTemplate.getForObject(key, String.class); |
| 143 | +JWKSet jwkSet = JWKSet.parse(jsonString); |
| 144 | + |
| 145 | +JWKSetKeyStore keyStore = new JWKSetKeyStore(jwkSet); |
| 146 | + |
| 147 | +JWTEncryptionAndDecryptionService service = new DefaultJWTEncryptionAndDecryptionService(keyStore); |
| 148 | + |
| 149 | +return service; |
| 150 | +} catch (JsonParseException | RestClientException e) { |
| 151 | +throw new IllegalArgumentException("Unable to load JWK Set"); |
| 152 | +} |
147 | 153 | }
|
148 | 154 | }
|
149 | 155 |
|
|
0 commit comments