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