@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"); Map<String, List<String>> users = Map.of( "user1", user1GroupNames, "user2", user2GroupNames, IPA_PROTECTED_USERS.get(0), ipaOnlyUserGroupNames ); Set<com.sequenceiq.freeipa.client.model.User> usersFindAll = users.entrySet().stream() .map(entry -> createIpaUser(entry.getKey(), entry.getValue())) .collect(Collectors.toSet()); Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = Stream.of(user1GroupNames.stream(), user2GroupNames.stream(), IPA_UNMANAGED_GROUPS.stream()) .flatMap(groupName -> groupName) .map(this::createIpaGroup) .collect(Collectors.toSet()); when(freeIpaClient.userFindAll()).thenReturn(usersFindAll); when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll); UsersState ipaState = underTest.getUsersState(freeIpaClient); Set<String> expectedUsers = users.keySet().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user)) .collect(Collectors.toSet()); Set<String> expectedGroups = expectedUsers.stream() .flatMap(user -> users.get(user).stream()) .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .collect(Collectors.toSet()); 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()); }
public UsersState getUsersState(FreeIpaClient freeIpaClient) throws FreeIpaClientException { LOGGER.debug("Retrieving all users from FreeIPA"); UsersState.Builder builder = new UsersState.Builder(); freeIpaClient.userFindAll().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user.getUid())) .forEach(user -> { builder.addUser(fromIpaUser(user)); if (null != user.getMemberOfGroup()) { user.getMemberOfGroup().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .forEach(group -> builder.addMemberToGroup(group, user.getUid())); } else { LOGGER.warn("User {} is not a member of any groups.", user.getUid()); } }); freeIpaClient.groupFindAll().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())) .forEach(group -> builder.addGroup(fromIpaGroup(group))); return builder.build(); }
FreeIpaUsersStateProvider { public UsersState getUsersState(FreeIpaClient freeIpaClient) throws FreeIpaClientException { LOGGER.debug("Retrieving all users from FreeIPA"); UsersState.Builder builder = new UsersState.Builder(); freeIpaClient.userFindAll().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user.getUid())) .forEach(user -> { builder.addUser(fromIpaUser(user)); if (null != user.getMemberOfGroup()) { user.getMemberOfGroup().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .forEach(group -> builder.addMemberToGroup(group, user.getUid())); } else { LOGGER.warn("User {} is not a member of any groups.", user.getUid()); } }); freeIpaClient.groupFindAll().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())) .forEach(group -> builder.addGroup(fromIpaGroup(group))); return builder.build(); } }
FreeIpaUsersStateProvider { public UsersState getUsersState(FreeIpaClient freeIpaClient) throws FreeIpaClientException { LOGGER.debug("Retrieving all users from FreeIPA"); UsersState.Builder builder = new UsersState.Builder(); freeIpaClient.userFindAll().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user.getUid())) .forEach(user -> { builder.addUser(fromIpaUser(user)); if (null != user.getMemberOfGroup()) { user.getMemberOfGroup().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .forEach(group -> builder.addMemberToGroup(group, user.getUid())); } else { LOGGER.warn("User {} is not a member of any groups.", user.getUid()); } }); freeIpaClient.groupFindAll().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())) .forEach(group -> builder.addGroup(fromIpaGroup(group))); return builder.build(); }  }
FreeIpaUsersStateProvider { public UsersState getUsersState(FreeIpaClient freeIpaClient) throws FreeIpaClientException { LOGGER.debug("Retrieving all users from FreeIPA"); UsersState.Builder builder = new UsersState.Builder(); freeIpaClient.userFindAll().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user.getUid())) .forEach(user -> { builder.addUser(fromIpaUser(user)); if (null != user.getMemberOfGroup()) { user.getMemberOfGroup().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .forEach(group -> builder.addMemberToGroup(group, user.getUid())); } else { LOGGER.warn("User {} is not a member of any groups.", user.getUid()); } }); freeIpaClient.groupFindAll().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())) .forEach(group -> builder.addGroup(fromIpaGroup(group))); return builder.build(); }  UsersState getUsersState(FreeIpaClient freeIpaClient); UsersState getFilteredFreeIpaState(FreeIpaClient freeIpaClient, Set<String> userNames); }
FreeIpaUsersStateProvider { public UsersState getUsersState(FreeIpaClient freeIpaClient) throws FreeIpaClientException { LOGGER.debug("Retrieving all users from FreeIPA"); UsersState.Builder builder = new UsersState.Builder(); freeIpaClient.userFindAll().stream() .filter(user -> !IPA_PROTECTED_USERS.contains(user.getUid())) .forEach(user -> { builder.addUser(fromIpaUser(user)); if (null != user.getMemberOfGroup()) { user.getMemberOfGroup().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)) .forEach(group -> builder.addMemberToGroup(group, user.getUid())); } else { LOGGER.warn("User {} is not a member of any groups.", user.getUid()); } }); freeIpaClient.groupFindAll().stream() .filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())) .forEach(group -> builder.addGroup(fromIpaGroup(group))); return builder.build(); }  UsersState getUsersState(FreeIpaClient freeIpaClient); UsersState getFilteredFreeIpaState(FreeIpaClient freeIpaClient, Set<String> userNames);  }