Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ scmVersion {
}
}

buildscript {
repositories {
maven {
url = 'https://plugins.gradle.org/m2'
}
}
dependencies {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:8.8.0'
}
}

allprojects {
// Apply common project setup
apply from: "${project.rootDir}/project.gradle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* 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
Expand All @@ -15,38 +12,37 @@
* 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/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.extension.demosetup;

import java.util.Arrays;
import java.util.List;

import org.openremote.model.Container;
import org.openremote.model.setup.Setup;
import org.openremote.model.setup.SetupTasks;

import java.util.Arrays;
import java.util.List;

/**
* Demo setup tasks.
*/
/** Demo setup tasks. */
public class DemoSetupTasks implements SetupTasks {

public static final String DEMO_SETUP_TYPE = "demo";
public static final String DEMO_SETUP_TYPE = "demo";

@Override
public List<Setup> createTasks(Container container, String setupType, boolean keycloakEnabled) {
@Override
public List<Setup> createTasks(Container container, String setupType, boolean keycloakEnabled) {

if (DEMO_SETUP_TYPE.equals(setupType)) {
return Arrays.asList(
new KeycloakDemoSetup(container),
new ManagerDemoSetup(container),
new RulesDemoSetup(container),
new ManagerDemoAgentSetup(container),
new ManagerDemoDashboardSetup(container)
);
}

// Do nothing otherwise
return null;
if (DEMO_SETUP_TYPE.equals(setupType)) {
return Arrays.asList(
new KeycloakDemoSetup(container),
new ManagerDemoSetup(container),
new RulesDemoSetup(container),
new ManagerDemoAgentSetup(container),
new ManagerDemoDashboardSetup(container));
}

// Do nothing otherwise
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* Copyright 2020, 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
Expand All @@ -15,70 +12,110 @@
* 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/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.extension.demosetup;

import java.util.Arrays;
import java.util.logging.Logger;

import org.openremote.manager.setup.AbstractKeycloakSetup;
import org.openremote.model.Constants;
import org.openremote.model.Container;
import org.openremote.model.security.ClientRole;
import org.openremote.model.security.Realm;
import org.openremote.model.security.User;

import java.util.Arrays;
import java.util.logging.Logger;

/**
* We have the following demo users:
* <ul>
* <li><code>admin</code> - The superuser in the "master" realm with all access</li>
* <li><code>smartcity</code> - (Password: smartcity) A user in the "smartcity" realm with read access</li>
* <li><code>manufacturer</code> - (Password: manufacturer) A user in the "manufacturer" realm with read access</li>
* <li><code>manufacturer - customer</code> - (Password: customer) A user in the "manufacturer" realm with restricted access to his assets</li>
*
* <ul>
* <li><code>admin</code> - The superuser in the "master" realm with all access
* <li><code>smartcity</code> - (Password: smartcity) A user in the "smartcity" realm with read
* access
* <li><code>manufacturer</code> - (Password: manufacturer) A user in the "manufacturer" realm
* with read access
* <li><code>manufacturer - customer</code> - (Password: customer) A user in the "manufacturer"
* realm with restricted access to his assets
* </ul>
*/
public class KeycloakDemoSetup extends AbstractKeycloakSetup {

private static final Logger LOG = Logger.getLogger(KeycloakDemoSetup.class.getName());
private static final Logger LOG = Logger.getLogger(KeycloakDemoSetup.class.getName());

public String smartCityUserId;
public static String manufacturerUserId;
public static String customerUserId;
public Realm realmMaster;
public Realm realmCity;
public static Realm realmManufacturer;
public String smartCityUserId;
public static String manufacturerUserId;
public static String customerUserId;
public Realm realmMaster;
public Realm realmCity;
public static Realm realmManufacturer;

public KeycloakDemoSetup(Container container) {
super(container);
}
public KeycloakDemoSetup(Container container) {
super(container);
}

@Override
public void onStart() throws Exception {
super.onStart();
@Override
public void onStart() throws Exception {
super.onStart();

// Realms
realmMaster = identityService.getIdentityProvider().getRealm(Constants.MASTER_REALM);
realmCity = createRealm("smartcity", "Smart City", true);
realmManufacturer = createRealm("manufacturer", "Manufacturer", true);
removeManageAccount("smartcity");
removeManageAccount("manufacturer");
// Realms
realmMaster = identityService.getIdentityProvider().getRealm(Constants.MASTER_REALM);
realmCity = createRealm("smartcity", "Smart City", true);
realmManufacturer = createRealm("manufacturer", "Manufacturer", true);
removeManageAccount("smartcity");
removeManageAccount("manufacturer");

// Don't allow demo users to write assets
ClientRole[] demoUserRoles = Arrays.stream(AbstractKeycloakSetup.REGULAR_USER_ROLES)
// Don't allow demo users to write assets
ClientRole[] demoUserRoles =
Arrays.stream(AbstractKeycloakSetup.REGULAR_USER_ROLES)
.filter(clientRole -> clientRole != ClientRole.WRITE_ASSETS)
.toArray(ClientRole[]::new);

// Users
User smartCityUser = createUser(realmCity.getName(), "smartcity", "smartcity", "Smart", "City", null, true, demoUserRoles);
this.smartCityUserId = smartCityUser.getId();
keycloakProvider.updateUserClientRoles(realmCity.getName(), smartCityUserId, "account"); // Remove all roles for account client
User manufacturerUser = createUser(realmManufacturer.getName(), "manufacturer", "manufacturer", "Agri", "Tech", null, true, demoUserRoles);
manufacturerUserId = manufacturerUser.getId();
keycloakProvider.updateUserClientRoles(realmManufacturer.getName(), manufacturerUserId, "account"); // Remove all roles for account client
User customerUser = createUser(realmManufacturer.getName(), "customer", "customer", "Bert", "Frederiks", null, true, demoUserRoles);
customerUserId = customerUser.getId();
keycloakProvider.updateUserClientRoles(realmManufacturer.getName(), customerUserId, "account"); // Remove all roles for account client
}
// Users
User smartCityUser =
createUser(
realmCity.getName(),
"smartcity",
"smartcity",
"Smart",
"City",
null,
true,
demoUserRoles);
this.smartCityUserId = smartCityUser.getId();
keycloakProvider.updateUserClientRoles(
realmCity.getName(), smartCityUserId, "account"); // Remove all roles for account client
User manufacturerUser =
createUser(
realmManufacturer.getName(),
"manufacturer",
"manufacturer",
"Agri",
"Tech",
null,
true,
demoUserRoles);
manufacturerUserId = manufacturerUser.getId();
keycloakProvider.updateUserClientRoles(
realmManufacturer.getName(),
manufacturerUserId,
"account"); // Remove all roles for account client
User customerUser =
createUser(
realmManufacturer.getName(),
"customer",
"customer",
"Bert",
"Frederiks",
null,
true,
demoUserRoles);
customerUserId = customerUser.getId();
keycloakProvider.updateUserClientRoles(
realmManufacturer.getName(),
customerUserId,
"account"); // Remove all roles for account client
}
}
Loading