github-code-scanning[bot] commented on code in PR #383: URL: https://github.com/apache/syncope/pull/383#discussion_r1006548975
########## core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/LDAPMembershipPullActions.java: ########## @@ -190,15 +212,49 @@ }); } + @Transactional(propagation = Propagation.REQUIRES_NEW) @Override public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException { - Map<String, Object> jobMap = new HashMap<>(); - jobMap.put(SetUMembershipsJob.MEMBERSHIPS_BEFORE_KEY, membershipsBefore); - jobMap.put(SetUMembershipsJob.MEMBERSHIPS_AFTER_KEY, membershipsAfter); - jobMap.put(JobManager.EXECUTOR_KEY, profile.getExecutor()); - jobMap.put( - SetUMembershipsJob.CONTEXT, - "PullTask " + profile.getTask().getKey() + " '" + profile.getTask().getName() + "'"); - schedule(SetUMembershipsJob.class, jobMap); + List<UserUR> updateReqs = new ArrayList<>(); + + membershipsAfter.forEach((user, groups) -> { + UserUR userUR = new UserUR(); + userUR.setKey(user); + updateReqs.add(userUR); + + groups.stream().forEach(group -> { + Set<String> before = membershipsBefore.get(user); + if (before == null || !before.contains(group)) { + userUR.getMemberships().add(new MembershipUR.Builder(group). + operation(PatchOperation.ADD_REPLACE). + build()); + } + }); + }); + + membershipsBefore.forEach((user, groups) -> { + UserUR userUR = updateReqs.stream(). + filter(req -> user.equals(req.getKey())).findFirst(). + orElseGet(() -> { + UserUR req = new UserUR.Builder(user).build(); + updateReqs.add(req); + return req; + }); + + groups.forEach(group -> { + Set<String> after = membershipsAfter.get(user); + if (after == null || !after.contains(group)) { + userUR.getMemberships().add(new MembershipUR.Builder(group). + operation(PatchOperation.DELETE). + build()); + } + }); + }); + + String context = "PullTask " + profile.getTask().getKey() + " '" + profile.getTask().getName() + "'"; + updateReqs.stream().filter(req -> !req.isEmpty()).forEach(req -> { + LOG.debug("About to update User {}", req); Review Comment: ## Use of default toString() Default toString(): UserUR inherits toString() from Object, and so is not suitable for printing. [Show more details](https://github.com/apache/syncope/security/code-scanning/1188) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org