100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Added Tenant Email Config
Rich Turnerf6b3b8afcc6e
diff --git a/manager/server/src/main/java/org/openremote/manager/server/security/ManagerIdentityService.java b/manager/server/src/main/java/org/openremote/manager/server/security/ManagerIdentityService.javaindex 17bcb04bf..732aab062 100644--- a/manager/server/src/main/java/org/openremote/manager/server/security/ManagerIdentityService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/security/ManagerIdentityService.java@@ -36,6 +36,7 @@ import org.openremote.container.security.KeycloakResource;import org.openremote.container.web.WebService;import org.openremote.manager.shared.security.ClientRole;import org.openremote.manager.shared.security.Tenant;+import org.openremote.manager.shared.security.TenantEmailConfig;import org.openremote.model.Constants;import javax.ws.rs.core.UriBuilder;@@ -159,9 +160,15 @@ public class ManagerIdentityService extends IdentityService {configureRealm(realmRepresentation, ACCESS_TOKEN_LIFESPAN_SECONDS);}+public void createTenant(String bearerAuth, Tenant tenant) throws Exception {+ createTenant(bearerAuth, tenant, null);+ }++ public void createTenant(String bearerAuth, Tenant tenant, TenantEmailConfig emailConfig) throws Exception {LOG.fine("Create tenant: " + tenant);RealmRepresentation realmRepresentation = convert(Container.JSON, RealmRepresentation.class, tenant);+ realmRepresentation.setSmtpServer(emailConfig.asMap());configureRealm(realmRepresentation);getRealms(bearerAuth).create(realmRepresentation);// TODO This is not atomic, write compensation actionsdiff --git a/manager/shared/src/main/java/org/openremote/manager/shared/security/Tenant.java b/manager/shared/src/main/java/org/openremote/manager/shared/security/Tenant.javaindex e8d6dccac..05e5a4cfd 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/security/Tenant.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/security/Tenant.java@@ -25,6 +25,7 @@ import org.hibernate.annotations.Subselect;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Id;+import javax.persistence.Transient;import javax.validation.constraints.NotNull;import javax.validation.constraints.Pattern;import javax.validation.constraints.Size;@@ -51,6 +52,13 @@ public class Tenant {@Column(name = "NOT_BEFORE")protected Integer notBefore; // This will explode in 2038+ // We allow password reset by default+ @Transient+ protected Boolean resetPasswordAllowed = true;++ @Transient+ protected Boolean duplicateEmailsAllowed;+public Tenant() {}@@ -106,6 +114,22 @@ public class Tenant {this.notBefore = notBefore;}+ public Boolean getResetPasswordAllowed() {+ return resetPasswordAllowed;+ }++ public void setResetPasswordAllowed(Boolean resetPasswordAllowed) {+ this.resetPasswordAllowed = resetPasswordAllowed;+ }++ public Boolean getDuplicateEmailsAllowed() {+ return duplicateEmailsAllowed;+ }++ public void setDuplicateEmailsAllowed(Boolean duplicateEmailsAllowed) {+ this.duplicateEmailsAllowed = duplicateEmailsAllowed;+ }+public boolean isActive() {return enabled != null && enabled&& (notBefore == null || notBefore == 0 || notBefore <= (System.currentTimeMillis()/1000));diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/security/TenantEmailConfig.java b/manager/shared/src/main/java/org/openremote/manager/shared/security/TenantEmailConfig.javanew file mode 100644index 000000000..9e27288e8--- /dev/null+++ b/manager/shared/src/main/java/org/openremote/manager/shared/security/TenantEmailConfig.java@@ -0,0 +1,100 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.manager.shared.security;++import com.fasterxml.jackson.annotation.JsonIgnoreProperties;+import com.fasterxml.jackson.annotation.JsonProperty;++import java.util.HashMap;+import java.util.Map;++@JsonIgnoreProperties({"password", "auth", "port", "host", "from", "user", "ssl", "starttls"})+public class TenantEmailConfig {+ @JsonProperty+ protected Map<String,String> settings = new HashMap<>();++ public Map<String,String> asMap() {+ return settings;+ }++ public void setPassword(String password) {+ settings.put("password", password);+ }++ public String getPassword() {+ return settings.get("password");+ }++ public Boolean isAuth() {+ return settings.containsKey("auth") ? Boolean.parseBoolean(settings.get("auth")) : null;+ }++ public void setAuth(boolean auth) {+ settings.put("auth", Boolean.toString(auth));+ }++ public Integer getPort() {+ return settings.containsKey("port") ? Integer.parseInt(settings.get("port")) : null;+ }++ public void setPort(int port) {+ settings.put("port", Integer.toString(port));+ }++ public String getHost() {+ return settings.get("host");+ }++ public void setHost(String host) {+ settings.put("host", host);+ }++ public String getFrom() {+ return settings.get("from");+ }++ public void setFrom(String from) {+ settings.put("from", from);+ }++ public String getUser() {+ return settings.get("user");+ }++ public void setUser(String user) {+ settings.put("user", user);+ }++ public Boolean isSsl() {+ return settings.containsKey("ssl") ? Boolean.parseBoolean(settings.get("ssl")) : null;+ }++ public void setSsl(boolean ssl) {+ settings.put("ssl", Boolean.toString(ssl));+ }++ public Boolean isStarttls() {+ return settings.containsKey("starttls") ? Boolean.parseBoolean(settings.get("starttls")) : null;+ }++ public void setStarttls(boolean starttls) {+ settings.put("starttls", Boolean.toString(starttls));+ }+}