Skip to content

armgit / core

Public Imported from GitHub
0

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

Enabled Keycloak session timeouts/iframe with new defaults, pretty error view in or-app component, fixed ventilation bug in smart home example app

Christian Bauer04720f4c4a5b
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 b40b42aef..a8de88a03 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
@@ -10,7 +10,6 @@
display: none;
}
-
#basicAuthHeadline {
margin: 1em;
}
@@ -29,70 +28,70 @@
<!-- The basic auth form, only visible if Keycloak is not available -->
<div id="basicAuthForm" class="flex layout vertical center-center">
- <div id="basicAuthHeadline"
- class="layout horizontal center-center">
- <a href="https://www.openremote.com/">
- <svg style="pointer-events: none; display: block; width: 4em; height:4em; margin-right: 0.4em;"
- viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet">
- <path fill="#C4D600"
- d="M11.93,21.851c-5.551,0-10.066-4.515-10.066-10.065h2.108c0,4.388,3.57,7.958,7.958,7.958 c4.387,0,7.958-3.57,7.958-7.958c0-4.388-3.57-7.958-7.958-7.958V1.72c5.55,0,10.066,4.517,10.066,10.066 C21.996,17.336,17.48,21.851,11.93,21.851L11.93,21.851z"/>
- <path fill="#4E9D2D"
- d="M10.406,19.088c-1.95-0.406-3.626-1.549-4.717-3.215s-1.469-3.66-1.062-5.61 c0.407-1.951,1.55-3.626,3.217-4.718c1.667-1.092,3.659-1.469,5.61-1.062c4.027,0.84,6.62,4.799,5.779,8.825l-2.063-0.429 c0.603-2.889-1.257-5.73-4.147-6.333c-1.4-0.292-2.829-0.022-4.025,0.762C7.802,8.091,6.982,9.293,6.69,10.693 c-0.291,1.398-0.021,2.828,0.762,4.024c0.783,1.196,1.985,2.016,3.385,2.307L10.406,19.088L10.406,19.088z"/>
- <path fill="#1D5632"
- d="M11.936,16.622c-0.082,0-0.164-0.001-0.245-0.004c-1.29-0.065-2.478-0.628-3.346-1.585 c-0.868-0.958-1.31-2.195-1.246-3.487l2.104,0.105c-0.036,0.728,0.214,1.427,0.704,1.967c0.488,0.54,1.16,0.858,1.888,0.894 c0.725,0.033,1.426-0.213,1.966-0.703c0.541-0.489,0.858-1.159,0.895-1.887c0.075-1.503-1.088-2.787-2.591-2.862l0.105-2.104 c2.664,0.132,4.724,2.406,4.592,5.07c-0.064,1.291-0.628,2.478-1.585,3.345C14.28,16.183,13.137,16.622,11.936,16.622L11.936,16.622 z"/>
- </svg>
- </a>
- <div class="layout vertical">
- <div class="or-HeadlineText">Master</div>
- <div class="or-HeadlineSub">OpenRemote Login</div>
- </div>
+ <div id="basicAuthHeadline"
+ class="layout horizontal center-center">
+ <a href="https://www.openremote.com/">
+ <svg style="pointer-events: none; display: block; width: 4em; height:4em; margin-right: 0.4em;"
+ viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet">
+ <path fill="#C4D600"
+ d="M11.93,21.851c-5.551,0-10.066-4.515-10.066-10.065h2.108c0,4.388,3.57,7.958,7.958,7.958 c4.387,0,7.958-3.57,7.958-7.958c0-4.388-3.57-7.958-7.958-7.958V1.72c5.55,0,10.066,4.517,10.066,10.066 C21.996,17.336,17.48,21.851,11.93,21.851L11.93,21.851z"/>
+ <path fill="#4E9D2D"
+ d="M10.406,19.088c-1.95-0.406-3.626-1.549-4.717-3.215s-1.469-3.66-1.062-5.61 c0.407-1.951,1.55-3.626,3.217-4.718c1.667-1.092,3.659-1.469,5.61-1.062c4.027,0.84,6.62,4.799,5.779,8.825l-2.063-0.429 c0.603-2.889-1.257-5.73-4.147-6.333c-1.4-0.292-2.829-0.022-4.025,0.762C7.802,8.091,6.982,9.293,6.69,10.693 c-0.291,1.398-0.021,2.828,0.762,4.024c0.783,1.196,1.985,2.016,3.385,2.307L10.406,19.088L10.406,19.088z"/>
+ <path fill="#1D5632"
+ d="M11.936,16.622c-0.082,0-0.164-0.001-0.245-0.004c-1.29-0.065-2.478-0.628-3.346-1.585 c-0.868-0.958-1.31-2.195-1.246-3.487l2.104,0.105c-0.036,0.728,0.214,1.427,0.704,1.967c0.488,0.54,1.16,0.858,1.888,0.894 c0.725,0.033,1.426-0.213,1.966-0.703c0.541-0.489,0.858-1.159,0.895-1.887c0.075-1.503-1.088-2.787-2.591-2.862l0.105-2.104 c2.664,0.132,4.724,2.406,4.592,5.07c-0.064,1.291-0.628,2.478-1.585,3.345C14.28,16.183,13.137,16.622,11.936,16.622L11.936,16.622 z"/>
+ </svg>
+ </a>
+ <div class="layout vertical">
+ <div class="or-HeadlineText">Master</div>
+ <div class="or-HeadlineSub">OpenRemote Login</div>
</div>
-
- <div id="basicAuthMessage"
- class="layout horizontal center or-FormMessages error"
- style="display: none;">
- <div class="or-Icon fa fa-warning"></div>
- <span id="basicAuthMessageText"></span>
- </div>
-
- <form class="layout vertical or-Form">
- <div class="layout horizontal center or-FormGroup">
- <div class="or-FormLabel">
- <label for="username">Username</label>
- </div>
- <div class="or-FormField">
- <input id="username"
- autofocus
- autocomplete="off"
- autocapitalize="off"
- class="or-FormControl or-FormInputText"
- name="username"
- value="{{user::input}}"
- type="text"/>
- </div>
+ </div>
+
+ <div id="basicAuthMessage"
+ class="layout horizontal center or-FormMessages error"
+ style="display: none;">
+ <div class="or-Icon fa fa-warning"></div>
+ <span id="basicAuthMessageText"></span>
+ </div>
+
+ <form class="layout vertical or-Form">
+ <div class="layout horizontal center or-FormGroup">
+ <div class="or-FormLabel">
+ <label for="username">Username</label>
</div>
- <div class="layout horizontal center or-FormGroup">
- <div class="or-FormLabel">
- <label for="password">Password</label>
- </div>
- <div class="or-FormField">
- <input id="password"
- class="or-FormControl or-FormInputText"
- name="password"
- type="password"
- value="{{basicAuthPassword::input}}"
- autocomplete="off"/>
- </div>
+ <div class="or-FormField">
+ <input id="username"
+ autofocus
+ autocomplete="off"
+ autocapitalize="off"
+ class="or-FormControl or-FormInputText"
+ name="username"
+ value="{{user::input}}"
+ type="text"/>
</div>
- <div class="layout horizontal center-center or-FormGroup">
- <input class="or-FormControl or-FormButtonPrimary or-PushButton"
- name="login"
- type="submit"
- value="Log in"
- onclick="return false"
- on-click="performBasicAuthentication"/>
+ </div>
+ <div class="layout horizontal center or-FormGroup">
+ <div class="or-FormLabel">
+ <label for="password">Password</label>
+ </div>
+ <div class="or-FormField">
+ <input id="password"
+ class="or-FormControl or-FormInputText"
+ name="password"
+ type="password"
+ value="{{basicAuthPassword::input}}"
+ autocomplete="off"/>
</div>
- </form>
+ </div>
+ <div class="layout horizontal center-center or-FormGroup">
+ <input class="or-FormControl or-FormButtonPrimary or-PushButton"
+ name="login"
+ type="submit"
+ value="Log in"
+ onclick="return false"
+ on-click="performBasicAuthentication"/>
+ </div>
+ </form>
</div>
</template>
@@ -234,14 +233,14 @@
}
getFullName() {
- if (this.authenticated && this.keycloak) {
+ if (this.authenticated && this.keycloak && this.keycloak.tokenParsed && this.keycloak.tokenParsed.name) {
return this.keycloak.tokenParsed.name;
}
return this.user;
}
getUserId() {
- if (this.authenticated && this.keycloak) {
+ if (this.authenticated && this.keycloak && this.keycloak.tokenParsed && this.keycloak.tokenParsed.sub) {
return this.keycloak.tokenParsed.sub;
}
return this.user;
@@ -335,8 +334,8 @@
var managerHost = '';
var hostURI = this.importPath;
- if ( hostURI ) {
- managerHost = '//' + new URL(hostURI).host;
+ if (hostURI) {
+ managerHost = '//' + new URL(hostURI).host;
}
let keycloakConfig = {
@@ -355,15 +354,10 @@
startKeycloakAuthentication() {
console.debug("Keycloak authentication init");
-
- // Disable invisible login status iframe of Keycloak, it only checks the max session lifespan anyway:
- //
- // For this, Keycloak sets a cookie that expires when the max session lifespan has been reached, then logs
- // you out when the cookie disappears. We get the same effect when the user triggers an HTTP request
- // and access token has to be obtained, if either the session/offline idle or max lifespan has been
- // reached the refresh will fail and we log out.
- //
- this.keycloak.init({checkLoginIframe: false, checkLoginIframeInterval: 10})
+ // Require login and enable invisible login status iframe of Keycloak: This sets a cookie that
+ // expires when the max session lifespan has been reached, then logs you out when the
+ // cookie disappears.
+ this.keycloak.init({onLoad: "login-required", checkLoginIframe: true, checkLoginIframeInterval: 5})
.success((authenticated) => {
if (authenticated) {
this.onKeycloakAuthSuccess()
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 8be619a74..1e604cc21 100644
--- a/client/src/main/webapp/src/or-app/or-app.html
+++ b/client/src/main/webapp/src/or-app/or-app.html
@@ -2,6 +2,8 @@
<link rel="import" href="or-style.html">
<!-- App services/dependencies -->
+<link rel="import" href="or-busy-indicator.html">
+<link rel="import" href="or-error-view.html">
<link rel="import" href="or-shell-native.html">
<link rel="import" href="or-app-security.html">
<link rel="import" href="or-app-events.html">
@@ -16,49 +18,6 @@
<style include="or-style">
- /* Children of or-app might be hidden by host page, some have to be visible */
- #loader,
- #errorView {
- visibility: visible !important;
- }
-
- #loader {
- z-index: 9999;
- position: fixed;
- bottom: 0.8em;
- right: 0.4em;
- pointer-events: none;
- width: 0.8em;
- height: 0.8em;
- border: 2px solid var(--theme-lightgreen);
- border-top-color: var(--theme-black);
- border-radius: 50%;
- -webkit-animation: loaderSpin 1s linear infinite;
- animation: loaderSpin 1s linear infinite;
- }
-
- @-webkit-keyframes loaderSpin {
- 100% {
- -webkit-transform: rotate(360deg);
- transform: rotate(360deg);
- }
- }
-
- @keyframes loaderSpin {
- 100% {
- -webkit-transform: rotate(360deg);
- transform: rotate(360deg);
- }
- }
-
- #errorView {
- padding: 1em;
- }
-
- #errorView h1 {
- color: var(--theme-darkgrey);
- }
-
/* Slots are not shown until we are ready */
#slots {
display: none;
@@ -71,7 +30,7 @@
*/
</style>
- <div id="loader"></div>
+ <or-busy-indicator id="busyIndicator"></or-busy-indicator>
<or-shell-native id="shellNative"></or-shell-native>
@@ -85,10 +44,7 @@
<or-app-events id="appEvents"></or-app-events>
<template is="dom-if" if="[[error]]">
- <div id="errorView" class="or-Viewport">
- <h1>[[defaultErrorMessage]]</h1>
- <h5>[[error]]</h5>
- </div>
+ <or-error-view id="errorView" error="[[error]]"></or-error-view>
</template>
<div id="slots" class="flex layout vertical">
@@ -221,16 +177,6 @@
observer: "onAppError"
},
- /**
- * The message that should be shown to the user, before the error state.
- */
- defaultErrorMessage: {
- type: String,
- value: function () {
- return "Service not available or application error, please try again later.";
- }
- },
-
/**
* Produces promises to load JS, CSS, HTML, IMG resources.
*/
@@ -368,6 +314,10 @@
});
}
+ setError(error) {
+ this.set("error", error);
+ }
+
onAppError(error) {
console.error("Application error, disabling app: " + error);
@@ -383,8 +333,7 @@
// Hide the slots
this.$.slots.style.display = "none";
- // Hide the loader
- this.hideLoader();
+ this.hideBusyIndicator();
// Fire an event so others can react to an error
window.dispatchEvent(new CustomEvent("AppError", {detail: {app: this, error: error}}));
@@ -408,16 +357,15 @@
}
});
- // Hide the loader
- this.hideLoader();
+ this.hideBusyIndicator();
}
- hideLoader() {
- this.$.loader.style.display = "none";
+ hideBusyIndicator() {
+ this.$.busyIndicator.hide();
}
- showLoader() {
- this.$.loader.style.display = "inherit";
+ showBusyIndicator() {
+ this.$.busyIndicator.show();
}
getSecurity() {
@@ -438,8 +386,8 @@
(requestParams, onComplete) => {
this.getSecurity().authorizeRequestParams(requestParams, onComplete);
},
- this.showLoader.bind(this),
- this.hideLoader.bind(this),
+ this.showBusyIndicator.bind(this),
+ this.hideBusyIndicator.bind(this),
(requestError) => {
this.set("error", "Request error (response status: " + requestError.statusCode + ") - " + requestError.message);
},
@@ -490,7 +438,7 @@
this.webSocket.onerror = () => {
this.set("webSocket", undefined);
this.set("status", "DISCONNECTED");
- this.set("error", "Error connecting to event service: " + serviceUrl);
+ this.set("error", "Error connecting to " + serviceUrl);
};
this.webSocket.onclose = (e) => {
@@ -500,12 +448,12 @@
if (e.code === 1000) {
// Do nothing, we closed the socket
} else if (e.code === 1001) {
- this.set("error", "Server closed connection to event service: " + serviceUrl);
+ this.set("error", "Connection closed by server.");
} else if (e.code === 1006) {
- this.set("error", "Event service connection was closed, server not reachable?");
+ this.set("error", "Network or server offline.");
} else {
let msg = e.reason ? e.reason : serviceUrl;
- this.set("error", "Event service connection was closed (clean: " + e.wasClean + ", code: " + e.code + "): " + msg);
+ this.set("error", "Connection closed (clean: " + e.wasClean + ", code: " + e.code + "): " + msg);
}
}
};
diff --git a/client/src/main/webapp/src/or-app/or-busy-indicator.html b/client/src/main/webapp/src/or-app/or-busy-indicator.html
new file mode 100644
index 000000000..d87e4a9c6
--- /dev/null
+++ b/client/src/main/webapp/src/or-app/or-busy-indicator.html
@@ -0,0 +1,65 @@
+<link rel="import" href="or-style.html">
+
+<dom-module id="or-busy-indicator">
+ <template>
+ <style include="or-style">
+ #spinner {
+ z-index: 9999;
+ position: absolute;
+ bottom: 0.8em;
+ right: 0.4em;
+ pointer-events: none;
+ width: 0.8em;
+ height: 0.8em;
+ border: 2px solid var(--theme-lightgreen);
+ border-top-color: var(--theme-darkgrey);
+ border-radius: 50%;
+ -webkit-animation: spinAnimation 1000ms linear infinite;
+ animation: spinAnimation 1000ms linear infinite;
+ }
+
+ @-webkit-keyframes spinAnimation {
+ 100% {
+ -webkit-transform: rotate(360deg);
+ transform: rotate(360deg);
+ }
+ }
+
+ @keyframes spinAnimation {
+ 100% {
+ -webkit-transform: rotate(360deg);
+ transform: rotate(360deg);
+ }
+ }
+ </style>
+
+ <div id="spinner"></div>
+
+ </template>
+
+ <script>
+ class OpenRemoteBusyIndicator extends Polymer.Element {
+
+ static get is() {
+ return "or-busy-indicator";
+ }
+
+ static get properties() {
+ return {
+ }
+ }
+
+ show() {
+ this.$.spinner.style.display = "inherit";
+ }
+
+ hide() {
+ this.$.spinner.style.display = "none";
+ }
+ }
+
+ // Upgrade immediately, so you can't use jsinterop in this class!
+ customElements.define(OpenRemoteBusyIndicator.is, OpenRemoteBusyIndicator);
+ </script>
+
+</dom-module>
\ No newline at end of file
diff --git a/client/src/main/webapp/src/or-app/or-error-view.html b/client/src/main/webapp/src/or-app/or-error-view.html
new file mode 100644
index 000000000..49a08fa75
--- /dev/null
+++ b/client/src/main/webapp/src/or-app/or-error-view.html
@@ -0,0 +1,94 @@
+<link rel="import" href="or-style.html">
+
+<dom-module id="or-error-view">
+ <template>
+ <style include="or-style">
+
+ .logo {
+ pointer-events: none;
+ display: block;
+ width: 4em;
+ height: 4em;
+ margin-right: 0.4em;
+ }
+
+ .defaultErrorMessage {
+ margin: 0;
+ white-space: nowrap;
+ }
+
+ .error {
+ max-width: 20em;
+ }
+
+ .actions {
+ width: 20em;
+ margin: 1em 0;
+ }
+ </style>
+
+ <div class="layout horizontal center-center">
+ <svg class="logo" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet">
+ <path fill="#C4D600"
+ d="M11.93,21.851c-5.551,0-10.066-4.515-10.066-10.065h2.108c0,4.388,3.57,7.958,7.958,7.958 c4.387,0,7.958-3.57,7.958-7.958c0-4.388-3.57-7.958-7.958-7.958V1.72c5.55,0,10.066,4.517,10.066,10.066 C21.996,17.336,17.48,21.851,11.93,21.851L11.93,21.851z"/>
+ <path fill="#4E9D2D"
+ d="M10.406,19.088c-1.95-0.406-3.626-1.549-4.717-3.215s-1.469-3.66-1.062-5.61 c0.407-1.951,1.55-3.626,3.217-4.718c1.667-1.092,3.659-1.469,5.61-1.062c4.027,0.84,6.62,4.799,5.779,8.825l-2.063-0.429 c0.603-2.889-1.257-5.73-4.147-6.333c-1.4-0.292-2.829-0.022-4.025,0.762C7.802,8.091,6.982,9.293,6.69,10.693 c-0.291,1.398-0.021,2.828,0.762,4.024c0.783,1.196,1.985,2.016,3.385,2.307L10.406,19.088L10.406,19.088z"/>
+ <path fill="#1D5632"
+ d="M11.936,16.622c-0.082,0-0.164-0.001-0.245-0.004c-1.29-0.065-2.478-0.628-3.346-1.585 c-0.868-0.958-1.31-2.195-1.246-3.487l2.104,0.105c-0.036,0.728,0.214,1.427,0.704,1.967c0.488,0.54,1.16,0.858,1.888,0.894 c0.725,0.033,1.426-0.213,1.966-0.703c0.541-0.489,0.858-1.159,0.895-1.887c0.075-1.503-1.088-2.787-2.591-2.862l0.105-2.104 c2.664,0.132,4.724,2.406,4.592,5.07c-0.064,1.291-0.628,2.478-1.585,3.345C14.28,16.183,13.137,16.622,11.936,16.622L11.936,16.622 z"/>
+ </svg>
+ <div class="layout vertical">
+ <div class="or-HeadlineText defaultErrorMessage">[[defaultErrorMessage]]</div>
+ <div class="or-HeadlineSub error">[[error]]
+ </div>
+ </div>
+ </div>
+ <div class="layout horizontal center-center or-FormGroup actions">
+ <div class="or-FormField layout horizontal center-center">
+ <button class="or-FormButtonPrimary or-PushButton"
+ onclick="window.location = window.location.href.split('#')[0]">
+ <span class="or-Icon fa fa-refresh"></span>
+ <span class="html-face">Try Again</span>
+ </button>
+ </div>
+ </div>
+
+ </template>
+
+ <script>
+ class OpenRemoteErrorView extends Polymer.Element {
+
+ static get is() {
+ return "or-error-view";
+ }
+
+ static get properties() {
+ return {
+ /**
+ * The message that should be shown to the user, before the error state.
+ */
+ defaultErrorMessage: {
+ type: String,
+ value: function () {
+ return "Service not available";
+ }
+ },
+ /**
+ * The error state (message).
+ */
+ error: {
+ type: String
+ }
+ }
+ }
+
+ ready() {
+ super.ready();
+ this.shadowRoot.host.classList.add("layout", "vertical", "center-center", "or-Viewport");
+ }
+ }
+
+ // Upgrade immediately, so you can't use jsinterop in this class!
+ customElements.define(OpenRemoteErrorView.is, OpenRemoteErrorView);
+ </script>
+
+</dom-module>
\ No newline at end of file
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 fbb643838..95f1bae83 100644
--- a/client/src/main/webapp/src/or-app/or-style.html
+++ b/client/src/main/webapp/src/or-app/or-style.html
@@ -143,6 +143,11 @@
opacity: inherit;
}
+ .or-PushButton,
+ .or-FormFileUploadLabel {
+ outline: 0;
+ }
+
.or-PushButton.or-PushButton-up-disabled {
cursor: not-allowed;
opacity: .44;
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 06b1cf13d..eb0e367f2 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
@@ -23,7 +23,6 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.undertow.server.HttpHandler;
-import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.ResponseCodeHandler;
import io.undertow.server.handlers.proxy.ProxyHandler;
import io.undertow.servlet.api.DeploymentInfo;
@@ -58,7 +57,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.MINUTES;
-import static java.util.concurrent.TimeUnit.SECONDS;
import static javax.ws.rs.core.Response.Status.Family.REDIRECTION;
import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL;
import static org.openremote.container.util.MapAccess.getInteger;
@@ -81,12 +79,12 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {
public static final String KEYCLOAK_CLIENT_POOL_SIZE = "KEYCLOAK_CLIENT_POOL_SIZE";
public static final int KEYCLOAK_CLIENT_POOL_SIZE_DEFAULT = 20;
- public static final String IDENTITY_SESSION_TIMEOUT_SECONDS = "IDENTITY_SESSION_TIMEOUT_SECONDS";
- public static final int IDENTITY_SESSION_TIMEOUT_SECONDS_DEFAULT = 60 * 60 * 3; // 3 hours
- public static final String IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS = "IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS";
- public static final int IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS_DEFAULT = 60 * 60 * 48; // 2 days
- public static final String IDENTITY_SESSION_MAX_SECONDS = "IDENTITY_SESSION_MAX_SECONDS";
- public static final int IDENTITY_SESSION_MAX_SECONDS_DEFAULT = 60 * 60 * 10; // 10 hours
+ public static final String IDENTITY_SESSION_TIMEOUT_MINUTES = "IDENTITY_SESSION_TIMEOUT_MINUTES";
+ public static final int IDENTITY_SESSION_TIMEOUT_MINUTES_DEFAULT = 60 * 24; // 1 day
+ public static final String IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES = "IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES";
+ public static final int IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES_DEFAULT = 60 * 24; // 1 day
+ public static final String IDENTITY_SESSION_MAX_MINUTES = "IDENTITY_SESSION_MAX_MINUTES";
+ public static final int IDENTITY_SESSION_MAX_MINUTES_DEFAULT = 60 * 24 * 14; // 14 days
// Each realm in Keycloak has a client application with this identifier
final protected String clientId;
@@ -122,17 +120,17 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {
this.clientId = clientId;
this.externalServerUri = externalServerUri;
- sessionTimeoutSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_TIMEOUT_SECONDS, IDENTITY_SESSION_TIMEOUT_SECONDS_DEFAULT);
+ sessionTimeoutSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_TIMEOUT_MINUTES, IDENTITY_SESSION_TIMEOUT_MINUTES_DEFAULT) * 60;
if (sessionTimeoutSeconds < 60) {
- throw new IllegalArgumentException(IDENTITY_SESSION_TIMEOUT_SECONDS + " must be more than 60 seconds");
+ throw new IllegalArgumentException(IDENTITY_SESSION_TIMEOUT_MINUTES + " must be more than 1 minute");
}
- sessionOfflineTimeoutSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS, IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS_DEFAULT);
+ sessionOfflineTimeoutSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES, IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES_DEFAULT) * 60;
if (sessionOfflineTimeoutSeconds < 60) {
- throw new IllegalArgumentException(IDENTITY_SESSION_OFFLINE_TIMEOUT_SECONDS + " must be more than 60 seconds");
+ throw new IllegalArgumentException(IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES + " must be more than 1 minute");
}
- sessionMaxSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_MAX_SECONDS, IDENTITY_SESSION_MAX_SECONDS_DEFAULT);
+ sessionMaxSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_MAX_MINUTES, IDENTITY_SESSION_MAX_MINUTES_DEFAULT) * 60;
if (sessionMaxSeconds < 60) {
- throw new IllegalArgumentException(IDENTITY_SESSION_MAX_SECONDS + " must be more than 60 seconds");
+ throw new IllegalArgumentException(IDENTITY_SESSION_MAX_MINUTES + " must be more than 1 minute");
}
keycloakServiceUri =
diff --git a/deployment/manager/consoles/customerA/smart-home/smart-home-climate.html b/deployment/manager/consoles/customerA/smart-home/smart-home-climate.html
index 19dfb663e..076b6b662 100644
--- a/deployment/manager/consoles/customerA/smart-home/smart-home-climate.html
+++ b/deployment/manager/consoles/customerA/smart-home/smart-home-climate.html
@@ -212,7 +212,7 @@
}
onResidenceChange() {
- let ventilationMode = null;
+ let ventilationMode;
if ("ventilationAuto" in this.residence.attributes && this.residence.attributes.ventilationAuto.value) {
ventilationMode = "AUTO";
} else if ("ventilationLevel" in this.residence.attributes) {
diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
index 425fe4458..0ef4672c7 100644
--- a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java
@@ -24,6 +24,7 @@ import org.openremote.agent.protocol.macro.MacroAction;
import org.openremote.agent.protocol.macro.MacroProtocol;
import org.openremote.agent.protocol.timer.TimerValue;
import org.openremote.container.Container;
+import org.openremote.manager.asset.AssetProcessingService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.asset.ServerAsset;
import org.openremote.manager.datapoint.AssetDatapointService;
@@ -54,6 +55,7 @@ public abstract class AbstractManagerSetup implements Setup {
final protected ManagerPersistenceService persistenceService;
final protected ManagerIdentityService identityService;
final protected AssetStorageService assetStorageService;
+ final protected AssetProcessingService assetProcessingService;
final protected AssetDatapointService assetDatapointService;
final protected RulesetStorageService rulesetStorageService;
final protected GeometryFactory geometryFactory = new GeometryFactory();
@@ -63,6 +65,7 @@ public abstract class AbstractManagerSetup implements Setup {
this.persistenceService = container.getService(ManagerPersistenceService.class);
this.identityService = container.getService(ManagerIdentityService.class);
this.assetStorageService = container.getService(AssetStorageService.class);
+ this.assetProcessingService = container.getService(AssetProcessingService.class);
this.assetDatapointService = container.getService(AssetDatapointService.class);
this.rulesetStorageService = container.getService(RulesetStorageService.class);
this.setupService = container.getService(SetupService.class);
@@ -74,7 +77,7 @@ public abstract class AbstractManagerSetup implements Setup {
ServerAsset apartment = new ServerAsset(name, RESIDENCE, parent);
apartment.setLocation(parent.getLocation());
apartment.setAttributes(
- new AssetAttribute("alarmEnabled", AttributeType.BOOLEAN, Values.create(false))
+ new AssetAttribute("alarmEnabled", AttributeType.BOOLEAN)
.setMeta(new Meta(
new MetaItem(LABEL, Values.create("Alarm enabled")),
new MetaItem(DESCRIPTION, Values.create("Send notifications when presence is detected")),
@@ -101,29 +104,30 @@ public abstract class AbstractManagerSetup implements Setup {
new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)),
new MetaItem(RULE_STATE, Values.create(true))
)),
- new AssetAttribute("autoSceneSchedule", AttributeType.BOOLEAN, Values.create(true))
- .setMeta(
- new MetaItem(LABEL, Values.create("Automatic scene schedule")),
- new MetaItem(DESCRIPTION, Values.create("Predict presence and automatically adjust scene schedule")),
- new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
- new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)),
- new MetaItem(RULE_STATE, Values.create(true))
- ),
- new AssetAttribute("lastExecutedScene", AttributeType.STRING, Values.create("HOME"))
+ new AssetAttribute("lastExecutedScene", AttributeType.STRING)
.setMeta(
new MetaItem(LABEL, Values.create("Last executed scene")),
new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
new MetaItem(READ_ONLY, Values.create(true)),
new MetaItem(RULE_STATE, Values.create(true)),
new MetaItem(SHOW_ON_DASHBOARD, Values.create(true))
+ )
+ /* TODO Unused, can be removed? Port schedule prediction from DRL...
+ new AssetAttribute("autoSceneSchedule", AttributeType.BOOLEAN)
+ .setMeta(
+ new MetaItem(LABEL, Values.create("Automatic scene schedule")),
+ new MetaItem(DESCRIPTION, Values.create("Predict presence and automatically adjust scene schedule")),
+ new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
+ new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)),
+ new MetaItem(RULE_STATE, Values.create(true))
),
- // TODO Unused, can be removed? Port schedule prediction from DRL...
- new AssetAttribute("lastDetectedScene", AttributeType.STRING, Values.create("home"))
+ new AssetAttribute("lastDetectedScene", AttributeType.STRING)
.setMeta(
new MetaItem(LABEL, Values.create("Last detected scene by rules")),
new MetaItem(READ_ONLY, Values.create(true)),
new MetaItem(RULE_STATE, Values.create(true))
)
+ */
);
return apartment;
}
@@ -477,14 +481,14 @@ public abstract class AbstractManagerSetup implements Setup {
}
}
apartment.addAttributes(
- new AssetAttribute("sceneTimerEnabled", AttributeType.BOOLEAN, Values.create(true))
+ new AssetAttribute("sceneTimerEnabled", AttributeType.BOOLEAN)
.setMeta(
new MetaItem(LABEL, Values.create("Scene timer enabled")),
new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
new MetaItem(SHOW_ON_DASHBOARD, Values.create(true)),
new MetaItem(READ_ONLY, Values.create(true))
),
- new AssetAttribute("enableSceneTimer", AttributeType.STRING, Values.create(AttributeExecuteStatus.READY.name()))
+ new AssetAttribute("enableSceneTimer", AttributeType.STRING)
.setMeta(
new MetaItem(LABEL, Values.create("Enable scene timer")),
new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
@@ -492,7 +496,7 @@ public abstract class AbstractManagerSetup implements Setup {
new MetaItem(EXECUTABLE, Values.create(true)),
new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), "enableSceneTimer").toArrayValue())
),
- new AssetAttribute("disableSceneTimer", AttributeType.STRING, Values.create(AttributeExecuteStatus.READY.name()))
+ new AssetAttribute("disableSceneTimer", AttributeType.STRING)
.setMeta(
new MetaItem(LABEL, Values.create("Disable scene timer")),
new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
index 03dbe6703..f423798a8 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
@@ -50,7 +50,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
final protected boolean importDemoScenes;
// Update these numbers whenever you change a RULE_STATE flag in test data
- public static final int DEMO_RULE_STATES_APARTMENT_1 = 39;
+ public static final int DEMO_RULE_STATES_APARTMENT_1 = 37;
public static final int DEMO_RULE_STATES_APARTMENT_2 = 11;
public static final int DEMO_RULE_STATES_APARTMENT_3 = 0;
public static final int DEMO_RULE_STATES_SMART_HOME = DEMO_RULE_STATES_APARTMENT_1 + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3;
diff --git a/model/src/main/java/org/openremote/model/notification/NotificationResource.java b/model/src/main/java/org/openremote/model/notification/NotificationResource.java
index b5d1fb1b1..29aab35ff 100644
--- a/model/src/main/java/org/openremote/model/notification/NotificationResource.java
+++ b/model/src/main/java/org/openremote/model/notification/NotificationResource.java
@@ -128,6 +128,7 @@ public interface NotificationResource {
@PathParam("userId") String userId,
@PathParam("alertId") Long id);
+ // TODO Fails silently on native apps when called with expired offline token?
@GET
@Path("alert")
@Produces(APPLICATION_JSON)
diff --git a/profile/deploy.yml b/profile/deploy.yml
index 1d17214b4..dd406df30 100644
--- a/profile/deploy.yml
+++ b/profile/deploy.yml
@@ -102,7 +102,7 @@ services:
# SETUP_WIPE_CLEAN_INSTALL: # Allow override on CLI
# SETUP_ADMIN_PASSWORD: # Allow override on CLI
- # Optional: Configure SMTP smart host for Keycloak, to send password reset emails etc.
+ # Configure SMTP smart host for Keycloak, to send password reset emails etc.
#SETUP_KEYCLOAK_EMAIL_HOST: smtp-host.demo.tld
#SETUP_KEYCLOAK_EMAIL_USER: 'smtp-user'
#SETUP_KEYCLOAK_EMAIL_PASSWORD: 'smtp-password'
@@ -161,24 +161,24 @@ services:
# when running in container. Default is 127.0.0.1.
WEBSERVER_LISTEN_HOST: 0.0.0.0
- # Optional: Console applications can register for push notifications through FCM.
+ # Console applications can register for push notifications through FCM.
# NOTIFICATION_FIREBASE_URL: https://fcm.googleapis.com/fcm/send
# NOTIFICATION_FIREBASE_API_KEY = '...'
- # Optional: Custom location of the static console applications, each subdirectory must
+ # Custom location of the static console applications, each subdirectory must
# have the name of a realm to which the console app belongs.
# CONSOLES_DOCROOT: '/deployment/consoles'
- # Optional: Disable HTTP redirects when a console application requests libraries which
+ # Disable HTTP redirects when a console application requests libraries which
# are delivered and used on the platform. This is necessary if your console application
# needs a different version of Polymer, Chart JS, or any of the other "bower_components"
# which are by default served as static resources from the manager service.
# CONSOLE_USE_STATIC_BOWER_COMPONENTS = 'false'
- # Optional: Provide a path to the map tiles database file (see https://openmaptiles.com/).
+ # Provide a path to the map tiles database file (see https://openmaptiles.com/).
# MAP_TILES_PATH: '/deployment/map/mapdata.mbtiles'
- # Optional: Override the map settings such as center location and zoom when opening the
+ # Override the map settings such as center location and zoom when opening the
# manager's map, as well as other style details and colours.
# MAP_SETTINGS_PATH: '/deployment/map/mapsettings.json'
@@ -199,10 +199,22 @@ services:
# The identity provider implementation to use for managing user identities, roles, and
# access authorization. The default is Keycloak, which requires a separate service but
- # provides full multi-tenancy identity and role management. The basic provider supports
- # only superusers and their text passwords, managed in a simple database table.
+ # provides full multi-tenancy identity, role permissions, and user session timeouts.
+ # The basic provider supports only superusers and their text passwords, managed in a
+ # simple database table, and always requires a new login when a page is reloaded.
# IDENTITY_PROVIDER: 'basic'
+ # For the Keycloak identity provider, you may configure session timeouts of frontend apps. This
+ # will only be applied on newly created realms, or once on the master realm when clean setup runs.
+ #
+ # The idle session timeout, logging the user out if no requests are made, default is 1 day.
+ # Note that WebSocket events do not count as requests and therefore do not extend the session!
+ # IDENTITY_SESSION_TIMEOUT_MINUTES : 1440
+ # The max session lifespan, always logging the user out when expired, default is 1 day.
+ # IDENTITY_SESSION_MAX_MINUTES: 1440
+ # The max offline token lifespan, forcing login on native console when app not used, default is 14 days.
+ # IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES: 20160
+
# Location of the static manager (UI and API) resources, you don't need to override this
# unless you want to deploy a modified version of the Manager UI and JavaScript components.
# MANAGER_DOCROOT: 'client/src/main/webapp'
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index 74553867f..ddec30a4a 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -167,12 +167,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets[1].tenantDisplayName == null
assets[1].coordinates == null
assets[1].path == null
- assets[1].getAttributesList().size() == 7
+ assets[1].getAttributesList().size() == 6
assets[1].getAttribute("ventilationAuto").isPresent()
assets[1].getAttribute("ventilationLevel").isPresent()
assets[1].getAttribute("alarmEnabled").isPresent()
assets[1].getAttribute("vacationUntil").isPresent()
- assets[1].getAttribute("autoSceneSchedule").isPresent()
assets[1].getAttribute("lastExecutedScene").isPresent()
assets[1].getAttribute("presenceDetected").isPresent()
assets[1].getAttribute("alarmEnabled").get().meta.size() == 1
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
index c4b408975..41590eb9c 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
@@ -53,18 +53,13 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
assert apartment1Engine != null
assert apartment1Engine.isRunning()
assert apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1_WITH_SCENES
- }
- and: "scene timers should be enabled"
- conditions.eventually {
+ // The macro should be ready
def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("sceneTimerEnabled").orElse(null).getValueAsBoolean().orElse(null)
- DayOfWeek.values().each {
- assert asset.getAttribute("homeSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("awaySceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("eveningSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("nightSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- }
+ def executionStatus = AttributeExecuteStatus.fromString(
+ asset.getAttribute("awayScene").get().getValueAsString().get()
+ ).get()
+ assert executionStatus == AttributeExecuteStatus.READY
}
when: "the vacation days are set to 5"
@@ -77,15 +72,15 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
def executionStatus = AttributeExecuteStatus.fromString(
- asset.getAttribute("awayScene").orElse(null).getValueAsString().orElse(null)
- ).orElse(null)
+ asset.getAttribute("awayScene").get().getValueAsString().get()
+ ).get()
assert executionStatus == AttributeExecuteStatus.COMPLETED
- assert !asset.getAttribute("sceneTimerEnabled").orElse(null).getValueAsBoolean().orElse(null)
+ assert !asset.getAttribute("sceneTimerEnabled").get().getValueAsBoolean().get()
DayOfWeek.values().each {
- assert !asset.getAttribute("homeSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("awaySceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("eveningSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("nightSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
+ assert !asset.getAttribute("homeSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("awaySceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("eveningSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("nightSceneEnabled" + it.name()).get().getValueAsBoolean().get()
}
}
@@ -95,13 +90,13 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
then: "vacation mode is still on"
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("vacationUntil").orElse(null).getValueAsNumber().orElse(null) == fiveDaysInFuture
- assert !asset.getAttribute("sceneTimerEnabled").orElse(null).getValueAsBoolean().orElse(null)
+ assert asset.getAttribute("vacationUntil").get().getValueAsNumber().get() == fiveDaysInFuture
+ assert !asset.getAttribute("sceneTimerEnabled").get().getValueAsBoolean().get()
DayOfWeek.values().each {
- assert !asset.getAttribute("homeSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("awaySceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("eveningSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert !asset.getAttribute("nightSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
+ assert !asset.getAttribute("homeSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("awaySceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("eveningSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert !asset.getAttribute("nightSceneEnabled" + it.name()).get().getValueAsBoolean().get()
}
}
@@ -111,13 +106,13 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
then: "vacation mode is off and scene timers are enabled"
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert !asset.getAttribute("vacationUntil").orElse(null).getValue().isPresent()
- assert asset.getAttribute("sceneTimerEnabled").orElse(null).getValueAsBoolean().orElse(null)
+ assert !asset.getAttribute("vacationUntil").get().getValue().isPresent()
+ assert asset.getAttribute("sceneTimerEnabled").get().getValueAsBoolean().get()
DayOfWeek.values().each {
- assert asset.getAttribute("homeSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("awaySceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("eveningSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
- assert asset.getAttribute("nightSceneEnabled" + it.name()).orElse(null).getValueAsBoolean().orElse(null)
+ assert asset.getAttribute("homeSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert asset.getAttribute("awaySceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert asset.getAttribute("eveningSceneEnabled" + it.name()).get().getValueAsBoolean().get()
+ assert asset.getAttribute("nightSceneEnabled" + it.name()).get().getValueAsBoolean().get()
}
}