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
More hacking on CCS, still nothing working...
Christian Bauer9ed42d366bd3
diff --git a/base/mysql/scripts/10_CreateLegacyBeehiveSchema.sql b/base/mysql/scripts/10_CreateBeehiveSchema.sqlsimilarity index 100%rename from base/mysql/scripts/10_CreateLegacyBeehiveSchema.sqlrename to base/mysql/scripts/10_CreateBeehiveSchema.sqldiff --git a/base/mysql/scripts/11_CreateLegacyBeehiveDefaultData.sql b/base/mysql/scripts/11_CreateBeehiveDefaultData.sqlsimilarity index 100%rename from base/mysql/scripts/11_CreateLegacyBeehiveDefaultData.sqlrename to base/mysql/scripts/11_CreateBeehiveDefaultData.sqldiff --git a/base/tomcat/Dockerfile b/base/tomcat/Dockerfileindex 734403c30..d1a5aceec 100644--- a/base/tomcat/Dockerfile+++ b/base/tomcat/Dockerfile@@ -3,9 +3,6 @@ FROM tomcat:7.0.73-jre8# Remove default webappsRUN rm -rf /usr/local/tomcat/webapps/*-# Create certificate-RUN keytool -genkey -noprompt -genkey -keyalg RSA -alias selfsigned -keystore keystore.ks -storepass storepass -validity 360 -keysize 2048 -dname "CN=localhost, OU=localhost, O=localhost, L=, S=, C=" -keypass 'secret'-ADD conf/server_tpl.xml conf/ADD lib/* lib/ADD run.sh ./diff --git a/base/tomcat/conf/server_tpl.xml b/base/tomcat/conf/server_tpl.xmlindex 09a6fad53..6fbd23ca7 100644--- a/base/tomcat/conf/server_tpl.xml+++ b/base/tomcat/conf/server_tpl.xml@@ -132,7 +132,7 @@<Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/><Realm className="org.openremote.tomcat.realm.LegacyBeehiveDataSourceRealm"- dataSourceName="jdbc/AuthDB" digest="md5"+ dataSourceName="jdbc/AuthDB" digest="md5" debug="99"userTable="user" userNameCol="username" userCredCol="password"userRoleTable="tomcat_user_role" roleNameCol="rolename"/></Realm>diff --git a/beehive/ccs/conf/logging.properties b/beehive/ccs/conf/logging.propertiesindex 8114e56e3..4e2634e70 100644--- a/beehive/ccs/conf/logging.properties+++ b/beehive/ccs/conf/logging.properties@@ -3,3 +3,8 @@ handlers = java.util.logging.ConsoleHandler.level = INFOorg.openremote.level = INFOorg.hibernate.level = INFO++org.apache.catalina.realm.level = ALL+org.apache.catalina.realm.useParentHandlers = true+org.apache.catalina.authenticator.level = ALL+org.apache.catalina.authenticator.useParentHandlers = truediff --git a/beehive/ccs/src/main/java/org/openremote/controllercommand/ControllerProxyAndCommandServiceApplication.java b/beehive/ccs/src/main/java/org/openremote/controllercommand/ControllerProxyAndCommandServiceApplication.javaindex 22d0a09e0..1c926e38f 100644--- a/beehive/ccs/src/main/java/org/openremote/controllercommand/ControllerProxyAndCommandServiceApplication.java+++ b/beehive/ccs/src/main/java/org/openremote/controllercommand/ControllerProxyAndCommandServiceApplication.java@@ -51,7 +51,7 @@ import java.util.Properties;public class ControllerProxyAndCommandServiceApplication extends ResourceConfig {static private EntityManagerFactory entityManagerFactory;- protected final static Logger persistenceLog = LoggerFactory.getLogger(ControllerProxyAndCommandServiceApplication.class);+ protected final static Logger LOG = LoggerFactory.getLogger(ControllerProxyAndCommandServiceApplication.class);public ControllerProxyAndCommandServiceApplication() {@@ -66,9 +66,13 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigentityManagerFactory = Persistence.createEntityManagerFactory(config.getProperty("persistenceUnitName", "CCS-MySQL"));// TODO THis is never called, no idea why....if (config.getProperty("persistenceCreateSchema", "false").equals("true")) {+ LOG.info("### Creating database schema");createSchema();+ } else {+ LOG.info("### Not creating database schema");}- persistenceLog.info("EntityManagerFactory has been created");++ LOG.info("EntityManagerFactory has been created");register(EntityPersistence.class);GenericDAO genericDAO = new GenericDAO();@@ -82,7 +86,7 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigInteger proxyPort = getIntegerConfiguration(config, "proxy.port", 10000);String proxyClientPortRange = config.getProperty("proxy.clientPortRange", "30000-30010");Boolean useSSL = getBooleanConfiguration(config, "proxy.useSSL", true);- String keystore = config.getProperty("proxy.keystore", "keystore.ks");+ String keystore = config.getProperty("proxy.keystore", "keystore.jks");String keystorePassword = config.getProperty("proxy.keystorePassword", "storepass");ProxyServer ps = new ProxyServer(proxyHostname, proxyTimeout, proxyPort, proxyClientPortRange, useSSL, keystore, keystorePassword, controllerCommandService, accountService, this);ps.start();@@ -103,9 +107,9 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigprivate void testDestroy() {try {entityManagerFactory.close();- persistenceLog.info("EntityManagerFactory has been closed");+ LOG.info("EntityManagerFactory has been closed");} catch (Exception e) {- persistenceLog.warn("Could not close EntityManagerFactory");+ LOG.warn("Could not close EntityManagerFactory");}}@@ -138,41 +142,41 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfig}public EntityManager createEntityManager() {- persistenceLog.trace(">>createEntityManager");+ LOG.trace(">>createEntityManager");EntityManager entityManager = null;try {- persistenceLog.trace("Before createEntityManager");+ LOG.trace("Before createEntityManager");entityManager = entityManagerFactory.createEntityManager();- persistenceLog.debug("Got entityManager " + entityManager);+ LOG.debug("Got entityManager " + entityManager);EntityTransaction tx = entityManager.getTransaction();- persistenceLog.debug("Got transaction " + tx);+ LOG.debug("Got transaction " + tx);tx.begin();- persistenceLog.debug("Begun transaction");+ LOG.debug("Begun transaction");} catch (Exception e) {- persistenceLog.error("Failed to create an EntityManager", e);+ LOG.error("Failed to create an EntityManager", e);}- persistenceLog.trace("<<createEntityManager");+ LOG.trace("<<createEntityManager");return entityManager;}public void commitEntityManager(EntityManager entityManager) {- persistenceLog.trace(">>commitEntityManager");+ LOG.trace(">>commitEntityManager");if (entityManager.isOpen()) {- persistenceLog.debug("entityManager opened, commit transaction");+ LOG.debug("entityManager opened, commit transaction");entityManager.getTransaction().commit();entityManager.close();}- persistenceLog.trace("<<commitEntityManager");+ LOG.trace("<<commitEntityManager");}public void rollbackEntityManager(EntityManager entityManager) {- persistenceLog.trace(">>rollbackEntityManager");+ LOG.trace(">>rollbackEntityManager");if (entityManager.isOpen()) {- persistenceLog.debug("entityManager opened, rollback transaction");+ LOG.debug("entityManager opened, rollback transaction");entityManager.getTransaction().rollback();entityManager.close();}- persistenceLog.trace("<<rollbackEntityManager");+ LOG.trace("<<rollbackEntityManager");}/**@@ -197,7 +201,7 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigentityManager.getTransaction().begin();} catch (Throwable throwable) {- persistenceLog.error("Failed to create EntityManager", throwable);+ LOG.error("Failed to create EntityManager", throwable);if (entityManager != null) {EntityTransaction tx = entityManager.getTransaction();@@ -205,7 +209,7 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigtry {tx.rollback();} catch (Exception e) {- persistenceLog.warn("Failed to rollback transaction ", e);+ LOG.warn("Failed to rollback transaction ", e);}}}@@ -226,22 +230,22 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigEntityTransaction tx = entityManager.getTransaction();- persistenceLog.debug("Transaction is " + tx + " , active ? " + (tx.isActive() ? "yes" : "no"));+ LOG.debug("Transaction is " + tx + " , active ? " + (tx.isActive() ? "yes" : "no"));if (tx != null && tx.isActive()) {if (tx.getRollbackOnly() || response.getStatus() >= 400) {- persistenceLog.debug("Rolling back transaction");+ LOG.debug("Rolling back transaction");try {tx.rollback();} catch (Exception e) {- persistenceLog.warn("Failed to rollback transaction ", e);+ LOG.warn("Failed to rollback transaction ", e);}} else {- persistenceLog.debug("Commit transaction");+ LOG.debug("Commit transaction");try {tx.commit();} catch (Exception e) {- persistenceLog.error("Failed to commit transaction ", e);+ LOG.error("Failed to commit transaction ", e);}}}@@ -249,7 +253,7 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigtry {entityManager.close();} catch (Exception e) {- persistenceLog.warn("Failed to closed EntityManager", e);+ LOG.warn("Failed to closed EntityManager", e);}}}@@ -267,11 +271,11 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfigrs = meta.getTables(null, null, "controller", new String[]{"TABLE"});if (!rs.next()) {rs.close();- persistenceLog.warn("NO DATABASE SCHEMA FOUND, ATTEMPTING TO CREATE DATABASE SCHEMA...");+ LOG.info("Table CONTROLLER not found, attempting to create database schema");MultipleLinesSqlCommandExtractor extractor = new MultipleLinesSqlCommandExtractor();String[] sqlCommands = extractor.extractCommands(new BufferedReader(new InputStreamReader(- getClass().getClassLoader().getResourceAsStream("sql/CreateTables.sql"))+ getClass().getClassLoader().getResourceAsStream("sql/10-CreateSchema.sql"))));for (String sqlCommand : sqlCommands) {@@ -285,6 +289,8 @@ public class ControllerProxyAndCommandServiceApplication extends ResourceConfig}}}+ } else {+ LOG.info("Table CONTROLLER found in database schema, not creating schema");}} finally {if (rs != null)diff --git a/beehive/ccs/src/main/resources/CreateTables.sql b/beehive/ccs/src/main/resources/10-CreateSchema.sqlsimilarity index 100%rename from beehive/ccs/src/main/resources/CreateTables.sqlrename to beehive/ccs/src/main/resources/10-CreateSchema.sqldiff --git a/beehive/ccs/src/main/resources/META-INF/persistence.xml b/beehive/ccs/src/main/resources/META-INF/persistence.xmlindex be9d6c060..c990a20f6 100644--- a/beehive/ccs/src/main/resources/META-INF/persistence.xml+++ b/beehive/ccs/src/main/resources/META-INF/persistence.xml@@ -43,12 +43,12 @@<property name="javax.persistence.jdbc.url"value="jdbc:mysql://mysql:3306/openremote?useUnicode=true&characterEncoding=UTF-8&useSSL=false"/>+ <!-- TODO Use environment variables --><property name="javax.persistence.jdbc.user" value="openremote"/><property name="javax.persistence.jdbc.password" value="CHANGE_ME_DB_USER_PASSWORD"/><property name="hibernate.cache.provider_class" value="org.hibernate.cache.internal.NoCacheProvider"/><property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>- <property name="hibernate.hbm2ddl.auto" value="validate"/><property name="hibernate.current_session_context_class" value="managed"/><property name="hibernate.connection.provider_class"diff --git a/beehive/ccs/src/main/resources/config.properties b/beehive/ccs/src/main/resources/config.propertiesindex 181eabe51..f14c0e2d2 100644--- a/beehive/ccs/src/main/resources/config.properties+++ b/beehive/ccs/src/main/resources/config.properties@@ -6,5 +6,5 @@ proxy.timeout=10000proxy.port=10000proxy.clientPortRange=30000-30010proxy.useSSL=true-proxy.keystore=/keystore.ks+proxy.keystore=/keystore.jksproxy.keystorePassword=storepassdiff --git a/beehive/ccs/src/main/webapp/WEB-INF/web.xml b/beehive/ccs/src/main/webapp/WEB-INF/web.xmlindex a116cad08..37ff4e8eb 100644--- a/beehive/ccs/src/main/webapp/WEB-INF/web.xml+++ b/beehive/ccs/src/main/webapp/WEB-INF/web.xml@@ -88,7 +88,8 @@<!-- User roles required to access CCS resources... --><auth-constraint>- <role-name>ROLE_ADMIN</role-name>+ <role-name>service-admin</role-name>+ <role-name>account-owner</role-name></auth-constraint></security-constraint>@@ -98,19 +99,21 @@<login-config><auth-method>BASIC</auth-method>- <realm-name>ControllerProxyAndCommandService</realm-name>+ <realm-name>Restricted Service</realm-name></login-config><!-- Define the security roles... -->-<security-role>-<description>- ROLE_ADMIN is the administrator role for a specific account (it's the account owner).+ The user who owns an account</description>-- <role-name>ROLE_ADMIN</role-name>-+ <role-name>account-owner</role-name>+ </security-role>+ <security-role>+ <description>+ The service administrator+ </description>+ <role-name>service-admin</role-name></security-role></web-app>