adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062367026


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = 
LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values 
before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*
+     * Creates an OpenIDWellKnown class that reads the json from an OIDC
+     * well-known endpoint and saves these values for later use. Use Guice
+     * to ensure environment exists before initializing.
+     */
+    public OpenIDWellKnown() {
+    }
+
+    @Inject
+    public void init() {
+        // Call to well-known endpoint might fail, so allow several tries 
before giving up
+        ScheduledExecutorService scheduler = 
Executors.newSingleThreadScheduledExecutor();
+        
+        Runnable task = new Runnable() {
+            int attempts = 0;
+
+            @Override
+            public void run() {
+                attempts++;
+
+                try {
+                    Map<String,Object> json = JsonUrlReader.fetch("GET", 
getWellKnownEndpoint().toURL(), "");

Review Comment:
   At the moment JsonUrlReader will be called 24 times failing each time and 
eventually stop. Yes I could have a fast return from init() if the well-known 
endpoint is missing
   
   The missing well-known endpoint just means the getters of confWellKnown will 
always return null, which is what we want in confService 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to