From 2613917668b70937af3287bd743a8738ab9804e9 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 4 Jul 2022 11:53:46 +1000 Subject: [PATCH] Issue #8216 - changes from review Signed-off-by: Lachlan Roberts --- .../security/openid/OpenIdConfiguration.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java b/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java index e9fdf8ccf45..e98fab4724a 100644 --- a/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java +++ b/jetty-openid/src/main/java/org/eclipse/jetty/security/openid/OpenIdConfiguration.java @@ -40,6 +40,9 @@ public class OpenIdConfiguration extends ContainerLifeCycle { private static final Logger LOG = LoggerFactory.getLogger(OpenIdConfiguration.class); private static final String CONFIG_PATH = "/.well-known/openid-configuration"; + private static final String AUTHORIZATION_ENDPOINT = "authorization_endpoint"; + private static final String TOKEN_ENDPOINT = "token_endpoint"; + private static final String ISSUER = "issuer"; private final HttpClient httpClient; private final String issuer; @@ -121,20 +124,27 @@ public class OpenIdConfiguration extends ContainerLifeCycle } } + /** + * Process the OpenID Connect metadata discovered by {@link #fetchOpenIdConnectMetadata()}. + */ protected void processMetadata(Map discoveryDocument) { - authEndpoint = (String)discoveryDocument.get("authorization_endpoint"); + authEndpoint = (String)discoveryDocument.get(AUTHORIZATION_ENDPOINT); if (authEndpoint == null) - throw new IllegalArgumentException("authorization_endpoint"); + throw new IllegalArgumentException(AUTHORIZATION_ENDPOINT); - tokenEndpoint = (String)discoveryDocument.get("token_endpoint"); + tokenEndpoint = (String)discoveryDocument.get(TOKEN_ENDPOINT); if (tokenEndpoint == null) - throw new IllegalArgumentException("token_endpoint"); + throw new IllegalArgumentException(TOKEN_ENDPOINT); - if (!Objects.equals(discoveryDocument.get("issuer"), issuer)) + if (!Objects.equals(discoveryDocument.get(ISSUER), issuer)) LOG.warn("The issuer in the metadata is not correct."); } + /** + * Obtain the JSON metadata from OpenID Connect Discovery Configuration Endpoint. + * @return a set of Claims about the OpenID Provider's configuration in JSON format. + */ protected Map fetchOpenIdConnectMetadata() { String provider = issuer;