Source:
private List<DbUser> refreshUsers(List<DbUser> dbUsers, ExtensionProxy authz) { Map<String, List<String>> idsPerNamespace = new HashMap<>(); List<DbUser> refreshed = new ArrayList<>(); for (DbUser dbUser : dbUsers) { MultiValueMapUtils.addToMap(dbUser.getNamespace(), dbUser.getExternalId(), idsPerNamespace); } for (String namespace : idsPerNamespace.keySet()) { List<DirectoryUser> directoryUsers = null; if (authz != null) { directoryUsers = AuthzUtils.findPrincipalsByIds(authz, namespace, idsPerNamespace.get(namespace), true, false); } else { directoryUsers = Collections.emptyList(); } Map<String, DirectoryUser> index = new HashMap<>(); Set<DirectoryGroup> groupsToFetch = new HashSet<>(); for (DirectoryUser directoryUser : directoryUsers) { groupsToFetch.addAll(directoryUser.getGroups()); index.put(directoryUser.getId(), directoryUser); } Map<String, DirectoryGroup> fetchedGroups = new HashMap<>(); populateRecrusiveGroups(authz, fetchedGroups, groupsToFetch); for (DirectoryUser directoryUser : directoryUsers) { List<DirectoryGroup> newDirectoryGroups = new ArrayList<>(directoryUser.getGroups().size()); for (DirectoryGroup fetchedGroup : directoryUser.getGroups()) { newDirectoryGroups.add(fetchedGroups.get(fetchedGroup.getId())); } directoryUser.setGroups(newDirectoryGroups); } for (DbUser dbUser : dbUsers) { DirectoryUser directoryUser = index.get(dbUser.getExternalId()); if (directoryUser != null) { dbUser.setActive(false); dbUser.setGroupIds(DirectoryUtils.getGroupIdsFromUser(directoryUser)); dbUser = refreshUser(dbUser, directoryUser); if (dbUser != null) { refreshed.add(dbUser); } } } } return refreshed; }

Target:
private List<DbUser> refreshUsers(List<DbUser> dbUsers, ExtensionProxy authz) { Map<String, List<String>> idsPerNamespace = new HashMap<>(); List<DbUser> refreshed = new ArrayList<>(); for (DbUser dbUser : dbUsers) { MultiValueMapUtils.addToMap(dbUser.getNamespace(), dbUser.getExternalId(), idsPerNamespace); } for (String namespace : idsPerNamespace.keySet()) { List<DirectoryUser> directoryUsers = null; if (authz != null) { directoryUsers = AuthzUtils.findPrincipalsByIds(authz, namespace, idsPerNamespace.get(namespace), true, false); } else { directoryUsers = Collections.emptyList(); } Map<String, DirectoryUser> index = new HashMap<>(); Set<DirectoryGroup> groupsToFetch = new HashSet<>(); for (DirectoryUser directoryUser : directoryUsers) { groupsToFetch.addAll(directoryUser.getGroups()); index.put(directoryUser.getId(), directoryUser); } if (dbGroups.get(namespace) != null) { for (DbGroup group : dbGroups.get(namespace)) { if (groupFromAuthzProvider(group, AuthzUtils.getName(authz))) { DirectoryGroup directoryGroup = AuthzUtils.findGroupById(authz, namespace, group.getExternalId(), true, false); groupsToFetch.addAll(directoryGroup.getGroups()); } } } Map<String, DirectoryGroup> fetchedGroups = new HashMap<>(); populateRecrusiveGroups(authz, fetchedGroups, groupsToFetch); for (DirectoryUser directoryUser : directoryUsers) { List<DirectoryGroup> newDirectoryGroups = new ArrayList<>(directoryUser.getGroups().size()); for (DirectoryGroup fetchedGroup : directoryUser.getGroups()) { newDirectoryGroups.add(fetchedGroups.get(fetchedGroup.getId())); } directoryUser.setGroups(newDirectoryGroups); } for (DbUser dbUser : dbUsers) { DirectoryUser directoryUser = index.get(dbUser.getExternalId()); if (directoryUser != null) { dbUser.setActive(false); dbUser.setGroupIds(DirectoryUtils.getGroupIdsFromUser(directoryUser)); dbUser = refreshUser(dbUser, directoryUser, fetchedGroups); if (dbUser != null) { refreshed.add(dbUser); } } } } return refreshed; }