From 1840a67aadb62adc152737c1528e1f72d153d6ad Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Thu, 22 Aug 2013 14:08:54 -0400 Subject: [PATCH] explicitly try to initialize the JWK set if it's null by the time the getter is called --- .../mitre/jose/keystore/JWKSetKeyStore.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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(); }