use of com.sequenceiq.it.cloudbreak.actor.CloudbreakUser in project cloudbreak by hortonworks.
the class AssignResourceRoleUserAction method umsAction.
@Override
protected UmsTestDto umsAction(TestContext testContext, UmsTestDto testDto, UmsClient client) throws Exception {
CloudbreakUser user = testContext.getRealUmsUserByKey(userKey);
String userCrn = user.getCrn();
String resourceRole = testDto.getRequest().getRoleCrn();
String resourceCrn = testDto.getRequest().getResourceCrn();
Log.when(LOGGER, format(" Assigning resource role '%s' to user '%s' at resource '%s'... ", resourceRole, userCrn, resourceCrn));
Log.whenJson(LOGGER, format(" Assign resource role request:%n "), testDto.getRequest());
LOGGER.info(format(" Assigning resource role '%s' to user '%s' at resource '%s'... ", resourceRole, userCrn, resourceCrn));
Multimap<String, String> assignedResourceRoles = client.getDefaultClient().listAssignedResourceRoles(userCrn, Optional.of(""), regionAwareInternalCrnGeneratorFactory);
if (assignedResourceRoles.get(resourceCrn).contains(resourceRole)) {
LOGGER.info(format(" Resource role '%s' has already been assigned to user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
Log.when(LOGGER, format(" Resource role '%s' has already been assigned to user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
} else {
client.getDefaultClient().assignResourceRole(userCrn, resourceCrn, resourceRole, Optional.of(""), regionAwareInternalCrnGeneratorFactory);
// wait for UmsRightsCache to expire
Thread.sleep(7000);
LOGGER.info(format(" Resource role '%s' has been assigned to user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
Log.when(LOGGER, format(" Resource role '%s' has been assigned to user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
}
return testDto;
}
use of com.sequenceiq.it.cloudbreak.actor.CloudbreakUser in project cloudbreak by hortonworks.
the class BasicEnvironmentVirtualGroupTest method testAddGroupsToEnvironment.
@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running Manowar Environment with synced FreeIPA", when = "add then remove admin and user groups to Environment", then = "FreeIPA should be successfully synced with new groups and theirs resource roles.")
public void testAddGroupsToEnvironment(TestContext testContext) {
AtomicReference<Map<UmsVirtualGroupRight, String>> environmentVirtualGroups = new AtomicReference<>();
CloudbreakUser userEnvAdminA = testContext.getRealUmsUserByKey(L0UserKeys.ENV_ADMIN_A);
CloudbreakUser userEnvCreatorB = testContext.getRealUmsUserByKey(L0UserKeys.ENV_CREATOR_B);
CloudbreakUser userEnvCreatorA = testContext.getRealUmsUserByKey(L0UserKeys.ENV_CREATOR_A);
useRealUmsUser(testContext, L0UserKeys.ENV_CREATOR_A);
testContext.given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).given(FreeIpaUserSyncTestDto.class).when(freeIpaTestClient.getLastSyncOperationStatus()).await(OperationState.COMPLETED).given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).validate();
testContext.given(UmsTestDto.class).assignTargetByCrn(adminGroupCrn).withGroupAdmin().when(umsTestClient.assignResourceRole(L0UserKeys.ENV_CREATOR_A, regionAwareInternalCrnGeneratorFactory)).then(ResourceRoleTestAssertion.validateAssignedResourceRole(userEnvCreatorA, getIamGroupAdminCrn(), true, regionAwareInternalCrnGeneratorFactory)).assignTargetByCrn(userGroupCrn).withGroupAdmin().when(umsTestClient.assignResourceRole(L0UserKeys.ENV_CREATOR_A, regionAwareInternalCrnGeneratorFactory)).then(ResourceRoleTestAssertion.validateAssignedResourceRole(userEnvCreatorA, getIamGroupAdminCrn(), true, regionAwareInternalCrnGeneratorFactory)).given(UmsGroupTestDto.class).when(umsTestClient.addUserToGroup(adminGroupName, userEnvAdminA.getCrn(), regionAwareInternalCrnGeneratorFactory)).when(umsTestClient.addUserToGroup(userGroupName, userEnvCreatorB.getCrn(), regionAwareInternalCrnGeneratorFactory)).then(UserGroupTestAssertion.validateUserGroupMembership(userEnvAdminA, adminGroupName, true, regionAwareInternalCrnGeneratorFactory)).then(UserGroupTestAssertion.validateUserGroupMembership(userEnvCreatorB, userGroupName, true, regionAwareInternalCrnGeneratorFactory)).validate();
testContext.given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).given(FreeIpaUserSyncTestDto.class).when(freeIpaTestClient.getLastSyncOperationStatus()).await(OperationState.COMPLETED).given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).withEnvironmentAdmin().when(umsTestClient.assignResourceRoleWithGroup(adminGroupCrn, regionAwareInternalCrnGeneratorFactory)).withEnvironmentUser().when(umsTestClient.assignResourceRoleWithGroup(userGroupCrn, regionAwareInternalCrnGeneratorFactory)).then((tc, dto, client) -> {
environmentVirtualGroups.set(environmentUtil.getEnvironmentVirtualGroups(tc, client));
return dto;
}).given(FreeIpaUserSyncTestDto.class).when(freeIpaTestClient.syncAll()).await(OperationState.COMPLETED).given(FreeIpaTestDto.class).when(freeIpaTestClient.findGroups(Set.of(adminGroupName, userGroupName))).then(VirtualGroupTestAssertion.validateAdminVirtualGroupMembership(freeIpaTestClient, environmentVirtualGroups.get(), Set.of(userEnvAdminA.getWorkloadUserName()), true)).then(VirtualGroupTestAssertion.validateUserVirtualGroupMembership(freeIpaTestClient, environmentVirtualGroups.get(), Set.of(userEnvCreatorB.getWorkloadUserName()), true)).validate();
testContext.given(UmsGroupTestDto.class).when(umsTestClient.removeUserFromGroup(adminGroupName, userEnvAdminA.getCrn(), regionAwareInternalCrnGeneratorFactory)).when(umsTestClient.removeUserFromGroup(userGroupName, userEnvCreatorB.getCrn(), regionAwareInternalCrnGeneratorFactory)).then(UserGroupTestAssertion.validateUserGroupMembership(userEnvAdminA, adminGroupName, false, regionAwareInternalCrnGeneratorFactory)).then(UserGroupTestAssertion.validateUserGroupMembership(userEnvCreatorB, userGroupName, false, regionAwareInternalCrnGeneratorFactory)).validate();
testContext.given(UmsTestDto.class).assignTargetByCrn(adminGroupCrn).withGroupAdmin().when(umsTestClient.unAssignResourceRole(L0UserKeys.ENV_CREATOR_A, regionAwareInternalCrnGeneratorFactory)).then(ResourceRoleTestAssertion.validateAssignedResourceRole(userEnvCreatorA, getIamGroupAdminCrn(), false, regionAwareInternalCrnGeneratorFactory)).assignTargetByCrn(userGroupCrn).withGroupAdmin().when(umsTestClient.unAssignResourceRole(L0UserKeys.ENV_CREATOR_A, regionAwareInternalCrnGeneratorFactory)).then(ResourceRoleTestAssertion.validateAssignedResourceRole(userEnvCreatorA, getIamGroupAdminCrn(), false, regionAwareInternalCrnGeneratorFactory)).validate();
}
use of com.sequenceiq.it.cloudbreak.actor.CloudbreakUser in project cloudbreak by hortonworks.
the class TestContext method getRealUmsUserByKey.
/**
* Request a real UMS user by AuthUserKeys from the fetched ums-users/api-credentials.json
*
* @param userKey Key with UMS user's display name. Sample: AuthUserKeys.ACCOUNT_ADMIN
* @return Returns with the UMS user (CloudbreakUser)
*/
public CloudbreakUser getRealUmsUserByKey(String userKey) {
CloudbreakUser requestedRealUmsUser;
if (actingUser.getDisplayName().equalsIgnoreCase(userKey)) {
LOGGER.info(" Requested real UMS user is the same as acting user:: \nDisplay Name: {} \nAccess Key: {} \nSecret Key: {} \nCRN: {} \nAdmin: {}" + " \nDescription: {} ", actingUser.getDisplayName(), actingUser.getAccessKey(), actingUser.getSecretKey(), actingUser.getCrn(), actingUser.getAdmin(), actingUser.getDescription());
requestedRealUmsUser = actingUser;
} else {
requestedRealUmsUser = cloudbreakActor.useRealUmsUser(userKey);
LOGGER.info(" Found real UMS user:: \nDisplay Name: {} \nWorkload username: {} \nAccess Key: {} \nSecret Key: {} \nCRN: {} \nAdmin: {}" + " \nDescription: {} ", requestedRealUmsUser.getDisplayName(), requestedRealUmsUser.getWorkloadUserName(), requestedRealUmsUser.getAccessKey(), requestedRealUmsUser.getSecretKey(), requestedRealUmsUser.getCrn(), requestedRealUmsUser.getAdmin(), requestedRealUmsUser.getDescription());
}
return requestedRealUmsUser;
}
use of com.sequenceiq.it.cloudbreak.actor.CloudbreakUser in project cloudbreak by hortonworks.
the class UnassignResourceRoleAction method umsAction.
@Override
protected UmsTestDto umsAction(TestContext testContext, UmsTestDto testDto, UmsClient client) throws Exception {
CloudbreakUser user = testContext.getRealUmsUserByKey(userKey);
String userCrn = user.getCrn();
String resourceRole = testDto.getRequest().getRoleCrn();
String resourceCrn = testDto.getRequest().getResourceCrn();
Log.when(LOGGER, format(" Revoke resource role '%s' from user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
Log.whenJson(LOGGER, format(" Revoke resource role request:%n "), testDto.getRequest());
LOGGER.info(format(" Revoking resource role '%s' from user '%s' at resource '%s'... ", resourceRole, userCrn, resourceCrn));
Multimap<String, String> assignedResourceRoles = client.getDefaultClient().listAssignedResourceRoles(userCrn, Optional.of(""), regionAwareInternalCrnGeneratorFactory);
if (assignedResourceRoles.get(resourceCrn).contains(resourceRole)) {
client.getDefaultClient().unassignResourceRole(userCrn, resourceCrn, resourceRole, Optional.of(""), regionAwareInternalCrnGeneratorFactory);
// wait for UmsRightsCache to expire
Thread.sleep(7000);
LOGGER.info(format(" Resource role '%s' has been revoked from user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
Log.when(LOGGER, format(" Resource role '%s' has been revoked from user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
} else {
LOGGER.info(format(" Resource role '%s' has already been revoked from user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
Log.when(LOGGER, format(" Resource role '%s' has already been revoked from user '%s' at resource '%s' ", resourceRole, userCrn, resourceCrn));
}
return testDto;
}
use of com.sequenceiq.it.cloudbreak.actor.CloudbreakUser in project cloudbreak by hortonworks.
the class TestContext method getRealUmsAdmin.
/**
* Request the real UMS admin from the fetched ums-users json
*
* @return Returns with the UMS admin user (CloudbreakUser)
*/
public CloudbreakUser getRealUmsAdmin() {
String accountId = Objects.requireNonNull(Crn.fromString(actingUser.getCrn())).getAccountId();
CloudbreakUser adminUser = cloudbreakActor.getAdminByAccountId(accountId);
if (actingUser.getDisplayName().equalsIgnoreCase(adminUser.getDisplayName())) {
LOGGER.info(" Requested real UMS user is the same as acting user:: \nDisplay Name: {} \nAccess Key: {} \nSecret Key: {} \nCRN: {} \nAdmin: {}" + " \nDescription: {} ", actingUser.getDisplayName(), actingUser.getAccessKey(), actingUser.getSecretKey(), actingUser.getCrn(), actingUser.getAdmin(), actingUser.getDescription());
} else {
LOGGER.info(" Found real UMS admin user:: \nDisplay Name: {} \nWorkload username: {} \nAccess Key: {} \nSecret Key: {} \nCRN: {} \nAdmin: {}" + " \nDescription: {} ", adminUser.getDisplayName(), adminUser.getWorkloadUserName(), adminUser.getAccessKey(), adminUser.getSecretKey(), adminUser.getCrn(), adminUser.getAdmin(), adminUser.getDescription());
}
return adminUser;
}
Aggregations