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
Keycloak bug fixes (Interactive Tenant CRUD not functioning although test works)
Rich Turner14681c9b3ec6
diff --git a/container/src/main/java/org/openremote/container/security/AuthForm.java b/container/src/main/java/org/openremote/container/security/AuthForm.javaindex ccf86ec24..77ba39a9c 100644--- a/container/src/main/java/org/openremote/container/security/AuthForm.java+++ b/container/src/main/java/org/openremote/container/security/AuthForm.java@@ -38,6 +38,26 @@ public class AuthForm {public AuthForm() {}+ public AuthForm setClientId(String clientId) {+ this.clientId = clientId;+ return this;+ }++ public AuthForm setUsername(String username) {+ this.username = username;+ return this;+ }++ public AuthForm setPassword(String password) {+ this.password = password;+ return this;+ }++ public AuthForm setGrantType(String grantType) {+ this.grantType = grantType;+ return this;+ }+public AuthForm(String clientId, String username, String password) {this(clientId, username, password, "password");}diff --git a/container/src/main/java/org/openremote/container/web/ProxyWebClientBuilder.java b/container/src/main/java/org/openremote/container/web/ProxyWebClientBuilder.javaindex 0ccd61f86..52361b267 100644--- a/container/src/main/java/org/openremote/container/web/ProxyWebClientBuilder.java+++ b/container/src/main/java/org/openremote/container/web/ProxyWebClientBuilder.java@@ -24,6 +24,8 @@ import org.apache.http.HttpRequestInterceptor;import org.apache.http.impl.client.HttpClientBuilder;import org.apache.http.protocol.HTTP;+import javax.ws.rs.core.HttpHeaders;+/*** This client will always set the configured Host header on all outgoing requests.* We use this to emulate a reverse proxy that "preserves" the Host header. Using adiff --git a/docker-compose.yml b/docker-compose.ymlindex 3b796df23..07c99e14a 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -38,7 +38,7 @@## Your extension JAR files should be in the deployment/manager/extensions/ directory.#-version: '2.2'+version: '2.4'# If you enable volume mappings in services, you need this. Otherwise, remove the volumesvolumes:@@ -82,7 +82,8 @@ services:file: profile/deploy.ymlservice: managerdepends_on:- - keycloak+ keycloak:+ condition: service_healthyvolumes:- deployment-data:/deploymentdiff --git a/keycloak/Dockerfile b/keycloak/Dockerfileindex d888bac24..e8153db3f 100644--- a/keycloak/Dockerfile+++ b/keycloak/Dockerfile@@ -1,129 +1,19 @@-FROM debian:stretch+FROM jboss/keycloak:7.0.0MAINTAINER [email protected]-# Install utilities-RUN apt-get update && apt-get install -y --no-install-recommends \- apt-transport-https \- gnupg2 \- software-properties-common \- procps \- ca-certificates \- curl \- wget \- && rm -rf /var/lib/apt/lists/*--# Default to UTF-8 file.encoding-ENV LANG C.UTF-8--# add a simple script that can auto-detect the appropriate JAVA_HOME value-# based on whether the JDK or only the JRE is installed-RUN { \- echo '#!/bin/sh'; \- echo 'set -e'; \- echo; \- echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \- } > /usr/local/bin/docker-java-home \- && chmod +x /usr/local/bin/docker-java-home--# do some fancy footwork to create a JAVA_HOME that's cross-architecture-safe-RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home-ENV JAVA_HOME /docker-java-home--RUN set -ex; \- \-# deal with slim variants not having man page directories (which causes "update-alternatives" to fail)- if [ ! -d /usr/share/man/man1 ]; then \- mkdir -p /usr/share/man/man1; \- fi; \- \- apt-get update; \- apt-get install -y \- openjdk-8-jdk \- ca-certificates-java\- ; \- rm -rf /var/lib/apt/lists/*; \- \-# verify that "docker-java-home" returns what we expect- [ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \- \-# update-alternatives so that future installs of other OpenJDK versions don't change /usr/bin/java- update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \-# ... and verify that it actually worked for one of the alternatives we care about- update-alternatives --query java | grep -q 'Status: manual'--# Run postinst because it might not happen on install-RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure-# Add git commit label must be specified at build time using --build-arg GIT_COMMIT=dadadadadadARG GIT_COMMIT=unknownLABEL git-commit=$GIT_COMMIT-############ EDITS ABOVE THIS LINE SHOULD BE DONE IN ALL DOCKERFILES! ################--# Install dependencies for JBoss AS-RUN apt-get update \- && apt-get install -y --no-install-recommends \- jq xmlstarlet libsaxon-java unzip bsdtar bzip2 xz-utils \- && rm -rf /var/lib/apt/lists/*--# Create a user and group used to launch processes-# The user ID 1000 is the default for the first "regular" user on Fedora/RHEL,-# so there is a high chance that this ID will be equal to the current user-# making it easier to use volumes (no permission issues)-RUN groupadd -r jboss -g 1000 && useradd -u 1000 -r -g jboss -m -d /opt/jboss -s /sbin/nologin -c "JBoss user" jboss && \- chmod 755 /opt/jboss--# Set the working directory to jboss' user home directory-WORKDIR /opt/jboss+USER rootADD docker-entrypoint.sh /opt/jboss/RUN chmod +x /opt/jboss/docker-entrypoint.sh-ENV JBOSS_HOME /opt/jboss/keycloak--# Switch to jboss user-USER jboss--ENV KEYCLOAK_VERSION 6.0.1-ENV POSTGRESQL_DRIVER_VERSION 42.2.6--# Enables signals getting passed from startup script to JVM-# ensuring clean shutdown when container is stopped.-ENV LAUNCH_JBOSS_IN_BACKGROUND 1--RUN curl -L https://downloads.jboss.org/keycloak/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.tar.gz | \- tar zx && mv /opt/jboss/keycloak-$KEYCLOAK_VERSION $JBOSS_HOME--ADD setLogLevel.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/setLogLevel.xsl--ADD changeDatabase.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/changeDatabase.xsl && \- java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml \- /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml \- /opt/jboss/keycloak/changeDatabase.xsl && \- rm /opt/jboss/keycloak/changeDatabase.xsl-RUN mkdir -p /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main && \- curl -o /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main/postgresql-jdbc.jar \- http://repo1.maven.org/maven2/org/postgresql/postgresql/${POSTGRESQL_DRIVER_VERSION}/postgresql-${POSTGRESQL_DRIVER_VERSION}.jar 2>/dev/null-ADD module.xml /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main/--ADD setProxyForwarding.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/setProxyForwarding.xsl--RUN rm /opt/jboss/keycloak/*.xslHEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD curl --fail --silent http://localhost:8080/auth || exit 1+USER 1000+EXPOSE 8080ENTRYPOINT ["/opt/jboss/docker-entrypoint.sh"]-CMD ["-b", "0.0.0.0"]+CMD ["-b", "0.0.0.0"]\ No newline at end of filediff --git a/keycloak/changeDatabase.xsl b/keycloak/changeDatabase.xsldeleted file mode 100644index a60558059..000000000--- a/keycloak/changeDatabase.xsl+++ /dev/null@@ -1,45 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>--<xsl:stylesheet version="2.0"- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"- xmlns:ds="urn:jboss:domain:datasources:5.0">-- <xsl:output method="xml" indent="yes"/>-- <xsl:template match="//ds:subsystem/ds:datasources/ds:datasource[@jndi-name='java:jboss/datasources/KeycloakDS']">- <ds:datasource jndi-name="java:jboss/datasources/KeycloakDS" enabled="true" use-java-context="true" pool-name="KeycloakDS" use-ccm="true">- <!-- Weird behavior of JBoss/Postgres: If you don't force schema 'public', it will use the last one? But- you really can't override it, a different realm doesn't work... -->- <ds:connection-url>jdbc:postgresql://postgresql:5432/${env.POSTGRES_DATABASE:keycloak}?currentSchema=public</ds:connection-url>- <ds:driver>postgresql</ds:driver>- <ds:security>- <ds:user-name>${env.POSTGRES_USER:keycloak}</ds:user-name>- <ds:password>${env.POSTGRES_PASSWORD:password}</ds:password>- </ds:security>- <ds:validation>- <ds:check-valid-connection-sql>SELECT 1</ds:check-valid-connection-sql>- <ds:background-validation>true</ds:background-validation>- <ds:background-validation-millis>60000</ds:background-validation-millis>- </ds:validation>- <ds:pool>- <ds:flush-strategy>IdleConnections</ds:flush-strategy>- </ds:pool>- </ds:datasource>- </xsl:template>-- <xsl:template match="//ds:subsystem/ds:datasources/ds:drivers">- <xsl:copy>- <xsl:apply-templates select="node()|@*"/>- <ds:driver name="postgresql" module="org.postgresql">- <ds:xa-datasource-class>org.postgresql.xa.PGXADataSource</ds:xa-datasource-class>- </ds:driver>- </xsl:copy>- </xsl:template>-- <xsl:template match="@*|node()">- <xsl:copy>- <xsl:apply-templates select="@*|node()"/>- </xsl:copy>- </xsl:template>--</xsl:stylesheet>diff --git a/keycloak/dev.Dockerfile b/keycloak/dev.Dockerfiledeleted file mode 100644index 03336e935..000000000--- a/keycloak/dev.Dockerfile+++ /dev/null@@ -1,143 +0,0 @@-FROM debian:stretch-MAINTAINER [email protected]--# Install utilities-RUN apt-get update && apt-get install -y --no-install-recommends \- apt-transport-https \- gnupg2 \- software-properties-common \- procps \- ca-certificates \- curl \- wget \- && rm -rf /var/lib/apt/lists/*--# Default to UTF-8 file.encoding-ENV LANG C.UTF-8--# add a simple script that can auto-detect the appropriate JAVA_HOME value-# based on whether the JDK or only the JRE is installed-RUN { \- echo '#!/bin/sh'; \- echo 'set -e'; \- echo; \- echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \- } > /usr/local/bin/docker-java-home \- && chmod +x /usr/local/bin/docker-java-home--# do some fancy footwork to create a JAVA_HOME that's cross-architecture-safe-RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home-ENV JAVA_HOME /docker-java-home--RUN set -ex; \- \-# deal with slim variants not having man page directories (which causes "update-alternatives" to fail)- if [ ! -d /usr/share/man/man1 ]; then \- mkdir -p /usr/share/man/man1; \- fi; \- \- apt-get update; \- apt-get install -y \- openjdk-8-jdk \- ca-certificates-java\- ; \- rm -rf /var/lib/apt/lists/*; \- \-# verify that "docker-java-home" returns what we expect- [ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \- \-# update-alternatives so that future installs of other OpenJDK versions don't change /usr/bin/java- update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \-# ... and verify that it actually worked for one of the alternatives we care about- update-alternatives --query java | grep -q 'Status: manual'--# Run postinst because it might not happen on install-RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure--# Add git commit label must be specified at build time using --build-arg GIT_COMMIT=dadadadadad-ARG GIT_COMMIT=unknown-LABEL git-commit=$GIT_COMMIT--############ EDITS ABOVE THIS LINE SHOULD BE DONE IN ALL DOCKERFILES! ################--# Install dependencies for JBoss AS-RUN apt-get update \- && apt-get install -y --no-install-recommends \- jq xmlstarlet libsaxon-java unzip bsdtar bzip2 xz-utils \- && rm -rf /var/lib/apt/lists/*--# Create a user and group used to launch processes-# The user ID 1000 is the default for the first "regular" user on Fedora/RHEL,-# so there is a high chance that this ID will be equal to the current user-# making it easier to use volumes (no permission issues)-RUN groupadd -r jboss -g 1000 && useradd -u 1000 -r -g jboss -m -d /opt/jboss -s /sbin/nologin -c "JBoss user" jboss && \- chmod 755 /opt/jboss--# Set the working directory to jboss' user home directory-WORKDIR /opt/jboss-ADD docker-entrypoint.sh /opt/jboss/-RUN chmod +x /opt/jboss/docker-entrypoint.sh-ENV JBOSS_HOME /opt/jboss/keycloak--# Switch to jboss user-USER jboss--ENV KEYCLOAK_VERSION 6.0.1-ENV POSTGRESQL_DRIVER_VERSION 42.2.4--# Enables signals getting passed from startup script to JVM-# ensuring clean shutdown when container is stopped.-ENV LAUNCH_JBOSS_IN_BACKGROUND 1--RUN curl -L https://downloads.jboss.org/keycloak/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.tar.gz | \- tar zx && mv /opt/jboss/keycloak-$KEYCLOAK_VERSION $JBOSS_HOME--ADD setLogLevel.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/setLogLevel.xsl--ADD changeDatabase.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/changeDatabase.xsl && \- java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml \- /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml \- /opt/jboss/keycloak/changeDatabase.xsl && \- rm /opt/jboss/keycloak/changeDatabase.xsl-RUN mkdir -p /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main && \- curl -o /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main/postgresql-jdbc.jar \- http://repo1.maven.org/maven2/org/postgresql/postgresql/${POSTGRESQL_DRIVER_VERSION}/postgresql-${POSTGRESQL_DRIVER_VERSION}.jar 2>/dev/null-ADD module.xml /opt/jboss/keycloak/modules/system/layers/keycloak/org/postgresql/main/--ADD setProxyForwarding.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/setProxyForwarding.xsl--RUN rm /opt/jboss/keycloak/*.xsl--HEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD curl --fail http://localhost:8080/auth || exit 1--EXPOSE 8080--ENTRYPOINT ["/opt/jboss/docker-entrypoint.sh"]-CMD ["-b", "0.0.0.0"]--ADD devModeConfig.xsl /opt/jboss/keycloak/-RUN java -jar /usr/share/java/saxon.jar \- -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/standalone/configuration/standalone.xml \- /opt/jboss/keycloak/devModeConfig.xsl--# This produces a lot of log output, only enable when you must log all HTTP traffic into Keycloak-#ADD enableRequestDumping.xsl /opt/jboss/keycloak/-#RUN java -jar /usr/share/java/saxon.jar \-# -o /opt/jboss/keycloak/standalone/configuration/standalone.xml \-# /opt/jboss/keycloak/standalone/configuration/standalone.xml \-# /opt/jboss/keycloak/enableRequestDumping.xsl-diff --git a/keycloak/devModeConfig.xsl b/keycloak/devModeConfig.xsldeleted file mode 100644index b3ebd2dce..000000000--- a/keycloak/devModeConfig.xsl+++ /dev/null@@ -1,29 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<xsl:stylesheet version="2.0"- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"- xmlns:keycloak="urn:jboss:domain:keycloak-server:1.1">-- <xsl:output method="xml" indent="yes"/>-- <xsl:template match="//keycloak:staticMaxAge/text()">-1</xsl:template>- <xsl:template match="//keycloak:cacheThemes/text()">false</xsl:template>- <xsl:template match="//keycloak:cacheTemplates/text()">false</xsl:template>--<!--- <staticMaxAge>2592000</staticMaxAge>- <cacheThemes>true</cacheThemes>- <cacheTemplates>true</cacheTemplates>- <dir>${jboss.home.dir}/themes</dir>--.theme.staticMaxAge |= -1 |-.theme.cacheTemplates |=false |-.theme.cacheThemes |= false--->-- <xsl:template match="@*|node()">- <xsl:copy>- <xsl:apply-templates select="@*|node()"/>- </xsl:copy>- </xsl:template>--</xsl:stylesheet>\ No newline at end of filediff --git a/keycloak/docker-entrypoint.sh b/keycloak/docker-entrypoint.shindex 73ac23ef8..b94684f69 100644--- a/keycloak/docker-entrypoint.sh+++ b/keycloak/docker-entrypoint.sh@@ -1,13 +1,16 @@#!/bin/bash-# Copy themes from deployment if they exist+# Symlink each theme from deployment this preserves the default keycloak theme, reasons for this mechanism:+# Cannot volume map a subdir of a named volume+# Want all customisation to be in the /deployment dir and deployment-data volumeif [ -d "/deployment/keycloak/themes" ]; then- cp -r /deployment/keycloak/themes/* /opt/jboss/keycloak/themes/+ for dir in /deployment/keycloak/themes/*; do+ if [ -d ${dir} ]; then+ echo "${dir##*/}"+ ln -s ${dir} /opt/jboss/keycloak/themes/${dir##*/}+ fi+ donefi-if [ $SETUP_ADMIN_PASSWORD ]; then- keycloak/bin/add-user-keycloak.sh --user admin --password $SETUP_ADMIN_PASSWORD-fi--exec /opt/jboss/keycloak/bin/standalone.sh $@+exec /opt/jboss/tools/docker-entrypoint.sh $@exit $?\ No newline at end of filediff --git a/keycloak/module.xml b/keycloak/module.xmldeleted file mode 100644index b7ab16bd0..000000000--- a/keycloak/module.xml+++ /dev/null@@ -1,31 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<!--- ~ JBoss, Home of Professional Open Source.- ~ Copyright 2010, Red Hat, Inc., and individual contributors- ~ as indicated by the @author tags. See the copyright.txt file in the- ~ distribution for a full listing of individual contributors.- ~- ~ This is free software; you can redistribute it and/or modify it- ~ under the terms of the GNU Lesser General Public License as- ~ published by the Free Software Foundation; either version 2.1 of- ~ the License, or (at your option) any later version.- ~- ~ This software is distributed in the hope that it will be useful,- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU- ~ Lesser General Public License for more details.- ~- ~ You should have received a copy of the GNU Lesser General Public- ~ License along with this software; if not, write to the Free- ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA- ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.- -->-<module xmlns="urn:jboss:module:1.3" name="org.postgresql">- <resources>- <resource-root path="postgresql-jdbc.jar"/>- </resources>- <dependencies>- <module name="javax.api"/>- <module name="javax.transaction.api"/>- </dependencies>-</module>\ No newline at end of filediff --git a/keycloak/setLogLevel.xsl b/keycloak/setLogLevel.xsldeleted file mode 100644index 6b7d72cbf..000000000--- a/keycloak/setLogLevel.xsl+++ /dev/null@@ -1,26 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>--<xsl:stylesheet version="2.0"- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"- xmlns:log="urn:jboss:domain:logging:3.0">-- <xsl:output method="xml" indent="yes"/>-- <xsl:template match="//log:subsystem">- <xsl:copy>- <xsl:apply-templates select="node()|@*"/>- <log:logger category="org.keycloak">- <log:level>- <xsl:attribute name="name">${env.KEYCLOAK_LOGLEVEL:INFO}</xsl:attribute>- </log:level>- </log:logger>- </xsl:copy>- </xsl:template>-- <xsl:template match="@*|node()">- <xsl:copy>- <xsl:apply-templates select="@*|node()"/>- </xsl:copy>- </xsl:template>--</xsl:stylesheet>diff --git a/keycloak/setProxyForwarding.xsl b/keycloak/setProxyForwarding.xsldeleted file mode 100644index 62e734ca7..000000000--- a/keycloak/setProxyForwarding.xsl+++ /dev/null@@ -1,21 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<xsl:stylesheet version="2.0"- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"- xmlns:undertow="urn:jboss:domain:undertow:3.0">-- <xsl:output method="xml" indent="yes"/>-- <xsl:template match="//undertow:http-listener">- <xsl:copy>- <xsl:apply-templates select="@*|node()"/>- <xsl:attribute name="proxy-address-forwarding">true</xsl:attribute>- </xsl:copy>- </xsl:template>-- <xsl:template match="@*|node()">- <xsl:copy>- <xsl:apply-templates select="@*|node()"/>- </xsl:copy>- </xsl:template>--</xsl:stylesheet>\ No newline at end of filediff --git a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.javaindex 96d7dd52d..38421c30a 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java@@ -128,23 +128,23 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen}@Override- public void updateTenant(String remoteAddress, String realm, Tenant tenant) {+ public void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant) {throw new UnsupportedOperationException("This provider does not support multiple tenants");}@Override- public void createTenant(String remoteAddress, Tenant tenant) {+ public void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant) {throw new UnsupportedOperationException("This provider does not support multiple tenants");}@Override- public void createTenant(String remoteAddress, Tenant tenant, TenantEmailConfig emailConfig) {+ public void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant, TenantEmailConfig emailConfig) {throw new UnsupportedOperationException("This provider does not support multiple tenants");}@Override- public void deleteTenant(String remoteAddress, String realm) {+ public void deleteTenant(ClientRequestInfo clientRequestInfo, String realm) {throw new UnsupportedOperationException("This provider does not support multiple tenants");}diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.javaindex b12804248..c1c664cc9 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java@@ -27,6 +27,7 @@ import org.openremote.model.event.shared.TenantFilter;import org.openremote.model.query.UserQuery;import org.openremote.model.security.*;+import java.io.IOException;import java.util.List;/**@@ -67,13 +68,13 @@ public interface ManagerIdentityProvider extends IdentityProvider {Tenant getTenant(String realm);- void updateTenant(String remoteAddress, String realm, Tenant tenant);+ void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant) throws Exception;- void createTenant(String remoteAddress, Tenant tenant);+ void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant) throws Exception;- void createTenant(String remoteAddress, Tenant tenant, TenantEmailConfig emailConfig);+ void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant, TenantEmailConfig emailConfig) throws Exception;- void deleteTenant(String remoteAddress, String realm);+ void deleteTenant(ClientRequestInfo clientRequestInfo, String realm) throws Exception;boolean isTenantActiveAndAccessible(AuthContext authContext, Tenant tenant);diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 5b779d00e..7fe5e159a 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -20,7 +20,10 @@package org.openremote.manager.security;import org.apache.camel.ExchangePattern;+import org.keycloak.TokenVerifier;import org.keycloak.admin.client.resource.*;+import org.keycloak.common.VerificationException;+import org.keycloak.representations.AccessToken;import org.keycloak.representations.idm.*;import org.openremote.container.Container;import org.openremote.container.message.MessageBrokerService;@@ -29,6 +32,7 @@ import org.openremote.container.persistence.PersistenceService;import org.openremote.container.security.AuthContext;import org.openremote.container.security.AuthForm;import org.openremote.container.security.keycloak.KeycloakIdentityProvider;+import org.openremote.container.security.keycloak.KeycloakResource;import org.openremote.container.timer.TimerService;import org.openremote.container.web.ClientRequestInfo;import org.openremote.container.web.WebService;@@ -54,6 +58,8 @@ import java.util.logging.Logger;import java.util.stream.IntStream;import static org.openremote.container.util.JsonUtil.convert;+import static org.openremote.container.web.WebClient.getTarget;+import static org.openremote.manager.setup.AbstractKeycloakSetup.*;import static org.openremote.model.Constants.*;public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider implements ManagerIdentityProvider {@@ -66,11 +72,12 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imfinal protected MessageBrokerService messageBrokerService;final protected ClientEventService clientEventService;final protected ConsoleAppService consoleAppService;- final protected String accessToken;+ final protected String keycloakAdminPassword;public ManagerKeycloakIdentityProvider(UriBuilder externalServerUri, Container container) {super(KEYCLOAK_CLIENT_ID, externalServerUri, container);+ this.keycloakAdminPassword = container.getConfig().getOrDefault(SETUP_ADMIN_PASSWORD, SETUP_ADMIN_PASSWORD_DEFAULT);this.devMode = container.isDevMode();this.timerService = container.getService(TimerService.class);this.persistenceService = container.getService(PersistenceService.class);@@ -78,10 +85,6 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imthis.clientEventService = container.getService(ClientEventService.class);this.consoleAppService = container.getService(ConsoleAppService.class);- accessToken = getKeycloak().getAccessToken(- MASTER_REALM, new AuthForm("admin-cli", MASTER_REALM_ADMIN_USER, "secret")- ).getToken();-enableAuthProxy(container.getService(WebService.class));}@@ -355,38 +358,39 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im}@Override- public void updateTenant(String remoteAddress, String realm, Tenant tenant) {+ public void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant) throws VerificationException {LOG.fine("Update tenant: " + tenant);- getRealms(new ClientRequestInfo(remoteAddress, accessToken)).realm(realm).update(++ getRealms(new ClientRequestInfo(clientRequestInfo.getRemoteAddress(), getRealmAdminToken(realm, clientRequestInfo))).realm(realm).update(convert(Container.JSON, RealmRepresentation.class, tenant));publishModification(PersistenceEvent.Cause.UPDATE, tenant);}@Override- public void createTenant(String remoteAddress, Tenant tenant) {- createTenant(remoteAddress, tenant, null);+ public void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant) throws VerificationException {+ createTenant(clientRequestInfo, tenant, null);}@Override- public void createTenant(String remoteAddress, Tenant tenant, TenantEmailConfig emailConfig) {+ public void createTenant(ClientRequestInfo clientRequestInfo, Tenant tenant, TenantEmailConfig emailConfig) throws VerificationException {LOG.fine("Create tenant: " + tenant);RealmRepresentation realmRepresentation = convert(Container.JSON, RealmRepresentation.class, tenant);configureRealm(realmRepresentation, emailConfig);-+ clientRequestInfo = new ClientRequestInfo(clientRequestInfo.getRemoteAddress(), getRealmAdminToken(tenant.getRealm(), clientRequestInfo));// TODO This is not atomic, write compensation actions- getRealms(new ClientRequestInfo(remoteAddress, accessToken)).create(realmRepresentation);- createClientApplication(new ClientRequestInfo(null, accessToken), realmRepresentation.getRealm());+ getRealms(clientRequestInfo).create(realmRepresentation);+ createClientApplication(clientRequestInfo, realmRepresentation.getRealm());publishModification(PersistenceEvent.Cause.CREATE, tenant);}@Override- public void deleteTenant(String remoteAddress, String realm) {+ public void deleteTenant(ClientRequestInfo clientRequestInfo, String realm) throws VerificationException {Tenant tenant = getTenant(realm);if (tenant != null) {LOG.fine("Delete tenant: " + realm);- getRealms(new ClientRequestInfo(remoteAddress, accessToken)).realm(realm).remove();+ getRealms(new ClientRequestInfo(clientRequestInfo.getRemoteAddress(), getRealmAdminToken(realm, clientRequestInfo))).realm(realm).remove();publishModification(PersistenceEvent.Cause.DELETE, tenant);}}@@ -486,6 +490,20 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imaddDefaultRoles(clientResource.roles());}+ /**+ * Keycloak only allows realm CRUD using the {realm}-realm client or the admin-cli client so we need to ensure we+ * have a token for one of these realms; if we are creating a realm then that means using the admin-cli+ */+ protected String getRealmAdminToken(String realm, ClientRequestInfo clientRequestInfo) throws VerificationException {+ AccessToken token = TokenVerifier.create(clientRequestInfo.getAccessToken(), AccessToken.class).getToken();+ if (!token.getIssuedFor().equals(ADMIN_CLI_CLIENT_ID)) {+ return getKeycloak().getAccessToken(+ MASTER_REALM, new AuthForm(ADMIN_CLI_CLIENT_ID, MASTER_REALM_ADMIN_USER, keycloakAdminPassword)+ ).getToken();+ }+ return clientRequestInfo.getAccessToken();+ }+protected ClientRepresentation createClientApplication(String realm, String clientId, String appName, boolean devMode) {ClientRepresentation client = new ClientRepresentation();diff --git a/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java b/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.javaindex 6c2f31ce1..626d7828c 100644--- a/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java+++ b/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java@@ -92,7 +92,7 @@ public class TenantResourceImpl extends ManagerWebResource implements TenantReso}try {identityService.getIdentityProvider().updateTenant(- getClientRemoteAddress(), realm, tenant+ new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth()), realm, tenant);} catch (ClientErrorException ex) {throw new WebApplicationException(ex.getCause(), ex.getResponse().getStatus());@@ -108,7 +108,7 @@ public class TenantResourceImpl extends ManagerWebResource implements TenantReso}try {identityService.getIdentityProvider().createTenant(- getClientRemoteAddress(), tenant+ new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth()), tenant);} catch (ClientErrorException ex) {throw new WebApplicationException(ex.getCause(), ex.getResponse().getStatus());@@ -134,7 +134,7 @@ public class TenantResourceImpl extends ManagerWebResource implements TenantReso}try {identityService.getIdentityProvider().deleteTenant(- getClientRemoteAddress(), realm+ new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth()), realm);} catch (ClientErrorException ex) {throw new WebApplicationException(ex.getCause(), ex.getResponse().getStatus());diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.javaindex 629c9bb37..56d89d86d 100644--- a/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java@@ -74,14 +74,14 @@ public class KeycloakDemoSetup extends AbstractKeycloakSetup {tenantA.setRealm("tenantA");tenantA.setDisplayName("Tenant A");tenantA.setEnabled(true);- keycloakProvider.createTenant(null, tenantA, emailConfig);+ keycloakProvider.createTenant(new ClientRequestInfo(null, accessToken), tenantA, emailConfig);tenantA = keycloakProvider.getTenant(tenantA.getRealm());tenantB = new Tenant();tenantB.setRealm("tenantB");tenantB.setDisplayName("Tenant B");tenantB.setEnabled(true);- keycloakProvider.createTenant(null, tenantB, emailConfig);+ keycloakProvider.createTenant(new ClientRequestInfo(null, accessToken), tenantB, emailConfig);tenantB = keycloakProvider.getTenant(tenantB.getRealm());// Usersdiff --git a/profile/demo-rpi.yml b/profile/demo-rpi.ymlindex c030b66c4..52576cd71 100644--- a/profile/demo-rpi.yml+++ b/profile/demo-rpi.yml@@ -3,7 +3,7 @@## TODO: Needs updating for fast JDK9 aarch32 JVM, or JDK8 aarch64 JVM#-version: '2.2'+version: '2.4'services:diff --git a/profile/deploy.yml b/profile/deploy.ymlindex 29645e327..3e8dcb3e5 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -4,7 +4,7 @@# configuration to complete it with service dependencies and volume# mappings, see docker-compose.yml for a usable complete configuration.#-version: '2.2'+version: '2.4'services:@@ -248,8 +248,12 @@ services:# Keycloak identity providerkeycloak:+ # Image will be built when not already in the cache or when `--build` option is supplied to `docker-compose up`+ build: '../keycloak'+# Image will be pulled when using the `docker-compose pull` command or `docker-compose up --no-build`- image: jboss/keycloak:7.0.0+ image: openremote/keycloak:${DATE_TAG:-latest}+ #image: jboss/keycloak:7.0.0environment:@@ -260,14 +264,11 @@ services:# Switch to DEBUG to diagnose Keycloak problems.KEYCLOAK_LOGLEVEL: INFO- # CHANGE THIS PASSWORD BEFORE STARTING THE STACK! THIS IS ONLY FOR DEMO!- SETUP_ADMIN_PASSWORD: ${SETUP_ADMIN_PASSWORD:-secret}-# When you are ready to permanently install your project, replace it with the next line ...# SETUP_ADMIN_PASSWORD: # Allow override on CLI# Configure how Keycloak connects to the database- DB_VENDOR: POSTGRES+ DB_VENDOR: postgresDB_ADDR: postgresqlDB_PORT: 5432DB_DATABASE: openremote@@ -275,7 +276,10 @@ services:DB_SCHEMA: publicDB_PASSWORD: CHANGE_ME_DB_USER_PASSWORDKEYCLOAK_USER: admin- KEYCLOAK_PASSWORD: secret+ PROXY_ADDRESS_FORWARDING: 'true'++ # CHANGE THIS PASSWORD BEFORE STARTING THE STACK! THIS IS ONLY FOR DEMO!+ KEYCLOAK_PASSWORD: ${SETUP_ADMIN_PASSWORD:-secret}# Custom JVM options (increase heap size if required)JAVA_OPTS: '-Xms300m -Xmx300m@@ -294,6 +298,8 @@ services:logging:options:max-size: 10m+ ports:+ - "8081:8080"# PostgreSQL DBMSpostgresql:diff --git a/profile/dev-map.yml b/profile/dev-map.ymlindex 737d3cf90..f69bdaac1 100644--- a/profile/dev-map.yml+++ b/profile/dev-map.yml@@ -2,7 +2,7 @@# Profile for doing development work on raster map components.## https://localhost:8082-version: '2.2'+version: '2.4'services:diff --git a/profile/dev-proxy.yml b/profile/dev-proxy.ymlindex 239b6284e..b9ba2df1a 100644--- a/profile/dev-proxy.yml+++ b/profile/dev-proxy.yml@@ -14,7 +14,7 @@# - Mount the proxy-data volume in a new container and edit proxy configuration files# - Change the proxy configuration to a directory mount and edit configuration files#-version: '2.2'+version: '2.4'#networks:# default:@@ -46,10 +46,6 @@ services:extends:file: deploy.ymlservice: keycloak- build:- context: ../keycloak- dockerfile: dev.Dockerfile- image: openremote/keycloak_dev:${DATE_TAG:-latest}# Access directly if needed on localhostports:- "8081:8080"diff --git a/profile/dev-testing.yml b/profile/dev-testing.ymlindex d475c5fa0..7fa0c17d2 100644--- a/profile/dev-testing.yml+++ b/profile/dev-testing.yml@@ -3,7 +3,7 @@## Run this in the background for full ./gradlew clean build#-version: '2.2'+version: '2.4'volumes:postgresql-data:diff --git a/profile/dev.yml b/profile/dev.ymlindex 7c29056d7..b74e534c2 100644--- a/profile/dev.yml+++ b/profile/dev.yml@@ -8,7 +8,7 @@# - Mount the proxy-data volume in a new container and edit proxy configuration files# - Change the proxy configuration to a directory mount and edit configuration files#-version: '2.2'+version: '2.4'volumes:proxy-data:diff --git a/proxy/haproxy.cfg b/proxy/haproxy.cfgindex a66687a7f..a3eff8b6a 100644--- a/proxy/haproxy.cfg+++ b/proxy/haproxy.cfg@@ -62,6 +62,7 @@ frontend httpsbind :443 ssl crt "${CERT_FILE}" no-sslv3 no-tls-tickets no-tlsv10 no-tlsv11reqadd X-Forwarded-Proto:\ https+ reqadd X-Forwarded-Port:\ 443rspadd Strict-Transport-Security:\ max-age=15768000use_backend proxy_backenddiff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovyindex 3a4085aec..ac6218889 100644--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy@@ -11,7 +11,6 @@ import org.openremote.manager.setup.builtin.KeycloakDemoSetupimport org.openremote.manager.setup.builtin.ManagerDemoSetupimport org.openremote.model.rules.AssetRulesetimport org.openremote.model.rules.GlobalRuleset-import org.openremote.model.rules.RulesetStatusimport org.openremote.model.rules.TenantRulesetimport org.openremote.test.ManagerContainerTraitimport spock.lang.Specification@@ -190,7 +189,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainerdef apartment3Engine = rulesService.assetEngines.get(managerDemoSetup.apartment3Id)def tenantATenant = keycloakDemoSetup.tenantAtenantATenant.setEnabled(false)- identityService.getIdentityProvider().updateTenant(null, tenantATenant.getRealm(), tenantATenant)+ identityService.getIdentityProvider().updateTenant(new ClientRequestInfo(null, accessToken), tenantATenant.getRealm(), tenantATenant)then: "the tenants rule engine should stop and all asset rule engines in this realm should also stop"conditions.eventually {@@ -216,7 +215,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainerwhen: "the disabled tenant is re-enabled"tenantATenant.setEnabled(true)- identityService.getIdentityProvider().updateTenant(null, tenantATenant.getRealm(), tenantATenant)+ identityService.getIdentityProvider().updateTenant(new ClientRequestInfo(null, accessToken), tenantATenant.getRealm(), tenantATenant)then: "the tenants rule engine should start and all asset rule engines from this realm should also start"conditions.eventually {