Search in sources :

Example 6 with SynchronizeAllUsersRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.

the class AltusMachineUserServiceTest method testDeleteMachineUserForEnvironment.

@Test
void testDeleteMachineUserForEnvironment() {
    MachineUser machineUserMock = mock(MachineUser.class);
    RegionAwareInternalCrnGenerator regionAwareInternalCrnGenerator = mock(RegionAwareInternalCrnGenerator.class);
    when(machineUserMock.getCrn()).thenReturn(autoscaleMachineUserCrn);
    when(machineUserMock.getWorkloadUsername()).thenReturn("workloadUserName");
    when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(internalActorCrn);
    when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(eq(autoscaleMachineUserName), eq("testTenant"), any(Optional.class))).thenReturn(machineUserMock);
    when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
    underTest.deleteMachineUserForEnvironment(testAccountId, autoscaleMachineUserCrn, testEnvironmentCrn);
    verify(grpcUmsClient, times(1)).deleteMachineUser(eq(autoscaleMachineUserCrn), eq(internalActorCrn), eq(testAccountId), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
    ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
    verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
    SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
    Assertions.assertEquals(synchronizeAllUsersRequest.getDeletedWorkloadUsers(), Set.of("workloadUserName"), "WorkloadUserName Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), testAccountId, "Account Id Should match");
}
Also used : RegionAwareInternalCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator) Optional(java.util.Optional) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 7 with SynchronizeAllUsersRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.

the class AltusMachineUserServiceTest method testInitializeMachineUserForEnvironment.

@Test
void testInitializeMachineUserForEnvironment() {
    Cluster cluster = getACluster();
    MachineUser machineUser = mock(MachineUser.class);
    when(machineUser.getCrn()).thenReturn(autoscaleMachineUserCrn);
    when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(autoscaleMachineUserName, testAccountId, MDCUtils.getRequestId())).thenReturn(machineUser);
    when(grpcUmsClient.listAssignedResourceRoles(anyString(), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class))).thenReturn(LinkedHashMultimap.create());
    when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
    when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
    underTest.initializeMachineUserForEnvironment(cluster);
    verify(grpcUmsClient, times(1)).assignResourceRole(eq(autoscaleMachineUserCrn), eq(testEnvironmentCrn), eq(environmentRoleCrn), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
    verify(clusterService, times(1)).setMachineUserCrn(cluster.getId(), autoscaleMachineUserCrn);
    ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
    verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
    SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
    Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), cluster.getClusterPertain().getTenant(), "Account Id Should match");
}
Also used : Optional(java.util.Optional) Cluster(com.sequenceiq.periscope.domain.Cluster) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 8 with SynchronizeAllUsersRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.

the class AltusMachineUserServiceTest method testinitializeMachineUserForEnvironmentWhenRoleAlreadyAssigned.

@Test
void testinitializeMachineUserForEnvironmentWhenRoleAlreadyAssigned() {
    Cluster cluster = getACluster();
    MachineUser machineUser = mock(MachineUser.class);
    LinkedHashMultimap rolesMap = LinkedHashMultimap.create();
    rolesMap.put(cluster.getEnvironmentCrn(), environmentRoleCrn);
    when(grpcUmsClient.getOrCreateMachineUserWithoutAccessKey(autoscaleMachineUserName, testAccountId, MDCUtils.getRequestId())).thenReturn(machineUser);
    when(machineUser.getCrn()).thenReturn(autoscaleMachineUserCrn);
    when(grpcUmsClient.listAssignedResourceRoles(anyString(), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class))).thenReturn(rolesMap);
    when(roleCrnGenerator.getBuiltInEnvironmentUserResourceRoleCrn(anyString())).thenReturn(environmentRoleCrn);
    when(freeIpaCommunicator.synchronizeAllUsers(any(SynchronizeAllUsersRequest.class))).thenReturn(getSyncOpStatus(SynchronizationStatus.COMPLETED));
    underTest.initializeMachineUserForEnvironment(cluster);
    verify(grpcUmsClient, times(0)).assignResourceRole(eq(autoscaleMachineUserCrn), eq(testEnvironmentCrn), eq(environmentRoleCrn), any(Optional.class), any(RegionAwareInternalCrnGeneratorFactory.class));
    verify(clusterService, times(1)).setMachineUserCrn(cluster.getId(), autoscaleMachineUserCrn);
    ArgumentCaptor<SynchronizeAllUsersRequest> synchronizeUserCaptor = ArgumentCaptor.forClass(SynchronizeAllUsersRequest.class);
    verify(freeIpaCommunicator, times(1)).synchronizeAllUsers(synchronizeUserCaptor.capture());
    SynchronizeAllUsersRequest synchronizeAllUsersRequest = synchronizeUserCaptor.getValue();
    Assertions.assertEquals(synchronizeAllUsersRequest.getEnvironments(), Set.of(testEnvironmentCrn), "Environment Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getMachineUsers(), Set.of(autoscaleMachineUserCrn), "Machine User Crn Should match");
    Assertions.assertEquals(synchronizeAllUsersRequest.getAccountId(), cluster.getClusterPertain().getTenant(), "Account Id Should match");
}
Also used : LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Optional(java.util.Optional) Cluster(com.sequenceiq.periscope.domain.Cluster) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 9 with SynchronizeAllUsersRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.

the class AltusMachineUserService method syncEnvironment.

private void syncEnvironment(String accountId, String machineUserCrn, String environmentCrn, Optional<String> deletedWorkloadUserName) {
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setAccountId(accountId);
    request.setEnvironments(Set.of(environmentCrn));
    request.setMachineUsers(Set.of(machineUserCrn));
    deletedWorkloadUserName.ifPresent(s -> request.setDeletedWorkloadUsers(Set.of(s)));
    SyncOperationStatus statusResponse = freeIpaCommunicator.synchronizeAllUsers(request);
    LOGGER.info("Finished invoking freeIpa user Sync with operation: {}, for environmentCrn: {} and machineUserCrn: {}", statusResponse.getOperationId(), environmentCrn, machineUserCrn);
}
Also used : SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)

Example 10 with SynchronizeAllUsersRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeAllUsers.

@Test
void synchronizeAllUsers() {
    Set<String> environments = Set.of(ENV_CRN);
    Set<String> users = Set.of(USER_CRN);
    Set<String> machineUsers = Set.of(MACHINE_USER_CRN);
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setEnvironments(environments);
    request.setUsers(users);
    request.setMachineUsers(machineUsers);
    request.setWorkloadCredentialsUpdateType(WorkloadCredentialsUpdateType.FORCE_UPDATE);
    Operation operation = mock(Operation.class);
    when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeAllUsers(request)));
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, machineUsers, Optional.empty());
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.FORCE_UPDATE, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)12 Test (org.junit.jupiter.api.Test)10 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)8 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)5 Operation (com.sequenceiq.freeipa.entity.Operation)5 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)5 MachineUser (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser)3 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)3 Optional (java.util.Optional)3 Cluster (com.sequenceiq.periscope.domain.Cluster)2 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 RegionAwareInternalCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Retryable (org.springframework.retry.annotation.Retryable)1