Skip to content

armgit / core

Public Imported from GitHub
0

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

WebService route overhaul and deployment folder restructure:

Rich Turner4861eb980394
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
index 808262c8b..3c43d66e8 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
@@ -57,7 +57,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
-import static org.openremote.container.web.WebService.JSAPI_PATH;
+import static org.openremote.container.web.WebService.pathStartsWithHandler;
import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
/**
@@ -115,7 +115,7 @@ public abstract class AbstractHttpServerProtocol extends AbstractProtocol {
*/
public static final Pattern PATH_REGEX = Pattern.compile("^[\\w/_]+$", Pattern.CASE_INSENSITIVE);
-
+ public static final String JSAPI_PATH = "/jsapi";
public static final String DEFAULT_ALLOWED_METHODS = "OPTIONS, GET, POST, DELETE, PUT, PATCH";
public static final String DEFAULT_DEPLOYMENT_NAME_FORMAT = "HttpServer %1$s Deployment %2$d";
private static final Logger LOG = Logger.getLogger(AbstractHttpServerProtocol.class.getName());
@@ -126,7 +126,7 @@ public abstract class AbstractHttpServerProtocol extends AbstractProtocol {
protected static AlreadyGzippedWriterInterceptor alreadtGzippedWriterInterceptor;
protected static ClientErrorExceptionHandler clientErrorExceptionHandler;
protected static WebServiceExceptions.ServletUndertowExceptionHandler undertowExceptionHandler;
- protected static final Map<AttributeRef, List<Pair<DeploymentInfo, HttpHandler>>> deployments = new HashMap<>();
+ protected static final Map<AttributeRef, List<Pair<DeploymentInfo, WebService.RequestHandler>>> deployments = new HashMap<>();
protected int deploymentCounter = 0;
protected Container container;
protected boolean devMode;
@@ -382,23 +382,24 @@ public abstract class AbstractHttpServerProtocol extends AbstractProtocol {
try {
httpHandler = manager.start();
+ WebService.RequestHandler requestHandler = pathStartsWithHandler(deploymentInfo.getDeploymentName(), deploymentInfo.getContextPath(), httpHandler);
+ List<Pair<DeploymentInfo, WebService.RequestHandler>> deploymentList = deployments.getOrDefault(protocolConfiguration.getReferenceOrThrow(), new ArrayList<>());
- List<Pair<DeploymentInfo, HttpHandler>> deploymentList = deployments.getOrDefault(protocolConfiguration.getReferenceOrThrow(), new ArrayList<>());
- deploymentList.add(new Pair<>(deploymentInfo, httpHandler));
+ deploymentList.add(new Pair<>(deploymentInfo, requestHandler));
deployments.put(protocolConfiguration.getReferenceOrThrow(), deploymentList);
LOG.info("Registering HTTP Server Protocol request handler '"
+ this.getClass().getSimpleName()
+ "' for request path: "
+ deploymentInfo.getContextPath());
- webService.getRequestPathHandler().addPrefixPath(deploymentInfo.getContextPath(), httpHandler);
+ webService.getRequestHandlers().add(requestHandler);
} catch (ServletException e) {
LOG.severe("Failed to deploy deployment: " + deploymentInfo.getDeploymentName());
}
}
protected void undeploy(AssetAttribute protocolConfiguration) {
- for (Pair<DeploymentInfo, HttpHandler> deploymentInfoHttpHandlerPair : deployments.get(protocolConfiguration.getReferenceOrThrow())) {
+ for (Pair<DeploymentInfo, WebService.RequestHandler> deploymentInfoHttpHandlerPair : deployments.get(protocolConfiguration.getReferenceOrThrow())) {
if (deploymentInfoHttpHandlerPair == null) {
LOG.info("Deployment doesn't exist for protocol configuration: " + protocolConfiguration);
return;
@@ -411,7 +412,7 @@ public abstract class AbstractHttpServerProtocol extends AbstractProtocol {
+ this.getClass().getSimpleName()
+ "' for request path: "
+ deploymentInfo.getContextPath());
- webService.getRequestPathHandler().removePrefixPath(deploymentInfo.getContextPath());
+ webService.getRequestHandlers().remove(deploymentInfoHttpHandlerPair.value);
DeploymentManager manager = Servlets.defaultContainer().getDeployment(deploymentInfo.getDeploymentName());
manager.stop();
manager.undeploy();
diff --git a/client/src/main/webapp/index.html b/client/src/main/webapp/index.html
index 69543949f..fb07c3da5 100644
--- a/client/src/main/webapp/index.html
+++ b/client/src/main/webapp/index.html
@@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="icon" type="image/png" href="/static/img/favicon.png"/>
- <script src="/static/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="/static/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="/static/src/or-app/or-app.html">
<link rel="import" href="/static/src/manager/or-manager-console-apps/or-manager-console-apps-view.html">
@@ -22,7 +22,7 @@
app.load.css("/static/3rdparty/mapbox-gl-js/0.42.2/mapbox-gl.css"),
app.load.js("/static/3rdparty/mapbox-gl-js/0.42.2/mapbox-gl.js"),
- app.load.js("/static/bower_components/chart.js/dist/Chart.js"),
+ app.load.js("/static/node_modules/chart.js/dist/Chart.js"),
app.load.js("/static/3rdparty/sprintf/1.0.3/sprintf.min.js")
]).then(() => {
diff --git a/client/src/main/webapp/js/auth.js b/client/src/main/webapp/js/auth.js
index d1aa2c75b..d15cbc81b 100644
--- a/client/src/main/webapp/js/auth.js
+++ b/client/src/main/webapp/js/auth.js
@@ -40,9 +40,9 @@ window.startKeycloakAuthentication = function (realm, successCallback, failureCa
window.startBasicAuthentication = function (realm, successCallback, failureCallback, errorCallback) {
Promise.all([
- load.js("/static/bower_components/webcomponentsjs/webcomponents-lite.min.js"),
- load.import("/static/bower_components/iron-flex-layout/iron-flex-layout-classes.html"),
- load.css("/static/bower_components/font-awesome/css/font-awesome.css"),
+ load.js("/static/node_modules/webcomponentsjs/webcomponents-lite.min.js"),
+ load.import("/static/node_modules/@polymer/iron-flex-layout/iron-flex-layout-classes.html"),
+ load.css("/static/node_modules/font-awesome/css/font-awesome.css"),
load.import("/static/css/style.html"),
load.import("/static/css/theme.html")
diff --git a/client/src/main/webapp/package.json b/client/src/main/webapp/package.json
index f641e5820..5fcb13dfc 100644
--- a/client/src/main/webapp/package.json
+++ b/client/src/main/webapp/package.json
@@ -2,26 +2,29 @@
"name": "manager",
"version": "3.0.0",
"homepage": "http://openremote.com/",
- "authors": [
- "OpenRemote Inc. <[email protected]>"
- ],
+ "author": "OpenRemote",
"description": "OR Manager",
"main": "index.html",
- "license": "APGLv3",
+ "license": "AGPL-3.0-or-later",
"ignore": [
"**/.*",
- "node_modules",
- "bower_components",
"test",
"tests"
],
"dependencies": {
- "polymer": "Polymer/polymer#^2.5.0",
- "iron-flex-layout": "^2.0.3",
- "app-localize-behavior": "PolymerElements/app-localize-behavior#^2.0.1",
- "app-route": "PolymerElements/app-route#^2.0.3",
- "moment": "moment#^2.20.1",
- "intl": "intl#^1.2.5",
+ "@polymer/polymer": "^2.6.1",
+ "@webcomponents/webcomponentsjs": "^1.1.0",
+ "@polymer/iron-flex-layout": "^1.3.1-pre.3",
+ "@polymer/app-localize-behavior": "^0.10.1-pre.3",
+ "@polymer/app-route": "^0.9.3-pre.3",
+ "@webcomponents/shadycss": "^1.1.1",
+ "font-awesome": "^4.7.0",
+ "moment": "^2.20.1",
+ "intl": "^1.2.5",
"chart.js": "^2.7.0"
+ },
+ "resolutions": {
+ "@polymer/polymer": "^2.6.1",
+ "@polymer/promise-polyfill": "^1.0.1-pre.3"
}
}
\ No newline at end of file
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.html
index e079efff8..8277863e2 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
@@ -183,15 +183,15 @@
ready() {
super.ready();
- // If login is required, and we don't have a realm, get it from the URL path
if (this.login && !this.realm) {
- if (!window.location.pathname || window.location.pathname.length <= 1) {
- this.set("error", "No tenant realm configured and URL doesn't have any path elements");
- return;
- }
- let realm = window.location.pathname.split('/')[1];
- console.log("No tenant realm configured, using first URL path segment: " + realm);
- this.set("realm", realm);
+ // TODO: Need a realm picker but for now hardcode to master
+ // if (!window.location.pathname || window.location.pathname.length <= 1) {
+ // this.set("error", "No tenant realm configured and URL doesn't have any path elements");
+ // return;
+ // }
+ // let realm = window.location.pathname.split('/')[1];
+ // console.log("No tenant realm configured, using first URL path segment: " + realm);
+ this.set("realm", "master");
}
}
diff --git a/client/src/main/webapp/src/or-app/or-app.html b/client/src/main/webapp/src/or-app/or-app.html
index cb1495cda..918792df1 100644
--- a/client/src/main/webapp/src/or-app/or-app.html
+++ b/client/src/main/webapp/src/or-app/or-app.html
@@ -2,7 +2,7 @@
<link rel="import" href="or-style.html">
<!-- App services/dependencies -->
-<link rel="import" href="../../bower_components/iron-location/iron-query-params.html">
+<link rel="import" href="../../node_modules/@polymer/iron-location/iron-query-params.html">
<link rel="import" href="or-busy-indicator.html">
<link rel="import" href="or-error-view.html">
<link rel="import" href="or-console.html">
@@ -437,7 +437,7 @@
}
);
- requests.configure(this.hostConfiguration.protocol + "//" + this.hostConfiguration.host + "/" + this.tenantRealm);
+ requests.configure(this.hostConfiguration.protocol + "//" + this.hostConfiguration.host + "/api/" + this.tenantRealm);
this.set("requests", requests);
this.$.console.set("reguests", requests);
diff --git a/client/src/main/webapp/src/or-app/or-component.html b/client/src/main/webapp/src/or-app/or-component.html
index 2cced393a..14d31c805 100644
--- a/client/src/main/webapp/src/or-app/or-component.html
+++ b/client/src/main/webapp/src/or-app/or-component.html
@@ -2,19 +2,19 @@
<script src="/static/3rdparty/sprintf/1.0.3/sprintf.min.js"></script>
<!-- Moment.js because we need a proper time/date API -->
-<script src="/static/bower_components/moment/moment.js"></script>
+<script src="/static/node_modules/moment/moment.js"></script>
<!-- URL/page routing -->
-<link rel="import" href="/static/bower_components/app-route/app-location.html">
+<link rel="import" href="/static/node_modules/@polymer/app-route/app-location.html">
<!-- Intl polyfill -->
-<script src="/static/bower_components/intl/dist/Intl.js"></script>
+<script src="/static/node_modules/intl/dist/Intl.js"></script>
<!-- Intl langage TODO How can we do this dynamically? -->
-<script src="/static/bower_components/intl/locale-data/jsonp/en.js"></script>
+<script src="/static/node_modules/intl/locale-data/jsonp/en.js"></script>
<!-- Provides Polymer.AppLocalizeBehavior -->
-<link rel="import" href="/static/bower_components/app-localize-behavior/app-localize-behavior.html">
+<link rel="import" href="/static/node_modules/@polymer/app-localize-behavior/app-localize-behavior.html">
<dom-module id="or-component">
<script>
diff --git a/client/src/main/webapp/src/or-app/or-style.html b/client/src/main/webapp/src/or-app/or-style.html
index 4e2e1ac94..66d68cde8 100644
--- a/client/src/main/webapp/src/or-app/or-style.html
+++ b/client/src/main/webapp/src/or-app/or-style.html
@@ -1,7 +1,7 @@
<link rel="import" href="or-theme.html">
<link rel="import" href="or-icons.html">
-<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
+<link rel="import" href="../../node_modules/@polymer/iron-flex-layout/iron-flex-layout-classes.html">
<dom-module id="or-style">
<template>
diff --git a/client/src/main/webapp/yarn.lock b/client/src/main/webapp/yarn.lock
new file mode 100644
index 000000000..71849ce8d
--- /dev/null
+++ b/client/src/main/webapp/yarn.lock
@@ -0,0 +1,124 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"@polymer/app-localize-behavior@^0.10.1-pre.3":
+ version "0.10.1-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/app-localize-behavior/-/app-localize-behavior-0.10.1-pre.3.tgz#9856ccbf9cee66631c6f4a869d146089b14f55f8"
+ integrity sha1-mFbMv5zuZmMcb0qGnRRgibFPVfg=
+ dependencies:
+ "@polymer/iron-ajax" preview
+ "@polymer/polymer" preview
+ intl-messageformat "^1.0.0"
+
+"@polymer/app-route@^0.9.3-pre.3":
+ version "0.9.3-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/app-route/-/app-route-0.9.3-pre.3.tgz#42ec32497d30e15592ecbbb3604d40e244caef15"
+ integrity sha1-QuwySX0w4VWS7LuzYE1A4kTK7xU=
+ dependencies:
+ "@polymer/iron-location" preview
+ "@polymer/polymer" preview
+
+"@polymer/iron-ajax@preview":
+ version "1.4.3-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/iron-ajax/-/iron-ajax-1.4.3-pre.3.tgz#a3b31b5622ca85be6d73bb60b8902bdc1c85b08c"
+ integrity sha1-o7MbViLKhb5tc7tguJAr3ByFsIw=
+ dependencies:
+ "@polymer/polymer" preview
+ "@polymer/promise-polyfill" gloo
+
+"@polymer/iron-flex-layout@^1.3.1-pre.3":
+ version "1.3.1-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/iron-flex-layout/-/iron-flex-layout-1.3.1-pre.3.tgz#4545f11ff2f3817098ec128c7d62779864b3c1bc"
+ integrity sha1-RUXxH/LzgXCY7BKMfWJ3mGSzwbw=
+ dependencies:
+ "@polymer/polymer" preview
+
+"@polymer/iron-location@preview":
+ version "0.8.11-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/iron-location/-/iron-location-0.8.11-pre.3.tgz#9ab735812eb4505f9efa19b8374e71446a153a1d"
+ integrity sha1-mrc1gS60UF+e+hm4N05xRGoVOh0=
+ dependencies:
+ "@polymer/polymer" preview
+
+"@polymer/polymer@^2.6.1", "@polymer/polymer@preview":
+ version "2.6.1"
+ resolved "https://registry.yarnpkg.com/@polymer/polymer/-/polymer-2.6.1.tgz#d233d0676cd634057a673fd8c2e62100d3b5a4e6"
+ integrity sha512-XBzaKlSZ094i8zfkOgczn08Gk4TWPLtGh3leANGIKLuzboid4totBt2RkBgHjRl8DgY6Up3+Jm+3lHz6W8QA+g==
+
+"@polymer/promise-polyfill@^1.0.1-pre.3", "@polymer/promise-polyfill@gloo":
+ version "1.0.1-pre.3"
+ resolved "https://registry.yarnpkg.com/@polymer/promise-polyfill/-/promise-polyfill-1.0.1-pre.3.tgz#3f534df183648c78c48f93d678a7db37be7e81fb"
+ integrity sha1-P1NN8YNkjHjEj5PWeKfbN75+gfs=
+ dependencies:
+ "@polymer/polymer" preview
+
+"@webcomponents/shadycss@^1.1.1":
+ version "1.6.0"
+ resolved "https://registry.yarnpkg.com/@webcomponents/shadycss/-/shadycss-1.6.0.tgz#2aeb0703983137a733bdb5c06fff125aa1f8c5c1"
+ integrity sha512-iURGZZU6BaiRJtGgjMn208QxPkY11QwT/VmuHNa4Yb+kJxU/WODe4C8b0LDOtnk4KJzJg50hCfwvPRAjePEzbA==
+
+"@webcomponents/webcomponentsjs@^1.1.0":
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/@webcomponents/webcomponentsjs/-/webcomponentsjs-1.3.0.tgz#57983165d8651e742bdd14c2718f8cc6c228496e"
+ integrity sha512-x7x4rfXfX+xlg0Cdy752IVC8SjjOuMfjSNi1Vy7GKfWCm/MKSc42wGubngPl6/nO7w+nHM/MvfhTD/aEngA7/w==
+
+chart.js@^2.7.0:
+ version "2.7.3"
+ resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-2.7.3.tgz#cdb61618830bf216dc887e2f7b1b3c228b73c57e"
+ integrity sha512-3+7k/DbR92m6BsMUYP6M0dMsMVZpMnwkUyNSAbqolHKsbIzH2Q4LWVEHHYq7v0fmEV8whXE0DrjANulw9j2K5g==
+ dependencies:
+ chartjs-color "^2.1.0"
+ moment "^2.10.2"
+
+chartjs-color-string@^0.5.0:
+ version "0.5.0"
+ resolved "https://registry.yarnpkg.com/chartjs-color-string/-/chartjs-color-string-0.5.0.tgz#8d3752d8581d86687c35bfe2cb80ac5213ceb8c1"
+ integrity sha512-amWNvCOXlOUYxZVDSa0YOab5K/lmEhbFNKI55PWc4mlv28BDzA7zaoQTGxSBgJMHIW+hGX8YUrvw/FH4LyhwSQ==
+ dependencies:
+ color-name "^1.0.0"
+
+chartjs-color@^2.1.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/chartjs-color/-/chartjs-color-2.2.0.tgz#84a2fb755787ed85c39dd6dd8c7b1d88429baeae"
+ integrity sha1-hKL7dVeH7YXDndbdjHsdiEKbrq4=
+ dependencies:
+ chartjs-color-string "^0.5.0"
+ color-convert "^0.5.3"
+
+color-convert@^0.5.3:
+ version "0.5.3"
+ resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-0.5.3.tgz#bdb6c69ce660fadffe0b0007cc447e1b9f7282bd"
+ integrity sha1-vbbGnOZg+t/+CwAHzER+G59ygr0=
+
+color-name@^1.0.0:
+ version "1.1.4"
+ resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
+ integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
+
+font-awesome@^4.7.0:
+ version "4.7.0"
+ resolved "https://registry.yarnpkg.com/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133"
+ integrity sha1-j6jPBBGhoxr9B7BtKQK7n8gVoTM=
+
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/intl-messageformat-parser/-/intl-messageformat-parser-1.2.0.tgz#5906b7f953ab7470e0dc8549097b648b991892ff"
+ integrity sha1-WQa3+VOrdHDg3IVJCXtki5kYkv8=
+
+intl-messageformat@^1.0.0:
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-1.3.0.tgz#f7d926aded7a3ab19b2dc601efd54e99a4bd4eae"
+ integrity sha1-99kmre16OrGbLcYB79VOmaS9Tq4=
+ dependencies:
+ intl-messageformat-parser "1.2.0"
+
+intl@^1.2.5:
+ version "1.2.5"
+ resolved "https://registry.yarnpkg.com/intl/-/intl-1.2.5.tgz#82244a2190c4e419f8371f5aa34daa3420e2abde"
+ integrity sha1-giRKIZDE5Bn4Nx9ao02qNCDiq94=
+
+moment@^2.10.2, moment@^2.20.1:
+ version "2.22.2"
+ resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
+ integrity sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y=
diff --git a/container/src/main/java/org/openremote/container/security/AuthOverloadHandler.java b/container/src/main/java/org/openremote/container/security/AuthOverloadHandler.java
index a08761e17..10aa99204 100644
--- a/container/src/main/java/org/openremote/container/security/AuthOverloadHandler.java
+++ b/container/src/main/java/org/openremote/container/security/AuthOverloadHandler.java
@@ -26,12 +26,12 @@ import io.undertow.util.HttpString;
import java.util.Deque;
import static javax.ws.rs.core.HttpHeaders.AUTHORIZATION;
-import static org.openremote.container.web.WebService.REQUEST_HEADER_REALM;
+import static org.openremote.model.Constants.REQUEST_HEADER_REALM;
/**
* If a client can't set Authorization header (e.g. Javascript websocket API), use a request
* parameter. This handler grabs the parameter and sets it as a regular header. This handler
- * will also grab {@link org.openremote.container.web.WebService#REQUEST_HEADER_REALM} as
+ * will also grab {@link org.openremote.model.Constants#REQUEST_HEADER_REALM} as
* a request parameter and set it as a regular header.
*/
public class AuthOverloadHandler implements HttpHandler {
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.java
index fcac98492..e909ab326 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
@@ -63,6 +63,8 @@ import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL;
import static org.openremote.container.util.MapAccess.getInteger;
import static org.openremote.container.util.MapAccess.getString;
import static org.openremote.container.web.WebClient.getTarget;
+import static org.openremote.container.web.WebService.pathStartsWithHandler;
+import static org.openremote.model.Constants.REQUEST_HEADER_REALM;
public abstract class KeycloakIdentityProvider implements IdentityProvider {
@@ -164,7 +166,7 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {
keycloakConfigResolver = request -> {
// The realm we authenticate against must be available as a request header
- String realm = request.getHeader(WebService.REQUEST_HEADER_REALM);
+ String realm = request.getHeader(REQUEST_HEADER_REALM);
if (realm == null || realm.length() == 0) {
LOG.fine("No realm in request, no authentication will be attempted: " + request.getURI());
return notAuthenticatedKeycloakDeployment;
@@ -365,8 +367,12 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {
protected void enableAuthProxy(WebService webService) {
if (authProxyHandler == null)
throw new IllegalStateException("Initialize this service first");
+
LOG.info("Enabling auth reverse proxy (passing requests through to Keycloak) on web context: /" + KeycloakResource.KEYCLOAK_CONTEXT_PATH);
- webService.getPrefixRoutes().put("/" + KeycloakResource.KEYCLOAK_CONTEXT_PATH, authProxyHandler);
+ webService.getRequestHandlers().add(0, pathStartsWithHandler(
+ "Keycloak auth proxy",
+ "/" + KeycloakResource.KEYCLOAK_CONTEXT_PATH,
+ authProxyHandler));
}
protected ClientRepresentation createClientApplication(String realm, String clientId, String appName, boolean devMode) {
diff --git a/container/src/main/java/org/openremote/container/web/DefaultWebsocketComponent.java b/container/src/main/java/org/openremote/container/web/DefaultWebsocketComponent.java
index 80ccc6e83..8551fdebd 100644
--- a/container/src/main/java/org/openremote/container/web/DefaultWebsocketComponent.java
+++ b/container/src/main/java/org/openremote/container/web/DefaultWebsocketComponent.java
@@ -51,6 +51,7 @@ import java.util.logging.Logger;
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static org.openremote.container.web.WebService.pathStartsWithHandler;
public class DefaultWebsocketComponent extends WebsocketComponent {
@@ -64,6 +65,7 @@ public class DefaultWebsocketComponent extends WebsocketComponent {
final protected WebService webService;
final protected String allowedOrigin;
protected DeploymentInfo deploymentInfo;
+ protected WebService.RequestHandler websocketHttpHandler;
public DefaultWebsocketComponent(IdentityService identityService, WebService webService, String allowedOrigin) {
this.identityService = identityService;
@@ -137,8 +139,9 @@ public class DefaultWebsocketComponent extends WebsocketComponent {
boolean directBuffers = Boolean.getBoolean("io.undertow.websockets.direct-buffers");
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(directBuffers, 1024, 100, 12));
+ String deploymentName = "WebSocket Deployment";
deploymentInfo = new DeploymentInfo()
- .setDeploymentName("WebSocket Deployment")
+ .setDeploymentName(deploymentName)
.setContextPath(MessageBrokerSetupService.WEBSOCKET_PATH)
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSocketDeploymentInfo)
.setClassLoader(WebsocketComponent.class.getClassLoader());
@@ -152,8 +155,10 @@ public class DefaultWebsocketComponent extends WebsocketComponent {
deploymentInfo.addSecurityConstraints(constraint);
HttpHandler handler = webService.addServletDeployment(identityService, deploymentInfo, true);
+ websocketHttpHandler = pathStartsWithHandler(deploymentName, MessageBrokerSetupService.WEBSOCKET_PATH, handler);
- webService.getPrefixRoutes().put(MessageBrokerSetupService.WEBSOCKET_PATH, handler);
+ // Give web socket handler higher priority than any other handlers already added
+ webService.getRequestHandlers().add(0, websocketHttpHandler);
}
@Override
@@ -162,7 +167,8 @@ public class DefaultWebsocketComponent extends WebsocketComponent {
webService.removeServletDeployment(deploymentInfo);
deploymentInfo = null;
}
- webService.getPrefixRoutes().remove(MessageBrokerSetupService.WEBSOCKET_PATH);
+ webService.getRequestHandlers().remove(websocketHttpHandler);
+ websocketHttpHandler = null;
}
/* TODO: Security - fix/use this! */
diff --git a/container/src/main/java/org/openremote/container/web/WebResource.java b/container/src/main/java/org/openremote/container/web/WebResource.java
index 1f8e0f7c0..b6186994c 100644
--- a/container/src/main/java/org/openremote/container/web/WebResource.java
+++ b/container/src/main/java/org/openremote/container/web/WebResource.java
@@ -33,6 +33,7 @@ import java.security.Principal;
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static org.openremote.model.Constants.REQUEST_HEADER_REALM;
public class WebResource implements AuthContext {
@@ -67,7 +68,7 @@ public class WebResource implements AuthContext {
}
public String getRequestRealm() {
- return request.getHeader(WebService.REQUEST_HEADER_REALM);
+ return request.getHeader(REQUEST_HEADER_REALM);
}
public boolean isAuthenticated() {
diff --git a/container/src/main/java/org/openremote/container/web/WebService.java b/container/src/main/java/org/openremote/container/web/WebService.java
index 00472502d..77311ed1c 100644
--- a/container/src/main/java/org/openremote/container/web/WebService.java
+++ b/container/src/main/java/org/openremote/container/web/WebService.java
@@ -21,49 +21,62 @@ package org.openremote.container.web;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
-import io.undertow.server.handlers.PathHandler;
-import io.undertow.server.handlers.RedirectHandler;
+import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.RequestDumpingHandler;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
-import io.undertow.servlet.api.ServletInfo;
-import io.undertow.util.HttpString;
import org.jboss.resteasy.plugins.interceptors.CorsFilter;
-import org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher;
-import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.json.JacksonConfig;
import org.openremote.container.json.ModelValueMessageBodyConverter;
-import org.openremote.container.security.CORSFilter;
import org.openremote.container.security.IdentityService;
-import org.openremote.container.web.jsapi.JSAPIServlet;
import org.xnio.Options;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.UriBuilder;
import java.net.Inet4Address;
import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.Predicate;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.stream.Collectors;
-import static javax.ws.rs.core.Response.Status.NOT_FOUND;
-import static javax.ws.rs.core.UriBuilder.fromUri;
import static org.openremote.container.util.MapAccess.*;
public abstract class WebService implements ContainerService {
- private static final Logger LOG = Logger.getLogger(WebService.class.getName());
+ public static class RequestHandler {
+ protected String name;
+ protected Predicate<HttpServerExchange> handlePredicate;
+ protected HttpHandler handler;
+
+ public RequestHandler(String name, Predicate<HttpServerExchange> handlePredicate, HttpHandler handler) {
+ this.name = name;
+ this.handlePredicate = handlePredicate;
+ this.handler = handler;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Predicate<HttpServerExchange> getHandlePredicate() {
+ return handlePredicate;
+ }
+
+ public io.undertow.server.HttpHandler getHandler() {
+ return handler;
+ }
+ }
// Change this to 0.0.0.0 to bind on all interfaces, enabling
// access of the manager service from other devices in your LAN
public static final String WEBSERVER_LISTEN_HOST = "WEBSERVER_LISTEN_HOST";
public static final String WEBSERVER_LISTEN_HOST_DEFAULT = "127.0.0.1";
-
public static final String WEBSERVER_LISTEN_PORT = "WEBSERVER_LISTEN_PORT";
public static final int WEBSERVER_LISTEN_PORT_DEFAULT = 8080;
public static final String WEBSERVER_DUMP_REQUESTS = "WEBSERVER_DUMP_REQUESTS";
@@ -72,56 +85,47 @@ public abstract class WebService implements ContainerService {
public static final int WEBSERVER_IO_THREADS_MAX_DEFAULT = Math.max(Runtime.getRuntime().availableProcessors(), 2);
public static final String WEBSERVER_WORKER_THREADS_MAX = "WEBSERVER_WORKER_THREADS_MAX";
public static final int WEBSERVER_WORKER_THREADS_MAX_DEFAULT = Math.max(Runtime.getRuntime().availableProcessors(), 10);
-
- // Authenticating requests requires a realm, either we receive this in a header or
- // we extract it (e.g. from request path segment) and set it as a header before
- // processing the request
- public static final String REQUEST_HEADER_REALM = "Auth-Realm";
-
- public static final String API_PATH = "/api";
- public static final String JSAPI_PATH = "/jsapi";
- protected static final Pattern PATTERN_REALM_ROOT = Pattern.compile("/([a-zA-Z0-9\\-_]+)/?");
- protected static final Pattern PATTERN_REALM_SUB = Pattern.compile("/([a-zA-Z0-9\\-_]+)/(.*)");
-
- protected PathHandler requestPathHandler;
+ private static final Logger LOG = Logger.getLogger(WebService.class.getName());
protected boolean devMode;
protected String host;
protected int port;
protected Undertow undertow;
- protected Map<String, HttpHandler> prefixRoutes = new LinkedHashMap<>();
- protected Collection<Class<?>> apiClasses = new HashSet<>();
- protected Collection<Object> apiSingletons = new HashSet<>();
+ protected List<RequestHandler> httpHandlers = new ArrayList<>();
protected URI containerHostUri;
protected static String getLocalIpAddress() throws Exception {
return Inet4Address.getLocalHost().getHostAddress();
}
+ public static RequestHandler pathStartsWithHandler(String name, String path, HttpHandler handler) {
+ return new RequestHandler(name, exchange -> exchange.getRequestPath().startsWith(path), handler);
+ }
+
@Override
public void init(Container container) throws Exception {
devMode = container.isDevMode();
host = getString(container.getConfig(), WEBSERVER_LISTEN_HOST, WEBSERVER_LISTEN_HOST_DEFAULT);
port = getInteger(container.getConfig(), WEBSERVER_LISTEN_PORT, WEBSERVER_LISTEN_PORT_DEFAULT);
String containerHost = host.equalsIgnoreCase("localhost") || host.indexOf("127") == 0 || host.indexOf("0.0.0.0") == 0
- ? getLocalIpAddress()
- : host;
+ ? getLocalIpAddress()
+ : host;
containerHostUri =
- UriBuilder.fromPath("/")
- .scheme("http")
- .host(containerHost)
- .port(port).build();
+ UriBuilder.fromPath("/")
+ .scheme("http")
+ .host(containerHost)
+ .port(port).build();
undertow = build(
- container,
- Undertow.builder()
- .addHttpListener(port, host)
- .setIoThreads(getInteger(container.getConfig(), WEBSERVER_IO_THREADS_MAX, WEBSERVER_IO_THREADS_MAX_DEFAULT))
- .setWorkerThreads(getInteger(container.getConfig(), WEBSERVER_WORKER_THREADS_MAX, WEBSERVER_WORKER_THREADS_MAX_DEFAULT))
- .setWorkerOption(Options.WORKER_NAME, "WebService")
- .setWorkerOption(Options.THREAD_DAEMON, true)
+ container,
+ Undertow.builder()
+ .addHttpListener(port, host)
+ .setIoThreads(getInteger(container.getConfig(), WEBSERVER_IO_THREADS_MAX, WEBSERVER_IO_THREADS_MAX_DEFAULT))
+ .setWorkerThreads(getInteger(container.getConfig(), WEBSERVER_WORKER_THREADS_MAX, WEBSERVER_WORKER_THREADS_MAX_DEFAULT))
+ .setWorkerOption(Options.WORKER_NAME, "WebService")
+ .setWorkerOption(Options.THREAD_DAEMON, true)
).build();
}
@@ -141,152 +145,6 @@ public abstract class WebService implements ContainerService {
}
}
- public PathHandler getRequestPathHandler() {
- return requestPathHandler;
- }
-
- protected Undertow.Builder build(Container container, Undertow.Builder builder) {
-
- LOG.info("Building web routing with custom routes: " + getPrefixRoutes().keySet());
-
- IdentityService identityService = container.hasService(IdentityService.class)
- ? container.getService(IdentityService.class)
- : null;
-
- ResteasyDeployment resteasyDeployment = createResteasyDeployment(container);
-
- HttpHandler apiHandler = createApiHandler(identityService, resteasyDeployment);
- HttpHandler jsApiHandler = createJsApiHandler(identityService, resteasyDeployment);
- requestPathHandler = new PathHandler(apiHandler);
-
- HttpHandler handler = exchange -> {
- String requestPath = exchange.getRequestPath();
- LOG.fine("Handling request: " + exchange.getRequestMethod() + " " + exchange.getRequestPath());
-
- // Other services can register routes here with a prefix patch match
- boolean handled = false;
- for (Map.Entry<String, HttpHandler> entry : getPrefixRoutes().entrySet()) {
- if (requestPath.startsWith(entry.getKey())) {
- LOG.fine("Handling with '" + entry.getValue().getClass().getName() + "' path prefix: " + entry.getKey());
- entry.getValue().handleRequest(exchange);
- handled = true;
- break;
- }
- }
- if (handled)
- return;
-
- // Redirect / to default realm
- if (requestPath.equals("/")) {
- LOG.fine("Handling root request, redirecting client to default realm: " + requestPath);
- new RedirectHandler(
- fromUri(exchange.getRequestURL()).replacePath(getDefaultRealm()).build().toString()
- ).handleRequest(exchange);
- return;
- }
-
- // Serve JavaScript API with path /jsapi/*
- if (jsApiHandler != null && requestPath.startsWith(JSAPI_PATH)) {
- LOG.fine("Serving JS API call: " + requestPath);
- jsApiHandler.handleRequest(exchange);
- return;
- }
-
- // Serve /<realm>/index.html
- Matcher realmRootMatcher = PATTERN_REALM_ROOT.matcher(requestPath);
- if (getRealmIndexHandler() != null && realmRootMatcher.matches()) {
- LOG.fine("Serving index document of realm: " + requestPath);
- exchange.setRelativePath("/index.html");
- getRealmIndexHandler().handleRequest(exchange);
- return;
- }
-
- Matcher realmSubMatcher = PATTERN_REALM_SUB.matcher(requestPath);
-
- if (!realmSubMatcher.matches()) {
- exchange.setStatusCode(NOT_FOUND.getStatusCode());
- throw new WebApplicationException(NOT_FOUND);
- }
-
- // Extract realm from path and push it into REQUEST_HEADER_REALM header
- String realm = realmSubMatcher.group(1);
-
- // Move the realm from path segment to header
- exchange.getRequestHeaders().put(HttpString.tryFromString(REQUEST_HEADER_REALM), realm);
-
- // Rewrite path, remove realm segment
- URI url = fromUri(exchange.getRequestURL())
- .replacePath(realmSubMatcher.group(2))
- .build();
- exchange.setRequestURI(url.toString(), true);
- exchange.setRequestPath(url.getPath());
- exchange.setRelativePath(url.getPath());
-
- // Look for registered path handlers and fallback to API handler
- LOG.fine("Serving HTTP call: " + url.getPath());
- requestPathHandler.handleRequest(exchange);
- };
-
- handler = new WebServiceExceptions.RootUndertowExceptionHandler(devMode, handler);
-
- if (getBoolean(container.getConfig(), WEBSERVER_DUMP_REQUESTS, WEBSERVER_DUMP_REQUESTS_DEFAULT)) {
- handler = new RequestDumpingHandler(handler);
- }
-
- builder.setHandler(handler);
-
- return builder;
- }
-
- protected HttpHandler createApiHandler(IdentityService identityService, ResteasyDeployment resteasyDeployment) {
- if (resteasyDeployment == null)
- return null;
-
- ServletInfo restServlet = Servlets.servlet("RESTEasy Servlet", HttpServlet30Dispatcher.class)
- .setAsyncSupported(true)
- .setLoadOnStartup(1)
- .addMapping("/*");
-
- DeploymentInfo deploymentInfo = new DeploymentInfo()
- .setDeploymentName("RESTEasy Deployment")
- .setContextPath(API_PATH)
- .addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment)
- .addServlet(restServlet)
- .setClassLoader(Container.class.getClassLoader());
-
- if (identityService != null) {
- resteasyDeployment.setSecurityEnabled(true);
- } else {
- throw new RuntimeException("No identity service deployed, can't enable API security");
- }
-
- return addServletDeployment(identityService, deploymentInfo, resteasyDeployment.isSecurityEnabled());
- }
-
- protected HttpHandler createJsApiHandler(IdentityService identityService, ResteasyDeployment resteasyDeployment) {
- if (resteasyDeployment == null)
- return null;
-
- ServletInfo jsApiServlet = Servlets.servlet("RESTEasy JS Servlet", JSAPIServlet.class)
- .setAsyncSupported(true)
- .setLoadOnStartup(1)
- .addMapping("/*");
-
- DeploymentInfo deploymentInfo = new DeploymentInfo()
- .setDeploymentName("RESTEasy JS Deployment")
- .setContextPath(JSAPI_PATH)
- .addServlet(jsApiServlet)
- .setClassLoader(Container.class.getClassLoader());
-
- deploymentInfo.addServletContextAttribute(
- ResteasyContextParameters.RESTEASY_DEPLOYMENTS,
- new HashMap<String, ResteasyDeployment>() {{
- put("", resteasyDeployment);
- }}
- );
- return addServletDeployment(identityService, deploymentInfo, false);
- }
-
/**
* Adds a deployment to the default servlet container and returns the started handler.
*
@@ -299,7 +157,7 @@ public abstract class WebService implements ContainerService {
if (secure) {
if (identityService == null)
throw new IllegalStateException(
- "No identity service found, make sure " + IdentityService.class.getName() + " is added before this service"
+ "No identity service found, make sure " + IdentityService.class.getName() + " is added before this service"
);
identityService.secureDeployment(deploymentInfo);
} else {
@@ -328,10 +186,61 @@ public abstract class WebService implements ContainerService {
}
}
- protected ResteasyDeployment createResteasyDeployment(Container container) {
- if (getApiClasses() == null && getApiSingletons() == null)
+ /**
+ * When a request comes in the handlers are called in order until a handler returns a non null value; when this
+ * happens the returned {@link RequestHandler} is invoked.
+ */
+ public List<RequestHandler> getRequestHandlers() {
+ return this.httpHandlers;
+ }
+
+ /**
+ * Provides the LAN IPv4 address the container is bound to so it can be
+ * used in the context provider callbacks; if CB is on the other side of some sort
+ * of NAT then this won't work also assumes HTTP
+ */
+ public URI getHostUri() {
+ return containerHostUri;
+ }
+
+ protected Undertow.Builder build(Container container, Undertow.Builder builder) {
+
+ LOG.info("Building web routing with handler(s): " + getRequestHandlers().stream().map(h -> h.name).collect(Collectors.joining("\n")));
+
+ HttpHandler handler = exchange -> {
+ String requestPath = exchange.getRequestPath();
+ LOG.fine("Handling request: " + exchange.getRequestMethod() + " " + exchange.getRequestPath());
+
+ boolean handled = false;
+ for (RequestHandler requestHandler : getRequestHandlers()) {
+ if (requestHandler.handlePredicate.test(exchange)) {
+ LOG.fine("Handling '" + requestPath + "' with handler: " + requestHandler.name);
+ requestHandler.handler.handleRequest(exchange);
+ handled = true;
+ break;
+ }
+ }
+
+ if (!handled) {
+ LOG.warning("No handler found for request: " + exchange.getRequestPath());
+ }
+ };
+
+ handler = new WebServiceExceptions.RootUndertowExceptionHandler(devMode, handler);
+
+ if (getBoolean(container.getConfig(), WEBSERVER_DUMP_REQUESTS, WEBSERVER_DUMP_REQUESTS_DEFAULT)) {
+ handler = new RequestDumpingHandler(handler);
+ }
+
+ builder.setHandler(handler);
+
+ return builder;
+ }
+
+ protected ResteasyDeployment createResteasyDeployment(Container container, Collection<Class<?>> apiClasses, Collection<Object> apiSingletons, boolean secure) {
+ if (apiClasses == null && apiSingletons == null)
return null;
- WebApplication webApplication = new WebApplication(container, getApiClasses(), getApiSingletons());
+ WebApplication webApplication = new WebApplication(container, apiClasses, apiSingletons);
ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
resteasyDeployment.setApplication(webApplication);
@@ -357,47 +266,8 @@ public abstract class WebService implements ContainerService {
resteasyDeployment.getActualProviderClasses().add(AlreadyGzippedWriterInterceptor.class);
resteasyDeployment.getActualProviderClasses().add(ClientErrorExceptionHandler.class);
- return resteasyDeployment;
- }
-
- /**
- * Add handlers with a path prefix.
- */
- public Map<String, HttpHandler> getPrefixRoutes() {
- return prefixRoutes;
- }
-
- /**
- * Add resource/provider/etc. classes to enable REST API
- */
- public Collection<Class<?>> getApiClasses() {
- return apiClasses;
- }
-
- /**
- * Add resource/provider/etc. singletons to enable REST API.
- */
- public Collection<Object> getApiSingletons() {
- return apiSingletons;
- }
+ resteasyDeployment.setSecurityEnabled(secure);
- /**
- * Provides the LAN IPv4 address the container is bound to so it can be
- * used in the context provider callbacks; if CB is on the other side of some sort
- * of NAT then this won't work also assumes HTTP
- */
- public URI getHostUri() {
- return containerHostUri;
+ return resteasyDeployment;
}
-
- /**
- * Default realm path the browser will be redirected to when a / root request is made.
- */
- abstract protected String getDefaultRealm();
-
- /**
- * @return Optional handler that can handle the request to /<realm>/index.html
- */
- abstract protected HttpHandler getRealmIndexHandler();
-
}
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 2ddbe1c1d..67863b6b6 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
@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
-import static org.openremote.container.web.WebService.REQUEST_HEADER_REALM;
+import static org.openremote.model.Constants.REQUEST_HEADER_REALM;
public class FileServlet extends AbstractFileServlet {
diff --git a/deployment/manager/consoles/customerA/.bowerrc b/deployment/manager/app/customerA/.bowerrc
similarity index 100%
rename from deployment/manager/consoles/customerA/.bowerrc
rename to deployment/manager/app/customerA/.bowerrc
diff --git a/deployment/manager/consoles/customerA/build.gradle b/deployment/manager/app/customerA/build.gradle
similarity index 100%
rename from deployment/manager/consoles/customerA/build.gradle
rename to deployment/manager/app/customerA/build.gradle
diff --git a/deployment/manager/consoles/customerA/index.html b/deployment/manager/app/customerA/index.html
similarity index 93%
rename from deployment/manager/consoles/customerA/index.html
rename to deployment/manager/app/customerA/index.html
index b688d9d4f..8adb2e53d 100644
--- a/deployment/manager/consoles/customerA/index.html
+++ b/deployment/manager/app/customerA/index.html
@@ -13,7 +13,7 @@
<meta name="or-language" content="en">
<!-- ############## Required: Load WebComponents polyfill and components ############### -->
- <script src="/static/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="/static/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<!-- Load the SmartHome app -->
<link rel="import" href="/console/customerA/smart-home/smart-home-app.html">
diff --git a/deployment/manager/consoles/customerA/package.json b/deployment/manager/app/customerA/package.json
similarity index 100%
rename from deployment/manager/consoles/customerA/package.json
rename to deployment/manager/app/customerA/package.json
diff --git a/deployment/manager/consoles/customerA/smart-home/img/co2.png b/deployment/manager/app/customerA/smart-home/img/co2.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/co2.png
rename to deployment/manager/app/customerA/smart-home/img/co2.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/eye.png b/deployment/manager/app/customerA/smart-home/img/eye.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/eye.png
rename to deployment/manager/app/customerA/smart-home/img/eye.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/eye_large.png b/deployment/manager/app/customerA/smart-home/img/eye_large.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/eye_large.png
rename to deployment/manager/app/customerA/smart-home/img/eye_large.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/eye_large_active.png b/deployment/manager/app/customerA/smart-home/img/eye_large_active.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/eye_large_active.png
rename to deployment/manager/app/customerA/smart-home/img/eye_large_active.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/home_large_energy.png b/deployment/manager/app/customerA/smart-home/img/home_large_energy.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/home_large_energy.png
rename to deployment/manager/app/customerA/smart-home/img/home_large_energy.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/home_on.png b/deployment/manager/app/customerA/smart-home/img/home_on.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/home_on.png
rename to deployment/manager/app/customerA/smart-home/img/home_on.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/humidity.png b/deployment/manager/app/customerA/smart-home/img/humidity.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/humidity.png
rename to deployment/manager/app/customerA/smart-home/img/humidity.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/star.png b/deployment/manager/app/customerA/smart-home/img/star.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/star.png
rename to deployment/manager/app/customerA/smart-home/img/star.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/temperature.png b/deployment/manager/app/customerA/smart-home/img/temperature.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/temperature.png
rename to deployment/manager/app/customerA/smart-home/img/temperature.png
diff --git a/deployment/manager/consoles/customerA/smart-home/img/ventilation.png b/deployment/manager/app/customerA/smart-home/img/ventilation.png
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/img/ventilation.png
rename to deployment/manager/app/customerA/smart-home/img/ventilation.png
diff --git a/deployment/manager/consoles/customerA/smart-home/locales.json b/deployment/manager/app/customerA/smart-home/locales.json
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/locales.json
rename to deployment/manager/app/customerA/smart-home/locales.json
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-app.html b/deployment/manager/app/customerA/smart-home/smart-home-app.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-app.html
rename to deployment/manager/app/customerA/smart-home/smart-home-app.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-body.html b/deployment/manager/app/customerA/smart-home/smart-home-body.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-body.html
rename to deployment/manager/app/customerA/smart-home/smart-home-body.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-climate.html b/deployment/manager/app/customerA/smart-home/smart-home-climate.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-climate.html
rename to deployment/manager/app/customerA/smart-home/smart-home-climate.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-component.html b/deployment/manager/app/customerA/smart-home/smart-home-component.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-component.html
rename to deployment/manager/app/customerA/smart-home/smart-home-component.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-energy.html b/deployment/manager/app/customerA/smart-home/smart-home-energy.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-energy.html
rename to deployment/manager/app/customerA/smart-home/smart-home-energy.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-header.html b/deployment/manager/app/customerA/smart-home/smart-home-header.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-header.html
rename to deployment/manager/app/customerA/smart-home/smart-home-header.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-scenes.html b/deployment/manager/app/customerA/smart-home/smart-home-scenes.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-scenes.html
rename to deployment/manager/app/customerA/smart-home/smart-home-scenes.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-section.html b/deployment/manager/app/customerA/smart-home/smart-home-section.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-section.html
rename to deployment/manager/app/customerA/smart-home/smart-home-section.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-security.html b/deployment/manager/app/customerA/smart-home/smart-home-security.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-security.html
rename to deployment/manager/app/customerA/smart-home/smart-home-security.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-settings.html b/deployment/manager/app/customerA/smart-home/smart-home-settings.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-settings.html
rename to deployment/manager/app/customerA/smart-home/smart-home-settings.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-smart.html b/deployment/manager/app/customerA/smart-home/smart-home-smart.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-smart.html
rename to deployment/manager/app/customerA/smart-home/smart-home-smart.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-style.html b/deployment/manager/app/customerA/smart-home/smart-home-style.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-style.html
rename to deployment/manager/app/customerA/smart-home/smart-home-style.html
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-temperature-select.html b/deployment/manager/app/customerA/smart-home/smart-home-temperature-select.html
similarity index 100%
rename from deployment/manager/consoles/customerA/smart-home/smart-home-temperature-select.html
rename to deployment/manager/app/customerA/smart-home/smart-home-temperature-select.html
diff --git a/deployment/manager/consoles/master/examples.html b/deployment/manager/app/master/examples.html
similarity index 98%
rename from deployment/manager/consoles/master/examples.html
rename to deployment/manager/app/master/examples.html
index 3b4f21f1d..26bf121f7 100644
--- a/deployment/manager/consoles/master/examples.html
+++ b/deployment/manager/app/master/examples.html
@@ -6,7 +6,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- ############## Required: Load WebComponents polyfill and components ############### -->
- <script src="/static/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="/static/node_modules/@webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="/static/src/or-app/or-app.html">
<link rel="import" href="/static/src/or-asset-list/or-asset-list.html">
diff --git a/deployment/manager/consoles/master/index.html b/deployment/manager/app/master/index.html
similarity index 100%
rename from deployment/manager/consoles/master/index.html
rename to deployment/manager/app/master/index.html
diff --git a/keycloak/theme/account/template.ftl b/keycloak/theme/account/template.ftl
index 994b75754..a951dd488 100644
--- a/keycloak/theme/account/template.ftl
+++ b/keycloak/theme/account/template.ftl
@@ -16,7 +16,7 @@
<link rel="icon" type="image/png" href="/static/img/favicon.png"/>
- <script src="/static/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="/static/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="/static/src/or-app/or-app.html">
diff --git a/keycloak/theme/login/template.ftl b/keycloak/theme/login/template.ftl
index b4420d7d1..ca7d8d3f8 100755
--- a/keycloak/theme/login/template.ftl
+++ b/keycloak/theme/login/template.ftl
@@ -16,7 +16,7 @@
<link rel="icon" type="image/png" href="/static/img/favicon.png"/>
- <script src="/static/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="/static/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="/static/src/or-app/or-app.html">
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index dd39fe800..1473cab93 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -35,6 +35,7 @@ import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.asset.AssetUpdateProcessor;
import org.openremote.manager.event.ClientEventService;
import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
@@ -115,7 +116,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
? ((TenantFilter) subscription.getFilter())
: null, ClientRole.READ_ASSETS));
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new AgentResourceImpl(
container.getService(TimerService.class),
container.getService(ManagerIdentityService.class),
diff --git a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
index 9ffe9ad6f..744793933 100644
--- a/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
+++ b/manager/src/main/java/org/openremote/manager/apps/ConsoleAppService.java
@@ -22,7 +22,6 @@ package org.openremote.manager.apps;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.timer.TimerService;
-import org.openremote.container.web.WebService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.apps.ConsoleApp;
@@ -50,7 +49,7 @@ public class ConsoleAppService implements ContainerService {
this.managerWebService = container.getService(ManagerWebService.class);
this.identityService = container.getService(ManagerIdentityService.class);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new ConsoleAppResourceImpl(this)
);
}
@@ -65,11 +64,11 @@ public class ConsoleAppService implements ContainerService {
public ConsoleApp[] getInstalled() throws Exception {
List<ConsoleApp> result = new ArrayList<>();
- Files.list(managerWebService.getConsolesDocRoot()).forEach(path -> {
- String directoryName = path.getFileName().toString();
+ Files.list(managerWebService.getAppDocRoot()).filter(Files::isDirectory).forEach(dir -> {
+ String directoryName = dir.getFileName().toString();
Tenant tenant = identityService.getIdentityProvider().getTenantForRealm(directoryName);
if (tenant == null) {
- LOG.fine("No tenant exists for installed console app: " + path.toAbsolutePath());
+ LOG.fine("No tenant exists for installed console app: " + dir.toAbsolutePath());
return;
}
if (tenant.isActive(timerService.getCurrentTimeMillis()) && tenant.getDisplayName() != null) {
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index d02eb6074..325fb6dd8 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -41,6 +41,7 @@ import org.openremote.container.web.WebService;
import org.openremote.manager.asset.console.ConsoleResourceImpl;
import org.openremote.manager.event.ClientEventService;
import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.Constants;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.*;
@@ -124,7 +125,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
ClientRole.READ_ASSETS)
);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new AssetResourceImpl(
container.getService(TimerService.class),
identityService,
@@ -133,7 +134,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
)
);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new ConsoleResourceImpl(container.getService(TimerService.class),
identityService,
this)
diff --git a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
index 3d0a6a431..523e73182 100644
--- a/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
+++ b/manager/src/main/java/org/openremote/manager/datapoint/AssetDatapointService.java
@@ -12,6 +12,7 @@ import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.asset.AssetUpdateProcessor;
import org.openremote.manager.concurrent.ManagerExecutorService;
import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetMeta;
@@ -71,7 +72,7 @@ public class AssetDatapointService implements ContainerService, AssetUpdateProce
timerService = container.getService(TimerService.class);
managerExecutorService = container.getService(ManagerExecutorService.class);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new AssetDatapointResourceImpl(
container.getService(TimerService.class),
container.getService(ManagerIdentityService.class),
diff --git a/manager/src/main/java/org/openremote/manager/map/MapService.java b/manager/src/main/java/org/openremote/manager/map/MapService.java
index 036a2aceb..674e19f2b 100644
--- a/manager/src/main/java/org/openremote/manager/map/MapService.java
+++ b/manager/src/main/java/org/openremote/manager/map/MapService.java
@@ -21,7 +21,6 @@ package org.openremote.manager.map;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
-import org.openremote.container.web.WebService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.value.ArrayValue;
@@ -41,6 +40,7 @@ import java.util.Map;
import java.util.logging.Logger;
import static org.openremote.container.util.MapAccess.getString;
+import static org.openremote.manager.web.ManagerWebService.API_PATH;
public class MapService implements ContainerService {
@@ -73,7 +73,7 @@ public class MapService implements ContainerService {
);
}
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new MapResourceImpl(this, container.getService(ManagerIdentityService.class))
);
}
@@ -119,14 +119,14 @@ public class MapService implements ContainerService {
);
String spriteUri =
baseUriBuilder.clone()
- .replacePath(ManagerWebService.MANAGER_PATH)
+ .replacePath(ManagerWebService.STATIC_PATH)
.path(spritePath)
.build().toString();
style.put("sprite", spriteUri);
}
String glyphsUri = baseUriBuilder.clone()
- .replacePath(ManagerWebService.MANAGER_PATH)
+ .replacePath(ManagerWebService.STATIC_PATH)
.path("/fonts/")
.build().toString() + "{fontstack}/{range}.pbf";
style.put("glyphs", glyphsUri);
@@ -140,7 +140,7 @@ public class MapService implements ContainerService {
vectorTiles.put("type", "vector");
ArrayValue tilesArray = Values.createArray();
- String tileUrl = baseUriBuilder.clone().replacePath(realm).path("map/tile").build().toString() + "/{z}/{x}/{y}";
+ String tileUrl = baseUriBuilder.clone().replacePath(API_PATH).path(realm).path("map/tile").build().toString() + "/{z}/{x}/{y}";
tilesArray.set(0, tileUrl);
vectorTiles.put("tiles", tilesArray);
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
index 0a7d788d3..6796c443a 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
@@ -33,6 +33,7 @@ import org.openremote.container.timer.TimerService;
import org.openremote.container.web.WebService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.Constants;
import org.openremote.model.asset.Asset;
import org.openremote.model.notification.Notification;
@@ -130,7 +131,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
handler.init(container);
}
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new NotificationResourceImpl(this,
container.getService(MessageBrokerService.class),
container.getService(AssetStorageService.class),
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
index 73e736113..47730b9e8 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
@@ -26,6 +26,7 @@ import org.openremote.container.timer.TimerService;
import org.openremote.container.web.WebService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.security.ManagerIdentityService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.rules.AssetRuleset;
import org.openremote.model.rules.GlobalRuleset;
import org.openremote.model.rules.Ruleset;
@@ -43,7 +44,7 @@ public class RulesetStorageService implements ContainerService {
persistenceService = container.getService(PersistenceService.class);
identityService = container.getService(ManagerIdentityService.class);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new RulesResourceImpl(
container.getService(TimerService.class),
container.getService(ManagerIdentityService.class),
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityService.java b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityService.java
index a11748393..a53fd9b6b 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityService.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityService.java
@@ -24,6 +24,7 @@ import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.security.IdentityService;
import org.openremote.container.timer.TimerService;
import org.openremote.container.web.WebService;
+import org.openremote.manager.web.ManagerWebService;
import javax.persistence.EntityManager;
import java.util.Locale;
@@ -41,10 +42,10 @@ public class ManagerIdentityService extends IdentityService {
super.init(container);
persistenceService = container.getService(PersistenceService.class);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new TenantResourceImpl(container.getService(TimerService.class), this)
);
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new UserResourceImpl(container.getService(TimerService.class), this)
);
diff --git a/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java b/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java
index e678934ec..7c91303d2 100644
--- a/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java
+++ b/manager/src/main/java/org/openremote/manager/syslog/SyslogService.java
@@ -25,6 +25,7 @@ import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.web.WebService;
import org.openremote.manager.concurrent.ManagerExecutorService;
import org.openremote.manager.event.ClientEventService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.syslog.SyslogConfig;
import org.openremote.model.syslog.SyslogCategory;
import org.openremote.model.syslog.SyslogEvent;
@@ -76,8 +77,8 @@ public class SyslogService extends Handler implements ContainerService {
});
}
- if (container.hasService(WebService.class)) {
- container.getService(WebService.class).getApiSingletons().add(
+ if (container.hasService(ManagerWebService.class)) {
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new SyslogResourceImpl(this)
);
}
diff --git a/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java b/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java
index e86276ac7..accc5a34b 100644
--- a/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java
+++ b/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java
@@ -22,6 +22,7 @@ package org.openremote.manager.system;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.web.WebService;
+import org.openremote.manager.web.ManagerWebService;
import org.openremote.model.system.HealthStatusProvider;
import org.openremote.model.system.StatusResource;
@@ -47,7 +48,7 @@ public class HealthStatusService implements ContainerService {
}
}
- container.getService(WebService.class).getApiSingletons().add(
+ container.getService(ManagerWebService.class).getApiSingletons().add(
new StatusResourceImpl(healthStatusProviderList)
);
}
diff --git a/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java b/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java
index 27f75807f..34704f1af 100644
--- a/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java
+++ b/manager/src/main/java/org/openremote/manager/web/ManagerWebService.java
@@ -20,135 +20,293 @@
package org.openremote.manager.web;
import io.undertow.server.HttpHandler;
+import io.undertow.server.handlers.PathHandler;
+import io.undertow.server.handlers.RedirectHandler;
+import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
-import io.undertow.util.Headers;
-import io.undertow.util.StatusCodes;
+import io.undertow.servlet.api.ServletInfo;
+import io.undertow.util.HttpString;
+import org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher;
+import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
+import org.jboss.resteasy.spi.ResteasyDeployment;
import org.openremote.container.Container;
import org.openremote.container.security.IdentityService;
import org.openremote.container.web.WebService;
-import org.openremote.model.Constants;
+import org.openremote.container.web.jsapi.JSAPIServlet;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static io.undertow.util.RedirectBuilder.redirect;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static javax.ws.rs.core.UriBuilder.fromUri;
import static org.openremote.container.util.MapAccess.getBoolean;
import static org.openremote.container.util.MapAccess.getString;
+import static org.openremote.model.Constants.REQUEST_HEADER_REALM;
public class ManagerWebService extends WebService {
- public static final String MANAGER_DOCROOT = "MANAGER_DOCROOT";
- public static final String MANAGER_DOCROOT_DEFAULT = "client/src/main/webapp";
- public static final String CONSOLES_DOCROOT = "CONSOLES_DOCROOT";
- public static final String CONSOLES_DOCROOT_DEFAULT = "deployment/manager/consoles";
public static final String UI_DOCROOT = "UI_DOCROOT";
public static final String UI_DOCROOT_DEFAULT = "deployment/manager/ui";
+ public static final String APP_DOCROOT = "APP_DOCROOT";
+ public static final String APP_DOCROOT_DEFAULT = "deployment/manager/app";
public static final String CONSOLE_USE_STATIC_BOWER_COMPONENTS = "CONSOLE_USE_STATIC_BOWER_COMPONENTS";
public static final boolean CONSOLE_USE_STATIC_BOWER_COMPONENTS_DEFAULT = true;
-
- public static final String MANAGER_PATH = "/static";
+ public static final String APP_DEFAULT = "APP_DEFAULT";
+ public static final String APP_DEFAULT_DEFAULT = "manager";
+ public static final String API_PATH = "/api";
+ public static final String JSAPI_PATH = "/jsapi";
+ public static final String STATIC_PATH = "/static";
public static final String CONSOLE_PATH = "/console";
public static final String UI_PATH = "/ui";
- public static final Pattern MANAGER_PATTERN = Pattern.compile(Pattern.quote(MANAGER_PATH) + "(/.*)?");
- public static final Pattern CONSOLE_PATTERN = Pattern.compile(Pattern.quote(CONSOLE_PATH) + "(/.*)?");
- public static final Pattern UI_PATTERN = Pattern.compile(Pattern.quote(UI_PATH) + "(/.*)?");
+ public static final String APP_PATH = "/app";
+ private static final Logger LOG = Logger.getLogger(ManagerWebService.class.getName());
+ protected static final Pattern PATTERN_REALM_SUB = Pattern.compile("/([a-zA-Z0-9\\-_]+)/(.*)");
- protected Path managerDocRoot;
- protected Path consolesDocRoot;
+ protected Path appDocRoot;
protected Path uiDocRoot;
- protected HttpHandler managerFileHandler;
+ protected Collection<Class<?>> apiClasses = new HashSet<>();
+ protected Collection<Object> apiSingletons = new HashSet<>();
@Override
public void init(Container container) throws Exception {
boolean devMode = container.isDevMode();
IdentityService identityService = container.getService(IdentityService.class);
+ String defaultApp = getString(container.getConfig(), APP_DEFAULT, APP_DEFAULT_DEFAULT);
- // Serve the Manager client files unsecured
- managerDocRoot = Paths.get(getString(container.getConfig(), MANAGER_DOCROOT, MANAGER_DOCROOT_DEFAULT));
- managerFileHandler = addDeployment(devMode, identityService, managerDocRoot, MANAGER_PATH);
- addRoute(managerFileHandler, MANAGER_PATH, MANAGER_PATTERN);
+ ResteasyDeployment resteasyDeployment = createResteasyDeployment(container, getApiClasses(), getApiSingletons(), true);
+ // TODO: Remove this once all apps updated to new structure
+ // Serve REST API
+ HttpHandler apiHandler = createApiHandler(identityService, resteasyDeployment);
+ // Serve JavaScript API
+ HttpHandler jsApiHandler = createJsApiHandler(identityService, resteasyDeployment);
- // Serve the Console client files unsecured
- consolesDocRoot = Paths.get(getString(container.getConfig(), CONSOLES_DOCROOT, CONSOLES_DOCROOT_DEFAULT));
- HttpHandler consoleHandler = addDeployment(devMode, identityService, consolesDocRoot, CONSOLE_PATH);
+ if (apiHandler != null) {
- final boolean useStaticBowerComponents =
- getBoolean(container.getConfig(), CONSOLE_USE_STATIC_BOWER_COMPONENTS, CONSOLE_USE_STATIC_BOWER_COMPONENTS_DEFAULT);
- // Special case for Console client files: When certain files are requested, serve them from the /static/*
- // resources already deployed in Manager. In other words: Console apps then can not have their own Polymer etc.
- // resources but use same libraries as the platform.
- String[] consoleStaticResources = {
- "/bower_components/polymer/polymer.html",
- "/bower_components/polymer/polymer-element.html",
- "/bower_components/iron-flex-layout/iron-flex-layout.html",
- "/bower_components/iron-flex-layout/iron-flex-layout-classes.html",
- "/bower_components/chart.js/dist/Chart.js",
- // TODO Add all the other stuff but Intl is many files, no idea how we deal with this... good approach?
- };
- addRoute(exchange -> {
- if (useStaticBowerComponents) {
- for (String consoleStaticResource : consoleStaticResources) {
- if (exchange.getRequestPath().endsWith(consoleStaticResource)) {
- exchange.setStatusCode(StatusCodes.FOUND);
- exchange.getResponseHeaders().put(Headers.LOCATION, "/static" + consoleStaticResource);
- exchange.endExchange();
- return;
- }
- }
+ // Authenticating requests requires a realm, either we receive this in a header or
+ // we extract it (e.g. from request path segment) and set it as a header before
+ // processing the request
+ HttpHandler baseApiHandler = apiHandler;
+
+ apiHandler = exchange -> {
+
+ String path = exchange.getRelativePath().substring(API_PATH.length());
+ Matcher realmSubMatcher = PATTERN_REALM_SUB.matcher(path);
+
+ if (!realmSubMatcher.matches()) {
+ exchange.setStatusCode(NOT_FOUND.getStatusCode());
+ throw new WebApplicationException(NOT_FOUND);
}
- consoleHandler.handleRequest(exchange);
- }, CONSOLE_PATH, CONSOLE_PATTERN
- );
- // Serve the UI deployment files unsecured
+ // Extract realm from path and push it into REQUEST_HEADER_REALM header
+ String realm = realmSubMatcher.group(1);
+
+ // Move the realm from path segment to header
+ exchange.getRequestHeaders().put(HttpString.tryFromString(REQUEST_HEADER_REALM), realm);
+
+ URI url = fromUri(exchange.getRequestURL())
+ .replacePath(realmSubMatcher.group(2))
+ .build();
+ exchange.setRequestURI(url.toString(), true);
+ exchange.setRequestPath(url.getPath());
+ exchange.setRelativePath(url.getPath());
+
+ baseApiHandler.handleRequest(exchange);
+ };
+ }
+
+ // Serve deployment files unsecured (explicitly map deployment folders to request paths)
+ appDocRoot = Paths.get(getString(container.getConfig(), APP_DOCROOT, APP_DOCROOT_DEFAULT));
uiDocRoot = Paths.get(getString(container.getConfig(), UI_DOCROOT, UI_DOCROOT_DEFAULT));
- addRoute(addDeployment(devMode, identityService, uiDocRoot, UI_PATH), UI_PATH, UI_PATTERN);
+ HttpHandler uiFileHandler = createFileHandler(devMode, identityService, uiDocRoot, null);
+ HttpHandler appBaseFileHandler = createFileHandler(devMode, identityService, appDocRoot, null);
- super.init(container);
- }
+ // Default app file handler to use index.html
+ HttpHandler appFileHandler = exchange -> {
+ if (exchange.getRelativePath().isEmpty() || "/".equals(exchange.getRelativePath())) {
+ exchange.setRelativePath("/index.html");
+ }
+ appBaseFileHandler.handleRequest(exchange);
+ };
- @Override
- public String getDefaultRealm() {
- return Constants.MASTER_REALM;
- }
+ // TODO: Remove this once GWT client is replaced
+ // Add a file handler for GWT source files in dev mode
+ if (container.isDevMode()) {
+ final HttpHandler baseGwtFileHandler = createFileHandler(devMode, identityService, Paths.get("client/src/main/webapp"), null);
+ final HttpHandler gwtFileHandler = exchange -> {
+ if (exchange.getRelativePath().isEmpty() || "/".equals(exchange.getRelativePath())) {
+ exchange.setRelativePath("/index.html");
+ }
+ baseGwtFileHandler.handleRequest(exchange);
+ };
+ HttpHandler standardHandler = appFileHandler;
- @Override
- protected HttpHandler getRealmIndexHandler() {
- return managerFileHandler;
+ appFileHandler = exchange -> {
+ String path = exchange.getRelativePath();
+ if (path.startsWith("/manager")) {
+ exchange.setRelativePath(path.substring(8));
+ gwtFileHandler.handleRequest(exchange);
+ } else if (path.startsWith("/app/manager")) {
+ exchange.setRelativePath(path.substring(12));
+ gwtFileHandler.handleRequest(exchange);
+ } else {
+ standardHandler.handleRequest(exchange);
+ }
+ };
+ }
+ HttpHandler finalAppFileHandler = appFileHandler;
+
+ // Serve deployment files
+ PathHandler deploymentHandler = new PathHandler(appFileHandler)
+ // TODO: Update this static file http handler to use shared folder in deployment
+ .addPrefixPath(STATIC_PATH, exchange -> {
+ // TODO: Remove this horrible hack for crappy polymer 2.x NPM package relative import issue
+ if (exchange.getRelativePath().startsWith("/node_modules/@polymer/shadycss")) {
+ exchange.setRelativePath("/node_modules/@webcomponents/shadycss" + exchange.getRequestPath().substring(38));
+ exchange.setRequestPath(STATIC_PATH + exchange.getRelativePath());
+ }
+
+ exchange.setRelativePath("/manager" + exchange.getRelativePath());
+ finalAppFileHandler.handleRequest(exchange);
+ })
+ .addPrefixPath(APP_PATH, appFileHandler)
+ // TODO: Remove this path prefix at some point
+ .addPrefixPath(CONSOLE_PATH, appFileHandler)
+ .addPrefixPath(UI_PATH, uiFileHandler);
+
+ // TODO: Remove this once all apps updated to new structure
+ final boolean useStaticBowerComponents =
+ getBoolean(container.getConfig(), CONSOLE_USE_STATIC_BOWER_COMPONENTS, CONSOLE_USE_STATIC_BOWER_COMPONENTS_DEFAULT);
+ if (useStaticBowerComponents) {
+ deploymentHandler.addPrefixPath("/bower_components", exchange -> {
+ exchange.setRequestPath("/manager/bower_components" + exchange.getRequestPath());
+ finalAppFileHandler.handleRequest(exchange);
+ });
+ }
+
+
+ // Add all route handlers required by the manager in priority order
+
+ // Redirect / to default app
+ getRequestHandlers().add(
+ new RequestHandler(
+ "Default app redirect",
+ exchange -> exchange.getRequestPath().equals("/"),
+ exchange -> {
+ LOG.fine("Handling root request, redirecting client to default app");
+ new RedirectHandler(redirect(exchange, "/" + defaultApp)).handleRequest(exchange);
+ }));
+
+ if (jsApiHandler != null) {
+ getRequestHandlers().add(pathStartsWithHandler("REST JS API Handler", JSAPI_PATH, jsApiHandler));
+ }
+
+ if (apiHandler != null) {
+ getRequestHandlers().add(pathStartsWithHandler("REST API Handler", API_PATH, apiHandler));
+ }
+
+ // This will try and handle any request that makes it to this handler
+ getRequestHandlers().add(
+ new RequestHandler(
+ "Deployment files",
+ exchange -> true,
+ deploymentHandler
+ )
+ );
+
+ super.init(container);
}
- public Path getManagerDocRoot() {
- return managerDocRoot;
+ /**
+ * Add resource/provider/etc. classes to enable REST API
+ */
+ public Collection<Class<?>> getApiClasses() {
+ return apiClasses;
}
- public Path getConsolesDocRoot() {
- return consolesDocRoot;
+ /**
+ * Add resource/provider/etc. singletons to enable REST API.
+ */
+ public Collection<Object> getApiSingletons() {
+ return apiSingletons;
}
- public Path getUiDocRoot() {
- return uiDocRoot;
+ public Path getAppDocRoot() {
+ return appDocRoot;
}
public String getConsoleUrl(UriBuilder baseUri, String realm) {
return baseUri.path(CONSOLE_PATH).path(realm).build().toString();
}
- protected HttpHandler addDeployment(boolean devMode, IdentityService identityService, Path filePath, String hostOnPath) {
- DeploymentInfo deploymentInfo = ManagerFileServlet.createDeploymentInfo(devMode, hostOnPath, filePath, new String[0]);
+ protected HttpHandler createApiHandler(IdentityService identityService, ResteasyDeployment resteasyDeployment) {
+ if (resteasyDeployment == null)
+ return null;
+
+ ServletInfo restServlet = Servlets.servlet("RESTEasy Servlet", HttpServlet30Dispatcher.class)
+ .setAsyncSupported(true)
+ .setLoadOnStartup(1)
+ .addMapping("/*");
+
+ DeploymentInfo deploymentInfo = new DeploymentInfo()
+ .setDeploymentName("RESTEasy Deployment")
+ .setContextPath(API_PATH)
+ .addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment)
+ .addServlet(restServlet)
+ .setClassLoader(Container.class.getClassLoader());
+
+ if (identityService != null) {
+ resteasyDeployment.setSecurityEnabled(true);
+ } else {
+ throw new RuntimeException("No identity service deployed, can't enable API security");
+ }
+
+ return addServletDeployment(identityService, deploymentInfo, resteasyDeployment.isSecurityEnabled());
+ }
+
+ protected HttpHandler createJsApiHandler(IdentityService identityService, ResteasyDeployment resteasyDeployment) {
+ if (resteasyDeployment == null)
+ return null;
+
+ ServletInfo jsApiServlet = Servlets.servlet("RESTEasy JS Servlet", JSAPIServlet.class)
+ .setAsyncSupported(true)
+ .setLoadOnStartup(1)
+ .addMapping("/*");
+
+ DeploymentInfo deploymentInfo = new DeploymentInfo()
+ .setDeploymentName("RESTEasy JS Deployment")
+ .setContextPath(JSAPI_PATH)
+ .addServlet(jsApiServlet)
+ .setClassLoader(Container.class.getClassLoader());
+
+ deploymentInfo.addServletContextAttribute(
+ ResteasyContextParameters.RESTEASY_DEPLOYMENTS,
+ new HashMap<String, ResteasyDeployment>() {{
+ put("", resteasyDeployment);
+ }}
+ );
return addServletDeployment(identityService, deploymentInfo, false);
}
- protected void addRoute(HttpHandler httpHandler, String hostOnPath, Pattern requestPattern) {
- getPrefixRoutes().put(hostOnPath, ManagerFileServlet.wrapHandler(httpHandler, requestPattern));
+ public HttpHandler createFileHandler(boolean devMode, IdentityService identityService, Path filePath, String[] requiredRoles) {
+ requiredRoles = requiredRoles == null ? new String[0] : requiredRoles;
+ DeploymentInfo deploymentInfo = ManagerFileServlet.createDeploymentInfo(devMode, "", filePath, requiredRoles);
+ return addServletDeployment(identityService, deploymentInfo, requiredRoles.length != 0);
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "managerDocRoot=" + managerDocRoot +
- ", consolesDocRoot=" + consolesDocRoot +
- ", uiDocRoot=" + uiDocRoot +
- '}';
+ "appDocRoot=" + appDocRoot +
+ '}';
}
}
diff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.java
index 35099897c..6ff1433a8 100644
--- a/model/src/main/java/org/openremote/model/Constants.java
+++ b/model/src/main/java/org/openremote/model/Constants.java
@@ -51,4 +51,5 @@ public interface Constants {
boolean SETUP_EMAIL_TLS_DEFAULT = true;
String SETUP_EMAIL_FROM = "SETUP_EMAIL_FROM";
String SETUP_EMAIL_FROM_DEFAULT = "[email protected]";
+ String REQUEST_HEADER_REALM = "Auth-Realm";
}