Search in sources :

Example 21 with FmsUser

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

the class FreeIpaUsersStateProviderTest method testGetUserStateUserWithNullGroups.

@Test
void testGetUserStateUserWithNullGroups() throws Exception {
    String username = "userNull";
    Set<com.sequenceiq.freeipa.client.model.User> usersFindAll = Set.of(createIpaUser(username, null));
    Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = IPA_UNMANAGED_GROUPS.stream().map(this::createIpaGroup).collect(Collectors.toSet());
    when(freeIpaClient.userFindAll()).thenReturn(usersFindAll);
    when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
    UsersState ipaState = underTest.getUsersState(freeIpaClient);
    assertEquals(1, ipaState.getUsers().size());
    FmsUser ipaUser = ipaState.getUsers().asList().get(0);
    assertEquals(username, ipaUser.getName());
}
Also used : 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) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Test(org.junit.jupiter.api.Test)

Example 22 with FmsUser

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

the class UserSyncForStackServiceTest method testSynchronizeStackForDeleteUser.

@Test
public void testSynchronizeStackForDeleteUser() throws FreeIpaClientException, TimeoutException {
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of(new FmsUser().withName("deleteMe")));
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(usersState.getGroupMembership()).thenReturn(ImmutableMultimap.of("deleteMe", "group"));
    when(freeIpaUsersStateProvider.getFilteredFreeIpaState(FREE_IPA_CLIENT, Set.of("deleteMe"))).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    ArgumentCaptor<Collection<String>> captor = ArgumentCaptor.forClass(Collection.class);
    when(userStateDifferenceCalculator.forDeletedUser(eq("deleteMe"), captor.capture())).thenReturn(usersStateDifference);
    SyncStatusDetail result = underTest.synchronizeStackForDeleteUser(STACK, "deleteMe");
    verify(stateApplier).applyStateDifferenceToIpa(eq(ENV_CRN), eq(FREE_IPA_CLIENT), eq(usersStateDifference), any(), eq(false));
    assertTrue(captor.getValue().contains("group"));
    assertEquals(1, captor.getValue().size());
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(COMPLETED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Collection(java.util.Collection) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 23 with FmsUser

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

the class FmsUserConverter method createFmsUser.

private FmsUser createFmsUser(String workloadUsername, String firstName, String lastName, UserManagementProto.ActorState.Value actorState) {
    checkArgument(StringUtils.isNotBlank(workloadUsername));
    FmsUser fmsUser = new FmsUser();
    fmsUser.withName(workloadUsername);
    fmsUser.withFirstName(StringUtils.defaultIfBlank(StringUtils.strip(firstName), NONE_STRING));
    fmsUser.withLastName(StringUtils.defaultIfBlank(StringUtils.strip(lastName), NONE_STRING));
    fmsUser.withState(toFmsUserState(actorState));
    return fmsUser;
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)

Example 24 with FmsUser

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

the class UserSyncOperationsTest method testAddUsersBatch.

@Test
public void testAddUsersBatch() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    FmsUser user1 = new FmsUser().withName("user_1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
    FmsUser user2 = new FmsUser().withName("user_2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
    Set<FmsUser> users = Set.of(user1, user2);
    when(batchPartitionSizeProperties.getByOperation("user_add")).thenReturn(3);
    underTest.addUsers(true, freeIpaClient, users, warnings::put);
    assertTrue(warnings.isEmpty());
    ArgumentCaptor<List<Object>> operationsCaptor = ArgumentCaptor.forClass(List.class);
    verify(freeIpaClient).callBatch(any(), operationsCaptor.capture(), eq(3), eq(Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)), any());
    List<Object> operations = operationsCaptor.getValue();
    assertEquals(2, operations.size());
    Object user1oper = operations.stream().filter(op -> {
        Map<String, Object> operation = (Map<String, Object>) op;
        List<Object> params = (List<Object>) operation.get("params");
        return "user_1".equals(((List<String>) params.get(0)).get(0));
    }).findFirst().get();
    Map<String, Object> operation1 = (Map<String, Object>) user1oper;
    List<Object> params1 = (List<Object>) operation1.get("params");
    Map<String, Object> attribs1 = (Map<String, Object>) params1.get(1);
    assertEquals("User_1", attribs1.get("givenname"));
    assertEquals("Test1", attribs1.get("sn"));
    assertTrue(((List<String>) attribs1.get("setattr")).contains("nsAccountLock=false"));
    Object user2oper = operations.stream().filter(op -> {
        Map<String, Object> operation = (Map<String, Object>) op;
        List<Object> params = (List<Object>) operation.get("params");
        return "user_2".equals(((List<String>) params.get(0)).get(0));
    }).findFirst().get();
    Map<String, Object> operation2 = (Map<String, Object>) user2oper;
    List<Object> params2 = (List<Object>) operation2.get("params");
    Map<String, Object> attribs2 = (Map<String, Object>) params2.get(1);
    assertEquals("User_2", attribs2.get("givenname"));
    assertEquals("Test2", attribs2.get("sn"));
    assertTrue(((List<String>) attribs2.get("setattr")).contains("nsAccountLock=true"));
    verify(interruptChecker, times(2)).throwTimeoutExIfInterrupted();
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 25 with FmsUser

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

the class FmsUserConverterTest method testUserToFmsUser.

@Test
public void testUserToFmsUser() {
    String firstName = "Foo";
    String lastName = "Bar";
    String workloadUsername = "foobar";
    UserManagementProto.User umsUser = UserManagementProto.User.newBuilder().setFirstName(firstName).setLastName(lastName).setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.ACTIVE).build();
    FmsUser fmsUser = underTest.toFmsUser(umsUser);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(firstName, fmsUser.getFirstName());
    assertEquals(lastName, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, 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)

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