adapted keyfetcher to be more general
parent
abd64eccd6
commit
c946a84b09
|
@ -608,10 +608,10 @@ public class AbstractOIDCAuthenticationFilter extends
|
||||||
|
|
||||||
if (serverConfig.getJwkSigningUrl() != null) {
|
if (serverConfig.getJwkSigningUrl() != null) {
|
||||||
// prefer the JWK
|
// prefer the JWK
|
||||||
signingKey = keyFetch.retrieveJwkKey(serverConfig);
|
signingKey = keyFetch.retrieveJwkKey(serverConfig.getJwkSigningUrl());
|
||||||
} else if (serverConfig.getX509SigningUrl() != null) {
|
} else if (serverConfig.getX509SigningUrl() != null) {
|
||||||
// use the x509 only if JWK isn't configured
|
// use the x509 only if JWK isn't configured
|
||||||
signingKey = keyFetch.retrieveX509Key(serverConfig);
|
signingKey = keyFetch.retrieveX509Key(serverConfig.getX509SigningUrl());
|
||||||
} else {
|
} else {
|
||||||
// no keys configured
|
// no keys configured
|
||||||
logger.warn("No server key URLs configured for " + serverConfig.getIssuer());
|
logger.warn("No server key URLs configured for " + serverConfig.getIssuer());
|
||||||
|
|
|
@ -54,13 +54,13 @@ public class KeyFetcher {
|
||||||
return getArray;
|
return getArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublicKey retrieveX509Key(OIDCServerConfiguration serverConfig) {
|
public PublicKey retrieveX509Key(String x509url) {
|
||||||
|
|
||||||
|
|
||||||
PublicKey key = null;
|
PublicKey key = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream x509Stream = restTemplate.getForObject(serverConfig.getX509SigningUrl(), InputStream.class);
|
InputStream x509Stream = restTemplate.getForObject(x509url, InputStream.class);
|
||||||
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
CertificateFactory factory = CertificateFactory.getInstance("X.509");
|
||||||
X509Certificate cert = (X509Certificate) factory.generateCertificate(x509Stream);
|
X509Certificate cert = (X509Certificate) factory.generateCertificate(x509Stream);
|
||||||
key = cert.getPublicKey();
|
key = cert.getPublicKey();
|
||||||
|
@ -73,11 +73,11 @@ public class KeyFetcher {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublicKey retrieveJwkKey(OIDCServerConfiguration serverConfig) {
|
public PublicKey retrieveJwkKey(String jwkUrl) {
|
||||||
RSAPublicKey pub = null;
|
RSAPublicKey pub = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String jwkString = restTemplate.getForObject(serverConfig.getJwkSigningUrl(), String.class);
|
String jwkString = restTemplate.getForObject(jwkUrl, String.class);
|
||||||
JsonObject json = (JsonObject) new JsonParser().parse(jwkString);
|
JsonObject json = (JsonObject) new JsonParser().parse(jwkString);
|
||||||
JsonArray getArray = json.getAsJsonArray("keys");
|
JsonArray getArray = json.getAsJsonArray("keys");
|
||||||
for(int i = 0; i < getArray.size(); i++) {
|
for(int i = 0; i < getArray.size(); i++) {
|
||||||
|
|
Loading…
Reference in New Issue