Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Support for unsecured static index.html in secured context (#17), updated Docker build

Christian Bauere99b80b4e253
diff --git a/README.md b/README.md
index ae7b84bdd..4ee03ea8b 100644
--- a/README.md
+++ b/README.md
@@ -17,11 +17,7 @@ We work with Java, Groovy, JavaScript, Gradle, Docker, and a wide range of APIs
A demo preview can be started with Docker Compose (install [Docker Toolbox](https://www.docker.com/products/docker-toolbox)):
```
-docker-compose -p openremote \
- -f profile/dependencies/postgresql.yml \
- -f profile/dependencies/keycloak.yml \
- -f profile/manager.yml \
- up
+docker-compose -p openremote -f profile/demo.yml up
```
Access the manager UI and API on http://192.168.99.100:8080/ with username `admin` and password `secret`. Configuration options of the images are documented in the compose profiles.
@@ -43,6 +39,17 @@ docker push openremote/keycloak:latest
docker push openremote/manager:latest
```
+An instance of the application in developer mode can be started with:
+
+```
+./gradlew clean prepareImage
+docker-compose -p ordev \
+ -f profile/postgresql_dev.yml \
+ -f profile/keycloak_dev.yml \
+ -f profile/manager_dev.yml \
+ up
+```
+
For more information and how to set up a development environment, see the [Developer Guide](https://github.com/openremote/openremote/wiki).
## Discuss OpenRemote
diff --git a/container/src/main/java/org/openremote/container/web/file/FileServlet.java b/container/src/main/java/org/openremote/container/web/file/FileServlet.java
index 69b1231e8..280a8464b 100644
--- a/container/src/main/java/org/openremote/container/web/file/FileServlet.java
+++ b/container/src/main/java/org/openremote/container/web/file/FileServlet.java
@@ -39,6 +39,7 @@ public class FileServlet extends AbstractFileServlet {
final protected boolean devMode;
final protected File base;
+ final protected File unsecuredIndex;
final protected String[] requiredRoles;
final protected Map<String, String> mimeTypes;
final protected Map<String, Integer> mimeTypesExpireSeconds;
@@ -47,6 +48,7 @@ public class FileServlet extends AbstractFileServlet {
public FileServlet(boolean devMode, File base, String[] requiredRoles, Map<String, String> mimeTypes, Map<String, Integer> mimeTypesExpireSeconds, String[] alreadyZippedExtensions) {
this.devMode = devMode;
this.base = base;
+ this.unsecuredIndex = new File(base, "index.html");
this.requiredRoles = requiredRoles;
this.mimeTypes = mimeTypes;
this.mimeTypesExpireSeconds = mimeTypesExpireSeconds;
@@ -60,6 +62,17 @@ public class FileServlet extends AbstractFileServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isSecured()) {
+
+ // Special case: Handle request to unsecured index.html. When a request is made
+ // to /index.html without an authentication realm header, assume the client wants
+ // an unsecured loader page (e.g. to handle authentication).
+ String realm = request.getHeader(REQUEST_HEADER_REALM);
+ if ((request.getPathInfo().equals("/") || request.getPathInfo().equals("/index.html"))
+ && (realm == null || realm.length() == 0) && unsecuredIndex.exists()) {
+ super.service(request, response);
+ return;
+ }
+
if (request.authenticate(response)) {
boolean userHasAllRoles = true;
for (String requiredRole : requiredRoles) {
@@ -84,8 +97,8 @@ public class FileServlet extends AbstractFileServlet {
@Override
protected File getFile(HttpServletRequest request) {
String relativePath = request.getPathInfo();
- if (relativePath == null || relativePath.isEmpty() || "/".equals(relativePath)) {
- throw new IllegalArgumentException();
+ if (relativePath == null || relativePath.isEmpty()) {
+ relativePath = "/index.html";
}
while (relativePath.startsWith("/"))
relativePath = relativePath.substring(1);
@@ -94,12 +107,24 @@ public class FileServlet extends AbstractFileServlet {
// If secured, serve files from a sub-directory that represents the authenticated realm
if (isSecured()) {
+
String realm = request.getHeader(REQUEST_HEADER_REALM);
+
+ // Special case: Handle request to unsecured index.html, see above
+ if ((relativePath.equals("") || relativePath.equals("index.html"))
+ && (realm == null || realm.length() == 0) && unsecuredIndex.exists()) {
+ LOG.fine("No realm in request, serving unsecured index: " + unsecuredIndex.getAbsolutePath());
+ return unsecuredIndex;
+ }
+
+ // If it's not a request for index.html and we are missing the auth realm header, ignore...
if (realm == null || realm.length() ==0) {
LOG.fine("Ignoring request, secured service needs request header: " + REQUEST_HEADER_REALM);
return null;
}
+
actualBase = new File(base, realm);
+
if (!actualBase.isDirectory()) {
LOG.fine("Ignoring request, missing realm content directory: " + actualBase.getAbsolutePath());
return null;
diff --git a/deployment/manager/resources_console/index.html b/deployment/manager/resources_console/index.html
new file mode 100644
index 000000000..30f3fe726
--- /dev/null
+++ b/deployment/manager/resources_console/index.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+<head>
+ <title>OpenRemote Console Loader</title>
+</head>
+<body>
+ <p>
+ This is a LOADER placeholder. Put your frontend application LOADER here (which, for example,
+ can perform a login with keycloak.js). This loader page is NOT secured and can always be
+ retrieved by any client.
+ </p>
+</body>
+</html>
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/ManagerCleanSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/ManagerCleanSetup.java
index 79dd80888..51ddb223b 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/ManagerCleanSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/ManagerCleanSetup.java
@@ -35,5 +35,6 @@ public class ManagerCleanSetup extends AbstractManagerSetup {
public void execute() throws Exception {
LOG.info("Dropping database schema and all data");
persistenceService.dropSchema();
+ LOG.info("### NOTE: The message 'PSQLException: ERROR: relation ... does not exist' is normal and can be ignored!");
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/web/ManagerWebService.java b/manager/server/src/main/java/org/openremote/manager/server/web/ManagerWebService.java
index 6f12d0e11..b04293330 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/web/ManagerWebService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/web/ManagerWebService.java
@@ -67,7 +67,7 @@ public class ManagerWebService extends WebService {
MANAGER_PATH, ManagerFileServlet.wrapHandler(managerFileHandler, MANAGER_PATTERN)
);
- // Serve the Console client files secured
+ // Serve the Console client files secured (note that CONSOLE_DOCROOT/index.html is the unsecured index page!)
Path consoleDocRoot = Paths.get(
getString(container.getConfig(), CONSOLE_DOCROOT, CONSOLE_DOCROOT_DEFAULT)
);
diff --git a/profile/manager.yml b/profile/demo.yml
similarity index 67%
rename from profile/manager.yml
rename to profile/demo.yml
index e046f0fa5..850932f83 100644
--- a/profile/manager.yml
+++ b/profile/demo.yml
@@ -2,6 +2,8 @@
#
# This configuration works with https://www.docker.com/products/overview#/docker_toolbox
#
+# Install Docker Toolbox and execute "docker-compose -p openremote -f profile/demo.yml up"
+#
version: '2'
services:
@@ -74,3 +76,44 @@ services:
logging:
options:
max-size: "10m"
+
+ # Keycloak identity provider
+ keycloak:
+ image: openremote/keycloak:latest
+ links:
+ - postgresql
+ environment:
+ TZ: "Europe/Zurich"
+
+ KEYCLOAK_LOGLEVEL: INFO
+
+ KEYCLOAK_USER: admin
+ # Change the admin root password if you make this application publicly accessible! Note
+ # that imported demo data uses the admin account and also creates a 'test' user with
+ # password 'test'. Importing will be broken if you change the password only here.
+ # Demo data should not be imported in production.
+ KEYCLOAK_PASSWORD: secret
+
+ # Configure how Keycloak connects to the database
+ POSTGRES_DATABASE: openremote
+ POSTGRES_USER: openremote
+ POSTGRES_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
+
+ # PostgreSQL DBMS
+ postgresql:
+ image: openremote/postgresql:latest
+ environment:
+ TZ: "Europe/Zurich"
+ # This is the DBMS superuser and password. You should change this, especially if you
+ # expose the DBMS port and make it accessible externally!
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: CHANGE_ME_DB_SUPERUSER_PASSWORD
+
+ # The database and service connection user, passwords should be changed in production!
+ POSTGRES_DB: openremote
+ OPENREMOTE_USERNAME: openremote
+ OPENREMOTE_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
+
+ # Durable data requires a volume mapping on your Docker host
+ # volumes:
+ # - /path/to/data/on/my/host/postgresql:/var/lib/postgresql/data
diff --git a/profile/dependencies/keycloak.yml b/profile/dependencies/keycloak.yml
deleted file mode 100644
index 7d6bba17b..000000000
--- a/profile/dependencies/keycloak.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Keycloak identity provider
-#
-version: '2'
-services:
-
- keycloak:
- image: openremote/keycloak:latest
- links:
- - postgresql
- environment:
- TZ: "Europe/Zurich"
-
- KEYCLOAK_LOGLEVEL: INFO
-
- KEYCLOAK_USER: admin
- # Change the admin root password if you make this application publicly accessible! Note
- # that imported demo data uses the admin account and also creates a 'test' user with
- # password 'test'. Importing will be broken if you change the password only here.
- # Demo data should not be imported in production.
- KEYCLOAK_PASSWORD: secret
-
- # Configure how Keycloak connects to the database
- POSTGRES_DATABASE: openremote
- POSTGRES_USER: openremote
- POSTGRES_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
diff --git a/profile/dependencies/postgresql.yml b/profile/dependencies/postgresql.yml
deleted file mode 100644
index ef5194493..000000000
--- a/profile/dependencies/postgresql.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# PostgreSQL DBMS
-#
-version: '2'
-services:
-
- postgresql:
- image: openremote/postgresql:latest
- environment:
- TZ: "Europe/Zurich"
- # This is the DBMS superuser and password. You should change this, especially if you
- # expose the DBMS port and make it accessible externally!
- POSTGRES_USER: postgres
- POSTGRES_PASSWORD: CHANGE_ME_DB_SUPERUSER_PASSWORD
-
- # The database and service connection user, passwords should be changed in production!
- POSTGRES_DB: openremote
- OPENREMOTE_USERNAME: openremote
- OPENREMOTE_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
-
- # Durable data requires a volume mapping on your Docker host
- # volumes:
- # - /path/to/data/on/my/host/postgresql:/var/lib/postgresql/data
diff --git a/profile/dependencies/keycloak_dev.yml b/profile/keycloak_dev.yml
similarity index 79%
rename from profile/dependencies/keycloak_dev.yml
rename to profile/keycloak_dev.yml
index ca1070104..a830a6903 100644
--- a/profile/dependencies/keycloak_dev.yml
+++ b/profile/keycloak_dev.yml
@@ -6,10 +6,10 @@ services:
keycloak_dev:
build:
- context: ../../keycloak
+ context: ../keycloak
dockerfile: Dockerfile-dev
volumes:
- - ../../keycloak/theme:/opt/jboss/keycloak/themes/openremote
+ - ../keycloak/theme:/opt/jboss/keycloak/themes/openremote
environment:
TZ: "Europe/Zurich"
KEYCLOAK_USER: admin
diff --git a/profile/manager_dev.yml b/profile/manager_dev.yml
new file mode 100644
index 000000000..81eb6ad07
--- /dev/null
+++ b/profile/manager_dev.yml
@@ -0,0 +1,18 @@
+#
+# Manager (development)
+#
+# Note: You must run ./gradlew prepareImage before you start this profile!
+#
+version: '2'
+services:
+
+ manager_dev:
+ build:
+ context: ../manager/build/install
+ ports:
+ - "8080:8080"
+ environment:
+ TZ: "Europe/Zurich"
+ DEV_MODE: 'true'
+ IDENTITY_NETWORK_HOST: '192.168.99.100'
+ IDENTITY_NETWORK_WEBSERVER_PORT: 8080
diff --git a/profile/dependencies/postgresql_dev.yml b/profile/postgresql_dev.yml
similarity index 89%
rename from profile/dependencies/postgresql_dev.yml
rename to profile/postgresql_dev.yml
index b1fb321e9..26da32a47 100644
--- a/profile/dependencies/postgresql_dev.yml
+++ b/profile/postgresql_dev.yml
@@ -6,7 +6,7 @@ services:
postgresql_dev:
build:
- context: ../../postgresql
+ context: ../postgresql
environment:
TZ: "Europe/Zurich"
# This is the database superuser