@Test void testCalculateGroupsToRemove() { 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) .build()) .setWorkloadAdministrationGroups(Set.of(groupWag)) .build(); UsersState ipaUsersState = new UsersState.Builder() .addGroup(groupBoth) .addGroup(groupIPA) .addGroup(groupWag) .addGroup(groupProtected) .build(); ImmutableSet<FmsGroup> groupsToRemove = UsersStateDifference.calculateGroupsToRemove(umsUsersState, ipaUsersState); assertTrue(groupsToRemove.contains(groupIPA)); assertFalse(groupsToRemove.contains(groupWag)); assertFalse(groupsToRemove.contains(groupProtected)); assertFalse(groupsToRemove.contains(groupBoth)); assertFalse(groupsToRemove.contains(groupUms)); }
public static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState) { Set<FmsGroup> allControlPlaneGroups = Sets.union(umsState.getWorkloadAdministrationGroups(), umsState.getUsersState().getGroups()); ImmutableSet<FmsGroup> groupsToRemove = ImmutableSet.copyOf(Sets.difference(ipaState.getGroups(), allControlPlaneGroups) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToRemove size = {}", groupsToRemove.size()); LOGGER.debug("groupsToRemove = {}", groupsToRemove.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToRemove; }
UsersStateDifference { public static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState) { Set<FmsGroup> allControlPlaneGroups = Sets.union(umsState.getWorkloadAdministrationGroups(), umsState.getUsersState().getGroups()); ImmutableSet<FmsGroup> groupsToRemove = ImmutableSet.copyOf(Sets.difference(ipaState.getGroups(), allControlPlaneGroups) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToRemove size = {}", groupsToRemove.size()); LOGGER.debug("groupsToRemove = {}", groupsToRemove.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToRemove; } }
UsersStateDifference { public static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState) { Set<FmsGroup> allControlPlaneGroups = Sets.union(umsState.getWorkloadAdministrationGroups(), umsState.getUsersState().getGroups()); ImmutableSet<FmsGroup> groupsToRemove = ImmutableSet.copyOf(Sets.difference(ipaState.getGroups(), allControlPlaneGroups) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToRemove size = {}", groupsToRemove.size()); LOGGER.debug("groupsToRemove = {}", groupsToRemove.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToRemove; } UsersStateDifference(ImmutableSet<FmsGroup> groupsToAdd, ImmutableSet<FmsGroup> groupsToRemove,
            ImmutableSet<FmsUser> usersToAdd, ImmutableSet<String> usersToRemove,
            ImmutableMultimap<String, String> groupMembershipToAdd, ImmutableMultimap<String, String> groupMembershipToRemove); }
UsersStateDifference { public static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState) { Set<FmsGroup> allControlPlaneGroups = Sets.union(umsState.getWorkloadAdministrationGroups(), umsState.getUsersState().getGroups()); ImmutableSet<FmsGroup> groupsToRemove = ImmutableSet.copyOf(Sets.difference(ipaState.getGroups(), allControlPlaneGroups) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToRemove size = {}", groupsToRemove.size()); LOGGER.debug("groupsToRemove = {}", groupsToRemove.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToRemove; } UsersStateDifference(ImmutableSet<FmsGroup> groupsToAdd, ImmutableSet<FmsGroup> groupsToRemove,
            ImmutableSet<FmsUser> usersToAdd, ImmutableSet<String> usersToRemove,
            ImmutableMultimap<String, String> groupMembershipToAdd, ImmutableMultimap<String, String> groupMembershipToRemove); ImmutableSet<FmsGroup> getGroupsToAdd(); ImmutableSet<FmsGroup> getGroupsToRemove(); ImmutableSet<FmsUser> getUsersToAdd(); ImmutableSet<String> getUsersToRemove(); ImmutableMultimap<String, String> getGroupMembershipToAdd(); ImmutableMultimap<String, String> getGroupMembershipToRemove(); @Override String toString(); static UsersStateDifference fromUmsAndIpaUsersStates(UmsUsersState umsState, UsersState ipaState); static UsersStateDifference forDeletedUser(String deletedUser, Collection<String> groupsToRemove); static ImmutableSet<FmsUser> calculateUsersToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<String> calculateUsersToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToRemove(UmsUsersState umsState, UsersState ipaState); }
UsersStateDifference { public static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState) { Set<FmsGroup> allControlPlaneGroups = Sets.union(umsState.getWorkloadAdministrationGroups(), umsState.getUsersState().getGroups()); ImmutableSet<FmsGroup> groupsToRemove = ImmutableSet.copyOf(Sets.difference(ipaState.getGroups(), allControlPlaneGroups) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToRemove size = {}", groupsToRemove.size()); LOGGER.debug("groupsToRemove = {}", groupsToRemove.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToRemove; } UsersStateDifference(ImmutableSet<FmsGroup> groupsToAdd, ImmutableSet<FmsGroup> groupsToRemove,
            ImmutableSet<FmsUser> usersToAdd, ImmutableSet<String> usersToRemove,
            ImmutableMultimap<String, String> groupMembershipToAdd, ImmutableMultimap<String, String> groupMembershipToRemove); ImmutableSet<FmsGroup> getGroupsToAdd(); ImmutableSet<FmsGroup> getGroupsToRemove(); ImmutableSet<FmsUser> getUsersToAdd(); ImmutableSet<String> getUsersToRemove(); ImmutableMultimap<String, String> getGroupMembershipToAdd(); ImmutableMultimap<String, String> getGroupMembershipToRemove(); @Override String toString(); static UsersStateDifference fromUmsAndIpaUsersStates(UmsUsersState umsState, UsersState ipaState); static UsersStateDifference forDeletedUser(String deletedUser, Collection<String> groupsToRemove); static ImmutableSet<FmsUser> calculateUsersToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<String> calculateUsersToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToRemove(UmsUsersState umsState, UsersState ipaState);  }