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));
}
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));
}
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());
}
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());
}
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());
}
Aggregations