100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
In development allow consoles hosted outside of the manager web server to use authentication
Rich Turner3eb32ba2e186
diff --git a/client/src/main/webapp/src/or-app/or-app-security.html b/client/src/main/webapp/src/or-app/or-app-security.htmlindex 10ac6d828..3cadb5949 100644--- a/client/src/main/webapp/src/or-app/or-app-security.html+++ b/client/src/main/webapp/src/or-app/or-app-security.html@@ -326,8 +326,15 @@this.logout();}+ var managerHost = '';+ var hostURI = this.importPath;+ if ( hostURI ) {+ managerHost = '//' + new URL(hostURI).host;+ }+let keycloakConfig = {- url: window.location.protocol + "//" + window.location.host + "/auth",++ url: managerHost + "/auth",realm: realm,clientId: "openremote"};diff --git a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.javaindex 1f713815b..fdd063a5f 100644--- a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java+++ b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java@@ -48,6 +48,7 @@ import javax.ws.rs.client.Client;import javax.ws.rs.core.Response;import javax.ws.rs.core.UriBuilder;import java.util.ArrayList;+import java.util.Collections;import java.util.List;import java.util.concurrent.TimeUnit;import java.util.logging.Level;@@ -341,17 +342,20 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider{webService.getPrefixRoutes().put("/" + KeycloakResource.KEYCLOAK_CONTEXT_PATH, authProxyHandler);}- protected ClientRepresentation createClientApplication(String realm, String clientId, String appName, boolean enableDirectAccess) {+ protected ClientRepresentation createClientApplication(String realm, String clientId, String appName, boolean devMode) {ClientRepresentation client = new ClientRepresentation();client.setClientId(clientId);client.setName(appName);client.setPublicClient(true);- if (enableDirectAccess) {+ if (devMode) {// We need direct access for integration testsLOG.info("### Allowing direct access grants for client app '" + appName + "', this must NOT be used in production! ###");client.setDirectAccessGrantsEnabled(true);++ // Allow any web origin (this will add CORS headers to token requests etc.)+ client.setWebOrigins(Collections.singletonList("*"));}List<String> redirectUris = new ArrayList<>();diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 5598da56a..e4d984ef7 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -75,13 +75,18 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im@Overrideprotected void addClientRedirectUris(String realm, List<String> redirectUrls) {- // Callback URL used by Manager web client authentication, any relative path to "ourselves" is fine- String managerCallbackUrl = UriBuilder.fromUri("/").path(realm).path("*").build().toString();- redirectUrls.add(managerCallbackUrl);-- // Callback URL used by Console web client authentication, any relative path to "ourselves" is fine- String consoleCallbackUrl = UriBuilder.fromUri("/console/").path(realm).path("*").build().toString();- redirectUrls.add(consoleCallbackUrl);+ if (devMode) {+ // Allow any redirect URIs in dev mode+ redirectUrls.add("*");+ } else {+ // Callback URL used by Manager web client authentication, any relative path to "ourselves" is fine+ String managerCallbackUrl = UriBuilder.fromUri("/").path(realm).path("*").build().toString();+ redirectUrls.add(managerCallbackUrl);++ // Callback URL used by Console web client authentication, any relative path to "ourselves" is fine+ String consoleCallbackUrl = UriBuilder.fromUri("/console/").path(realm).path("*").build().toString();+ redirectUrls.add(consoleCallbackUrl);+ }}@Override