Search in sources :

Example 1 with FmsGroup

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

the class UserSyncStateApplierTest method createStateDiff.

private UsersStateDifference createStateDiff() {
    FmsGroup groupToAdd1 = new FmsGroup().withName("groupToAdd1");
    FmsGroup groupToAdd2 = new FmsGroup().withName("groupToAdd2");
    FmsGroup groupToRemove1 = new FmsGroup().withName("groupToRemove1");
    FmsGroup groupToRemove2 = new FmsGroup().withName("groupToRemove2");
    FmsUser userToAdd1 = new FmsUser().withName("userToAdd1").withFirstName("clark").withLastName("kent");
    FmsUser userToAdd2 = new FmsUser().withName("userToAdd2").withFirstName("peter").withLastName("parker");
    String userToRemove1 = "userToRemove1";
    String userToRemove2 = "userToRemove2";
    String userToDisable1 = "userToDisable1";
    String userToDisable2 = "userToDisable2";
    String userToEnable1 = "userToEnable1";
    String userToEnable2 = "userToEnable2";
    return new UsersStateDifference(ImmutableSet.of(groupToAdd1, groupToAdd2), ImmutableSet.of(groupToRemove1, groupToRemove2), ImmutableSet.of(userToAdd1, userToAdd2), ImmutableSet.of("userToUpdate1", "userToUpdate2"), ImmutableSet.of(userToRemove1, userToRemove2), ImmutableMultimap.<String, String>builder().put(groupToAdd1.getName(), userToAdd1.getName()).put(groupToAdd2.getName(), userToAdd2.getName()).build(), ImmutableMultimap.<String, String>builder().put(groupToRemove1.getName(), userToRemove1).put(groupToRemove2.getName(), userToRemove2).build(), ImmutableSet.of(userToDisable1, userToDisable2), ImmutableSet.of(userToEnable1, userToEnable2));
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)

Example 2 with FmsGroup

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

the class UsersStateDifferenceCalculatorTest method testCalculateGroupsToAdd.

@Test
void testCalculateGroupsToAdd() {
    FmsGroup groupUms = new FmsGroup().withName("groupUms");
    FmsGroup groupWag = new FmsGroup().withName("groupWag");
    FmsGroup groupBoth = new FmsGroup().withName("groupBoth");
    FmsGroup groupIPA = new FmsGroup().withName("groupIPA");
    FmsGroup groupProtected = new FmsGroup().withName(FreeIpaChecks.IPA_PROTECTED_GROUPS.get(0));
    UmsUsersState umsUsersState = new UmsUsersState.Builder().setUsersState(new UsersState.Builder().addGroup(groupUms).addGroup(groupBoth).addGroup(groupProtected).build()).setWorkloadAdministrationGroups(Set.of(groupWag)).build();
    UsersState ipaUsersState = new UsersState.Builder().addGroup(groupBoth).addGroup(groupIPA).build();
    ImmutableSet<FmsGroup> groupsToAdd = new UserStateDifferenceCalculator().calculateGroupsToAdd(umsUsersState, ipaUsersState);
    // group that exists only in UMS will be added
    assertTrue(groupsToAdd.contains(groupUms));
    // protected groups will be ignored
    assertFalse(groupsToAdd.contains(groupProtected));
    // extra wags will not be added
    assertFalse(groupsToAdd.contains(groupWag));
    // groups that exist in both or only ipa will not be added
    assertFalse(groupsToAdd.contains(groupBoth));
    assertFalse(groupsToAdd.contains(groupIPA));
}
Also used : FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Test(org.junit.jupiter.api.Test)

Example 3 with FmsGroup

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

the class FmsGroupConverterTest method testUmsGroupToGroup.

@Test
public void testUmsGroupToGroup() {
    String groupName = "foobar";
    UserManagementProto.Group umsGroup = UserManagementProto.Group.newBuilder().setGroupName(groupName).build();
    FmsGroup fmsGroup = underTest.umsGroupToGroup(umsGroup);
    assertEquals(groupName, fmsGroup.getName());
}
Also used : UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) Test(org.junit.jupiter.api.Test)

Example 4 with FmsGroup

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

the class FmsGroupConverterTest method testNameToGroup.

@Test
public void testNameToGroup() {
    String groupName = "foobar";
    FmsGroup fmsGroup = underTest.nameToGroup(groupName);
    assertEquals(groupName, fmsGroup.getName());
}
Also used : FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) Test(org.junit.jupiter.api.Test)

Example 5 with FmsGroup

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

the class FreeIpaUsersStateProviderTest method testGetFilteredFreeIpaState.

@Test
void testGetFilteredFreeIpaState() throws Exception {
    List<String> user1GroupNames = List.of("group1", "group2");
    List<String> user2GroupNames = List.of("group2", "group3", IPA_UNMANAGED_GROUPS.get(0));
    List<String> groupsWithoutMembers = List.of("group4");
    com.sequenceiq.freeipa.client.model.User user1 = createIpaUser("user1", user1GroupNames);
    String userNotFound = "userNotFound";
    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());
    JsonRpcClientException jsonRpcException = new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "group not found", null);
    FreeIpaClientException notFoundException = new FreeIpaClientException("Invoke FreeIPA failed", jsonRpcException);
    when(freeIpaClient.userShow(user1.getUid())).thenReturn(user1);
    when(freeIpaClient.userShow(userNotFound)).thenThrow(notFoundException);
    when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
    Set<String> expectedUsers = Sets.newHashSet(user1.getUid());
    Set<String> expectedGroups = groupsFindAll.stream().map(com.sequenceiq.freeipa.client.model.Group::getCn).filter(groupName -> !IPA_UNMANAGED_GROUPS.contains(groupName)).collect(Collectors.toSet());
    UserMetadata user1Metadata = new UserMetadata("user1-crn", 1L);
    doReturn(Optional.of(user1Metadata)).when(userMetadataConverter).toUserMetadata(argThat(arg -> user1.getUid().equals(arg.getUid())));
    Map<String, UserMetadata> expectedUserMetadata = Map.of(user1.getUid(), user1Metadata);
    UsersState ipaState = underTest.getFilteredFreeIpaState(freeIpaClient, Set.of(user1.getUid(), userNotFound));
    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) 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) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Aggregations

FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)19 Test (org.junit.jupiter.api.Test)11 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)6 List (java.util.List)6 Map (java.util.Map)6 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)5 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)4 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)3 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)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 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)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 Group (com.sequenceiq.freeipa.client.model.Group)2