Removed @PostConstruct; placed buildSignersAndVerifiers() calls inside both constructors.
parent
c22cd62977
commit
85d9e07a94
|
@ -24,8 +24,6 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
import org.mitre.jose.keystore.JWKSetKeyStore;
|
import org.mitre.jose.keystore.JWKSetKeyStore;
|
||||||
import org.mitre.jwt.signer.service.JwtSigningAndValidationService;
|
import org.mitre.jwt.signer.service.JwtSigningAndValidationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -62,7 +60,7 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
||||||
|
|
||||||
// map of identifier to key
|
// map of identifier to key
|
||||||
private Map<String, JWK> keys = new HashMap<String, JWK>();
|
private Map<String, JWK> keys = new HashMap<String, JWK>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build this service based on the keys given. All public keys will be used
|
* Build this service based on the keys given. All public keys will be used
|
||||||
* to make verifiers, all private keys will be used to make signers.
|
* to make verifiers, all private keys will be used to make signers.
|
||||||
|
@ -77,7 +75,7 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
||||||
*/
|
*/
|
||||||
public DefaultJwtSigningAndValidationService(Map<String, JWK> keys) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
public DefaultJwtSigningAndValidationService(Map<String, JWK> keys) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
//buildSignersAndVerifiers();
|
buildSignersAndVerifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,29 +93,18 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
||||||
public DefaultJwtSigningAndValidationService(JWKSetKeyStore keyStore) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
public DefaultJwtSigningAndValidationService(JWKSetKeyStore keyStore) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
// convert all keys in the keystore to a map based on key id
|
// convert all keys in the keystore to a map based on key id
|
||||||
if (keyStore!= null && keyStore.getJwkSet() != null) {
|
if (keyStore!= null && keyStore.getJwkSet() != null) {
|
||||||
for (JWK key : keyStore.getKeys()) {
|
for (JWK key : keyStore.getKeys()) {
|
||||||
if (!Strings.isNullOrEmpty(key.getKeyID())) {
|
if (!Strings.isNullOrEmpty(key.getKeyID())) {
|
||||||
this.keys.put(key.getKeyID(), key);
|
this.keys.put(key.getKeyID(), key);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Tried to load a key from a keystore without a 'kid' field: " + key);
|
throw new IllegalArgumentException("Tried to load a key from a keystore without a 'kid' field: " + key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//buildSignersAndVerifiers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void afterPropertiesSet() throws NoSuchAlgorithmException, InvalidKeySpecException{
|
|
||||||
|
|
||||||
if (keys == null) {
|
|
||||||
throw new IllegalArgumentException("Signing and validation service must have at least one key configured.");
|
|
||||||
}
|
|
||||||
|
|
||||||
buildSignersAndVerifiers();
|
buildSignersAndVerifiers();
|
||||||
|
|
||||||
logger.info("DefaultJwtSigningAndValidationService is ready: " + this.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the defaultSignerKeyId
|
* @return the defaultSignerKeyId
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue