Search in sources :

Example 6 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserKeytabService method validateFreeIpaState.

private void validateFreeIpaState(String workloadUsername, String environmentCrn) {
    String accountId = Crn.safeFromString(environmentCrn).getAccountId();
    FreeIpaClient freeIpaClient;
    try {
        freeIpaClient = freeIpaClientFactory.getFreeIpaClientByAccountAndEnvironment(environmentCrn, accountId);
        if (!FreeIpaCapabilities.hasSetPasswordHashSupport(freeIpaClient.getConfig())) {
            throw new UnsupportedException("User keytab retrieval requires a newer environment and FreeIPA version");
        }
        Optional<User> user = freeIpaClient.userFind(workloadUsername);
        if (user.isEmpty()) {
            throw new NotFoundException(String.format("Workload user %s has not been synced into environment %s", workloadUsername, environmentCrn));
        }
    } catch (FreeIpaClientException e) {
        throw new RuntimeException(e);
    }
}
Also used : UnsupportedException(com.sequenceiq.freeipa.controller.exception.UnsupportedException) User(com.sequenceiq.freeipa.client.model.User) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Example 7 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserSyncOperationsTest method testEnableUsersSingle.

@Test
public void testEnableUsersSingle() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    Set<String> 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_enable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenReturn(response1, response2);
    underTest.enableUsers(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(0)));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : User(com.sequenceiq.freeipa.client.model.User) 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 8 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserSyncOperationsTest method testRemoveUsersSingle.

@Test
public void testRemoveUsersSingle() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    Set<String> 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_del"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
    underTest.removeUsers(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(0)));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : User(com.sequenceiq.freeipa.client.model.User) 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 9 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserSyncOperationsTest method testRemoveUsersFromGroupsSingle.

@Test
public void testRemoveUsersFromGroupsSingle() throws Exception {
    Multimap<String, String> groupMapping = setupGroupMapping(5, MAX_SUBJECTS_PER_REQUEST * 2);
    Multimap<String, String> warnings = ArrayListMultimap.create();
    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 Group());
    RPCResponse<Object> response2 = new RPCResponse<>();
    response2.setResult(new Group());
    when(freeIpaClient.invoke(eq("group_remove_member"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Group.class))).thenReturn(response1, response2);
    underTest.removeUsersFromGroups(false, freeIpaClient, groupMapping, warnings::put);
    assertTrue(warnings.isEmpty());
    verifyNoInteractions(batchPartitionSizeProperties);
    verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
    List<List<Object>> flagsList = flagsCaptor.getAllValues();
    Map<String, Long> flagCount = flagsList.stream().flatMap(Collection::stream).map(o -> (String) o).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    assertEquals(5, flagCount.size());
    assertTrue(flagCount.keySet().containsAll(Set.of("group1", "group2", "group3", "group4", "group0")));
    flagCount.forEach((flag, count) -> assertEquals(2, count, flag + " size should be 2"));
    List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
    assertEquals(10, paramsList.size());
    paramsList.forEach(map -> {
        assertEquals(10, ((List<String>) map.get("user")).size());
        assertTrue(((List<String>) map.get("user")).stream().allMatch(user -> user.startsWith("user")));
    });
    verify(interruptChecker, times(20)).throwTimeoutExIfInterrupted();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) BeforeEach(org.junit.jupiter.api.BeforeEach) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) TimeoutException(java.util.concurrent.TimeoutException) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) Group(com.sequenceiq.freeipa.client.model.Group) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) HashMultimap(com.google.common.collect.HashMultimap) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) BatchPartitionSizeProperties(com.sequenceiq.freeipa.configuration.BatchPartitionSizeProperties) ThreadInterruptChecker(com.sequenceiq.freeipa.util.ThreadInterruptChecker) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Matchers.allOf(org.hamcrest.Matchers.allOf) Collection(java.util.Collection) Set(java.util.Set) Matchers(org.hamcrest.Matchers) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) User(com.sequenceiq.freeipa.client.model.User) Mockito.times(org.mockito.Mockito.times) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Collectors(java.util.stream.Collectors) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) Group(com.sequenceiq.freeipa.client.model.Group) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 10 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserSyncOperationsTest method testDisableUsersSingle.

@Test
public void testDisableUsersSingle() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    Set<String> 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_disable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenReturn(response1, response2);
    underTest.disableUsers(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(0)));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : User(com.sequenceiq.freeipa.client.model.User) 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)

Aggregations

User (com.sequenceiq.freeipa.client.model.User)38 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)15 Test (org.junit.jupiter.api.Test)13 Map (java.util.Map)11 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)10 Set (java.util.Set)8 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)7 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)7 List (java.util.List)7 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)3 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2