diff --git a/openid-connect-common/src/main/java/org/mitre/jose/keystore/JWKSetKeyStore.java b/openid-connect-common/src/main/java/org/mitre/jose/keystore/JWKSetKeyStore.java index 4fc4d97eb..c464f06dd 100644 --- a/openid-connect-common/src/main/java/org/mitre/jose/keystore/JWKSetKeyStore.java +++ b/openid-connect-common/src/main/java/org/mitre/jose/keystore/JWKSetKeyStore.java @@ -19,7 +19,9 @@ */ package org.mitre.jose.keystore; +import java.io.IOException; import java.io.InputStreamReader; +import java.text.ParseException; import java.util.List; import javax.annotation.PostConstruct; @@ -50,18 +52,23 @@ public class JWKSetKeyStore { } @PostConstruct - public void afterPropertiesSet() throws Exception { + private void initializeJwkSet() { if (jwkSet == null) { if (location != null) { if (location.exists() && location.isReadable()) { - // read in the file from disk - String s = CharStreams.toString(new InputStreamReader(location.getInputStream(), Charsets.UTF_8)); + try { + // read in the file from disk + String s = CharStreams.toString(new InputStreamReader(location.getInputStream(), Charsets.UTF_8)); - // parse it into a jwkSet object - jwkSet = JWKSet.parse(s); + // parse it into a jwkSet object + jwkSet = JWKSet.parse(s); + } catch (IOException e) { + throw new IllegalArgumentException("Key Set resource could not be read: " + location); + } catch (ParseException e) { + throw new IllegalArgumentException("Key Set resource could not be parsed: " + location); } } else { throw new IllegalArgumentException("Key Set resource could not be read: " + location); @@ -105,6 +112,9 @@ public class JWKSetKeyStore { * Get the list of keys in this keystore. This is a passthrough to the underlying JWK Set */ public List getKeys() { + if (jwkSet == null) { + initializeJwkSet(); + } return jwkSet.getKeys(); }