use of org.openremote.model.Constants.MASTER_REALM in project openremote by openremote.
the class KeycloakTestSetup method onStart.
@Override
public void onStart() throws Exception {
super.onStart();
// Tenants
masterTenant = identityService.getIdentityProvider().getTenant(Constants.MASTER_REALM);
tenantBuilding = createTenant("building", "Building", true);
tenantCity = createTenant("smartcity", "Smart City", true);
energyTenant = createTenant("energy", "Energy Test", true);
// Don't allow demo users to write assets
ClientRole[] demoUserRoles = Arrays.stream(REGULAR_USER_ROLES).filter(clientRole -> clientRole != ClientRole.WRITE_ASSETS).toArray(ClientRole[]::new);
// Users
User testuser1 = createUser(MASTER_REALM, "testuser1", "testuser1", "DemoMaster", "DemoLast", null, true, container.isDevMode() ? REGULAR_USER_ROLES : demoUserRoles);
this.testuser1Id = testuser1.getId();
// Remove all roles for account client
keycloakProvider.updateUserRoles(MASTER_REALM, testuser1Id, "account");
User testuser2 = createUser(tenantBuilding.getRealm(), "testuser2", "testuser2", "DemoA2", "DemoLast", "testuser2@openremote.local", true, false, true, new ClientRole[] { ClientRole.WRITE_USER, ClientRole.READ_MAP, ClientRole.READ_ASSETS });
this.testuser2Id = testuser2.getId();
// Remove all roles for account client
keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), testuser2Id, "account");
User testuser3 = createUser(tenantBuilding.getRealm(), "testuser3", "testuser3", "DemoA3", "DemoLast", "testuser3@openremote.local", true, true, false, container.isDevMode() ? REGULAR_USER_ROLES : demoUserRoles);
this.testuser3Id = testuser3.getId();
// Remove all roles for account client
keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), testuser3Id, "account");
User buildingUser = createUser(tenantBuilding.getRealm(), "building", "building", "Building", "User", "building@openremote.local", true, demoUserRoles);
this.buildingUserId = buildingUser.getId();
// Remove all roles for account client
keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), buildingUserId, "account");
User smartCityUser = createUser(tenantCity.getRealm(), "smartcity", "smartcity", "Smart", "City", null, true, demoUserRoles);
this.smartCityUserId = smartCityUser.getId();
// Remove all roles for account client
keycloakProvider.updateUserRoles(tenantCity.getRealm(), smartCityUserId, "account");
/*
* Service user client
*/
serviceUser = new User().setServiceAccount(true).setEnabled(true).setUsername("org/openremote/test");
serviceUser = keycloakProvider.createUpdateUser(tenantBuilding.getRealm(), serviceUser, UniqueIdentifierGenerator.generateId("serviceusertest"));
keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), serviceUser.getId(), serviceUser.getUsername(), Stream.of(ClientRole.READ_ASSETS, ClientRole.WRITE_ASSETS, ClientRole.WRITE_ATTRIBUTES).map(ClientRole::getValue).toArray(String[]::new));
}
Aggregations