Skip to content

armgit / core

Public Imported from GitHub
0

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

Basic identity provider updates

Rich Turner946ea59b2e33
diff --git a/container/src/main/resources/org/openremote/container/persistence/schema/basicidentityprovider/V20171031_02__BasicIdentityProvider.sql b/container/src/main/resources/org/openremote/container/persistence/schema/basicidentityprovider/V20191202_00__BasicIdentityProvider.sql
similarity index 100%
rename from container/src/main/resources/org/openremote/container/persistence/schema/basicidentityprovider/V20171031_02__BasicIdentityProvider.sql
rename to container/src/main/resources/org/openremote/container/persistence/schema/basicidentityprovider/V20191202_00__BasicIdentityProvider.sql
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
index e96ab9e3f..227a3f7bd 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
@@ -40,6 +40,7 @@ import java.util.UUID;
import java.util.logging.Logger;
import static org.openremote.model.Constants.MASTER_REALM;
+import static org.openremote.model.Constants.MASTER_REALM_ADMIN_USER;
public class ManagerBasicIdentityProvider extends BasicIdentityProvider implements ManagerIdentityProvider {
@@ -61,10 +62,21 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
if (!tenantExists(MASTER_REALM)) {
LOG.info("Creating master tenant and admin user");
- createTenant(null, new Tenant(MASTER_REALM, MASTER_REALM, "Master", true));
+ // Configure the master realm
+ persistenceService.doTransaction(em -> em.unwrap(Session.class).doWork(connection -> {
+ String sql = "insert into PUBLIC.REALM(ID, NAME, ENABLED) values ('master', 'master', true)";
+ PreparedStatement st = connection.prepareStatement(sql);
+ st.executeUpdate();
+ st.close();
+
+ sql = "insert into PUBLIC.REALM_ATTRIBUTE(REALM_ID, NAME, VALUE) values ('master', 'displayName', 'Master')";
+ st = connection.prepareStatement(sql);
+ st.executeUpdate();
+ st.close();
+ }));
+
User adminUser = new User();
- adminUser.setFirstName("Admin");
- adminUser.setLastName("User");
+ adminUser.setUsername(MASTER_REALM_ADMIN_USER);
createUser(null, MASTER_REALM, adminUser, adminPassword);
}
}
@@ -130,7 +142,6 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
st.executeUpdate();
}
}));
- persistenceService.doTransaction(em -> em.merge(user));
}
@Override
@@ -190,7 +201,7 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
@Override
public void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant) {
- throw new UnsupportedOperationException("This provider does not support multiple tenants");
+ throw new UnsupportedOperationException("This provider does not support modifying tenants");
}
@Override
@@ -220,7 +231,7 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
@Override
public boolean tenantExists(String realm) {
- return Objects.equals(realm, MASTER_REALM);
+ return ManagerIdentityProvider.tenantExistsFromDb(persistenceService, realm);
}
@Override
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityInitSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityInitSetup.java
deleted file mode 100644
index 3b59e0c8b..000000000
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityInitSetup.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.setup.builtin;
-
-import org.hibernate.Session;
-import org.openremote.container.Container;
-import org.openremote.manager.persistence.ManagerPersistenceService;
-import org.openremote.manager.setup.Setup;
-
-import java.sql.PreparedStatement;
-
-public class BasicIdentityInitSetup implements Setup {
-
- final protected ManagerPersistenceService persistenceService;
-
- public BasicIdentityInitSetup(Container container) {
- this.persistenceService = container.getService(ManagerPersistenceService.class);
- }
-
- @Override
- public void onStart() {
- // Configure the master realm
- persistenceService.doTransaction(em -> em.unwrap(Session.class).doWork(connection -> {
- String sql = "insert into PUBLIC.REALM(ID, NAME, ENABLED) values ('master', 'master', true)";
- PreparedStatement st = connection.prepareStatement(sql);
- st.executeUpdate();
- st.close();
-
- sql = "insert into PUBLIC.REALM_ATTRIBUTE(REALM_ID, NAME, VALUE) values ('master', 'displayName', 'Master')";
- st = connection.prepareStatement(sql);
- st.executeUpdate();
- st.close();
- }));
- }
-}
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/BuiltinSetupTasks.java b/manager/src/main/java/org/openremote/manager/setup/builtin/BuiltinSetupTasks.java
index d8c65739c..2fff3b68b 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/BuiltinSetupTasks.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/BuiltinSetupTasks.java
@@ -54,8 +54,6 @@ public class BuiltinSetupTasks extends AbstractSetupTasks {
if (isImportDemoAgent(container)) {
addTask(new ManagerDemoAgentSetup(container));
}
- } else {
- addTask(new BasicIdentityInitSetup(container));
}
return getTasks();