Search in sources :

Example 1 with MASTER_REALM

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));
}
Also used : Tenant(org.openremote.model.security.Tenant) User(org.openremote.model.security.User) Arrays(java.util.Arrays) UniqueIdentifierGenerator(org.openremote.container.util.UniqueIdentifierGenerator) ClientRole(org.openremote.model.security.ClientRole) Stream(java.util.stream.Stream) AbstractKeycloakSetup(org.openremote.manager.setup.AbstractKeycloakSetup) MASTER_REALM(org.openremote.model.Constants.MASTER_REALM) Constants(org.openremote.model.Constants) Logger(java.util.logging.Logger) Container(org.openremote.model.Container) User(org.openremote.model.security.User) ClientRole(org.openremote.model.security.ClientRole)

Aggregations

Arrays (java.util.Arrays)1 Logger (java.util.logging.Logger)1 Stream (java.util.stream.Stream)1 UniqueIdentifierGenerator (org.openremote.container.util.UniqueIdentifierGenerator)1 AbstractKeycloakSetup (org.openremote.manager.setup.AbstractKeycloakSetup)1 Constants (org.openremote.model.Constants)1 MASTER_REALM (org.openremote.model.Constants.MASTER_REALM)1 Container (org.openremote.model.Container)1 ClientRole (org.openremote.model.security.ClientRole)1 Tenant (org.openremote.model.security.Tenant)1 User (org.openremote.model.security.User)1