use of org.keycloak.testsuite.util.RoleBuilder in project keycloak by keycloak.
the class CompositeRoleTest method before.
@Before
public void before() {
if (testContext.isInitialized()) {
return;
}
// addScopeMappings
addRealmLevelScopeMapping("REALM_COMPOSITE_1_APPLICATION", "REALM_COMPOSITE_1");
addRealmLevelScopeMapping("REALM_ROLE_1_APPLICATION", "REALM_ROLE_1");
addClientLevelScopeMapping("APP_COMPOSITE_APPLICATION", "APP_ROLE_APPLICATION", "APP_ROLE_2");
// createRealmAppCompositeRole
ClientResource appRoleApplication = ApiUtil.findClientByClientId(testRealm(), "APP_ROLE_APPLICATION");
RoleResource appRole1 = appRoleApplication.roles().get("APP_ROLE_1");
RoleBuilder realmAppCompositeRole = RoleBuilder.create().name("REALM_APP_COMPOSITE_ROLE");
testRealm().roles().create(realmAppCompositeRole.build());
String id = testRealm().roles().get("REALM_APP_COMPOSITE_ROLE").toRepresentation().getId();
testRealm().rolesById().addComposites(id, Collections.singletonList(appRole1.toRepresentation()));
// addRealmAppCompositeToUsers
UserResource userRsc = ApiUtil.findUserByUsernameId(testRealm(), "REALM_APP_COMPOSITE_USER");
RoleRepresentation realmAppCompositeRolee = testRealm().roles().get("REALM_APP_COMPOSITE_ROLE").toRepresentation();
userRsc.roles().realmLevel().add(Collections.singletonList(realmAppCompositeRolee));
// addRealmAppCompositeToUsers2
userRsc = ApiUtil.findUserByUsernameId(testRealm(), "APP_COMPOSITE_USER");
userRsc.roles().realmLevel().add(Collections.singletonList(realmAppCompositeRolee));
ClientResource appCompositeApplication = ApiUtil.findClientByClientId(testRealm(), "APP_COMPOSITE_APPLICATION");
RoleResource appCompositeRole = appCompositeApplication.roles().get("APP_COMPOSITE_ROLE");
// addCompositeRolesToAppCompositeRoleInAppCompositeApplication
List<RoleRepresentation> toAdd = new LinkedList<>();
toAdd.add(testRealm().roles().get("REALM_ROLE_1").toRepresentation());
toAdd.add(testRealm().roles().get("REALM_ROLE_2").toRepresentation());
toAdd.add(testRealm().roles().get("REALM_ROLE_3").toRepresentation());
ClientResource appRolesApplication = ApiUtil.findClientByClientId(testRealm(), "APP_ROLE_APPLICATION");
RoleRepresentation appRole1Rep = appRolesApplication.roles().get("APP_ROLE_1").toRepresentation();
toAdd.add(appRole1Rep);
appCompositeRole.addComposites(toAdd);
// Track that we initialized model already
testContext.setInitialized(true);
}
Aggregations