Search in sources :

Example 36 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class FmsUserConverterTest method testUserSyncActorDetailsToFmsUserDeactivatedState.

@Test
public void testUserSyncActorDetailsToFmsUserDeactivatedState() {
    String workloadUsername = "foobar";
    UserManagementProto.UserSyncActorDetails actorDetails = UserManagementProto.UserSyncActorDetails.newBuilder().setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.DEACTIVATED).build();
    FmsUser fmsUser = underTest.toFmsUser(actorDetails);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.DISABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Example 37 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class FreeIpaUsersStateProviderTest method testGetUserState.

@Test
void testGetUserState() throws Exception {
    List<String> user1GroupNames = List.of("group1", "group2");
    List<String> user2GroupNames = List.of("group2", "group3", IPA_UNMANAGED_GROUPS.get(0));
    List<String> ipaOnlyUserGroupNames = List.of("dont_include");
    List<String> groupsWithoutMembers = List.of("group4");
    Map<String, Pair<List<String>, Optional<UserMetadata>>> users = Map.of("user1", Pair.of(user1GroupNames, Optional.empty()), "user2", Pair.of(user2GroupNames, Optional.of(new UserMetadata("user2-crn", 1L))), IPA_PROTECTED_USERS.get(0), Pair.of(ipaOnlyUserGroupNames, Optional.empty()));
    Set<com.sequenceiq.freeipa.client.model.User> usersFindAll = users.entrySet().stream().map(entry -> createIpaUser(entry.getKey(), entry.getValue().getLeft())).collect(Collectors.toSet());
    Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = Stream.of(user1GroupNames.stream(), user2GroupNames.stream(), groupsWithoutMembers.stream(), IPA_UNMANAGED_GROUPS.stream()).flatMap(groupName -> groupName).map(this::createIpaGroup).collect(Collectors.toSet());
    when(freeIpaClient.userFindAll()).thenReturn(usersFindAll);
    when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
    Set<String> expectedUsers = users.keySet().stream().filter(user -> !IPA_PROTECTED_USERS.contains(user)).collect(Collectors.toSet());
    Set<String> expectedGroups = groupsFindAll.stream().map(com.sequenceiq.freeipa.client.model.Group::getCn).filter(groupName -> !IPA_UNMANAGED_GROUPS.contains(groupName)).collect(Collectors.toSet());
    Map<String, UserMetadata> expectedUserMetadata = Maps.newHashMap();
    expectedUsers.forEach(username -> {
        Optional<UserMetadata> userMetadata = users.get(username).getRight();
        doReturn(userMetadata).when(userMetadataConverter).toUserMetadata(argThat(arg -> username.equals(arg.getUid())));
        userMetadata.ifPresent(meta -> expectedUserMetadata.put(username, meta));
    });
    UsersState ipaState = underTest.getUsersState(freeIpaClient);
    for (FmsUser fmsUser : ipaState.getUsers()) {
        assertTrue(expectedUsers.contains(fmsUser.getName()));
        expectedUsers.remove(fmsUser.getName());
    }
    assertTrue(expectedUsers.isEmpty());
    for (FmsGroup fmsGroup : ipaState.getGroups()) {
        assertTrue(expectedGroups.contains(fmsGroup.getName()));
        expectedGroups.remove(fmsGroup.getName());
    }
    assertTrue(expectedGroups.isEmpty());
    assertEquals(expectedUserMetadata, ipaState.getUserMetadataMap());
}
Also used : FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) IPA_UNMANAGED_GROUPS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UserMetadataConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.UserMetadataConverter) Mockito.doReturn(org.mockito.Mockito.doReturn) Stack(com.sequenceiq.freeipa.entity.Stack) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IPA_PROTECTED_USERS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Optional(java.util.Optional) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 38 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class UserSyncOperationsTest method testAddUsersSingle.

@Test
public void testAddUsersSingle() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    FmsUser user1 = new FmsUser().withName("user1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
    FmsUser user2 = new FmsUser().withName("user2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
    Set<FmsUser> users = Set.of(user1, user2);
    ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
    RPCResponse<Object> response1 = new RPCResponse<>();
    response1.setResult(new User());
    RPCResponse<Object> response2 = new RPCResponse<>();
    response2.setResult(new User());
    when(freeIpaClient.invoke(eq("user_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
    underTest.addUsers(false, freeIpaClient, users, warnings::put);
    assertTrue(warnings.isEmpty());
    verifyNoInteractions(batchPartitionSizeProperties);
    verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
    List<List<Object>> flagsList = flagsCaptor.getAllValues();
    assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
    List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
    assertThat(paramsList, everyItem(aMapWithSize(5)));
    assertThat(paramsList, allOf(Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_1"), hasEntry("sn", "Test1"))), Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_2"), hasEntry("sn", "Test2")))));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : User(com.sequenceiq.freeipa.client.model.User) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 39 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class UserSyncOperations method addUsers.

public void addUsers(boolean fmsToFreeipaBatchCallEnabled, FreeIpaClient freeIpaClient, Set<FmsUser> fmsUsers, BiConsumer<String, String> warnings) throws FreeIpaClientException, TimeoutException {
    List<UserAddOperation> operations = Lists.newArrayList();
    for (FmsUser fmsUser : fmsUsers) {
        threadInterruptChecker.throwTimeoutExIfInterrupted();
        operations.add(UserAddOperation.create(fmsUser.getName(), fmsUser.getFirstName(), fmsUser.getLastName(), fmsUser.getState() == FmsUser.State.DISABLED));
    }
    invokeOperation(operations, fmsToFreeipaBatchCallEnabled, freeIpaClient, warnings, Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY), true);
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserAddOperation(com.sequenceiq.freeipa.client.operation.UserAddOperation)

Example 40 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class DefaultUmsUsersStateProvider method addActorsToUmsUsersStateBuilder.

private void addActorsToUmsUsersStateBuilder(String accountId, EnvironmentAccessChecker environmentAccessChecker, List<UserManagementProto.User> users, List<UserManagementProto.MachineUser> machineUsers, ActorHandler actorHandler, Optional<String> requestIdOptional) {
    Streams.concat(users.stream().map(user -> Triple.of(user.getCrn(), fmsUserConverter.toFmsUser(user), user.getCloudIdentitiesList())), machineUsers.stream().map(machineUser -> Triple.of(machineUser.getCrn(), fmsUserConverter.toFmsUser(machineUser), machineUser.getCloudIdentitiesList()))).forEach(triple -> {
        String memberCrn = triple.getLeft();
        FmsUser fmsUser = triple.getMiddle();
        List<UserManagementProto.CloudIdentity> cloudIdentityList = triple.getRight();
        Supplier<Collection<String>> groupMembershipSupplier = () -> grpcUmsClient.listGroupsForMember(accountId, memberCrn, requestIdOptional, regionAwareInternalCrnGeneratorFactory);
        Supplier<Collection<String>> wagMembershipSupplier = () -> grpcUmsClient.listWorkloadAdministrationGroupsForMember(memberCrn, requestIdOptional, regionAwareInternalCrnGeneratorFactory);
        Supplier<WorkloadCredential> workloadCredentialSupplier = () -> umsCredentialProvider.getCredentials(memberCrn, requestIdOptional);
        try {
            actorHandler.handleActor(environmentAccessChecker.hasAccess(memberCrn, requestIdOptional), fmsUser, memberCrn, groupMembershipSupplier, wagMembershipSupplier, workloadCredentialSupplier, cloudIdentityList);
        } catch (StatusRuntimeException e) {
            // membership.
            if (e.getStatus().getCode() == Status.Code.NOT_FOUND) {
                LOGGER.warn("Member CRN {} not found in UMS. Member will not be added to the UMS Users State. {}", memberCrn, e.getLocalizedMessage());
            } else {
                throw e;
            }
        }
    });
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) StatusRuntimeException(io.grpc.StatusRuntimeException) Collection(java.util.Collection) WorkloadCredential(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)

Aggregations

FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)42 Test (org.junit.jupiter.api.Test)33 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)23 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)8 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)6 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)5 List (java.util.List)5 Map (java.util.Map)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)3 Collection (java.util.Collection)3 Set (java.util.Set)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 IPA_PROTECTED_USERS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS)2 IPA_UNMANAGED_GROUPS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2