explicitly try to initialize the JWK set if it's null by the time the getter is called
parent
6a9650d2a7
commit
da915d8b35
|
@ -19,7 +19,9 @@
|
||||||
*/
|
*/
|
||||||
package org.mitre.jose.keystore;
|
package org.mitre.jose.keystore;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -50,18 +52,23 @@ public class JWKSetKeyStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void afterPropertiesSet() throws Exception {
|
private void initializeJwkSet() {
|
||||||
|
|
||||||
if (jwkSet == null) {
|
if (jwkSet == null) {
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
|
|
||||||
if (location.exists() && location.isReadable()) {
|
if (location.exists() && location.isReadable()) {
|
||||||
|
|
||||||
// read in the file from disk
|
try {
|
||||||
String s = CharStreams.toString(new InputStreamReader(location.getInputStream(), Charsets.UTF_8));
|
// read in the file from disk
|
||||||
|
String s = CharStreams.toString(new InputStreamReader(location.getInputStream(), Charsets.UTF_8));
|
||||||
|
|
||||||
// parse it into a jwkSet object
|
// parse it into a jwkSet object
|
||||||
jwkSet = JWKSet.parse(s);
|
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 {
|
} else {
|
||||||
throw new IllegalArgumentException("Key Set resource could not be read: " + location);
|
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
|
* Get the list of keys in this keystore. This is a passthrough to the underlying JWK Set
|
||||||
*/
|
*/
|
||||||
public List<JWK> getKeys() {
|
public List<JWK> getKeys() {
|
||||||
|
if (jwkSet == null) {
|
||||||
|
initializeJwkSet();
|
||||||
|
}
|
||||||
return jwkSet.getKeys();
|
return jwkSet.getKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue