Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 57239200CFA for ; Tue, 5 Sep 2017 09:36:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 55B891656C8; Tue, 5 Sep 2017 07:36:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4D1DE1656C4 for ; Tue, 5 Sep 2017 09:36:02 +0200 (CEST) Received: (qmail 42406 invoked by uid 500); 5 Sep 2017 07:36:01 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 42397 invoked by uid 99); 5 Sep 2017 07:36:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Sep 2017 07:36:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5420EF553A; Tue, 5 Sep 2017 07:36:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ilgrosso@apache.org To: commits@syncope.apache.org Date: Tue, 05 Sep 2017 07:36:01 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] syncope git commit: [SYNCOPE-1199] Simpler check for assignable groups / any objects archived-at: Tue, 05 Sep 2017 07:36:03 -0000 Repository: syncope Updated Branches: refs/heads/2_0_X 91329e620 -> 838edcc2b refs/heads/master a7e8b95a5 -> df4bd83c9 [SYNCOPE-1199] Simpler check for assignable groups / any objects Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/df4bd83c Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/df4bd83c Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/df4bd83c Branch: refs/heads/master Commit: df4bd83c9d4c8374991a57e33a496e93aeaa0f12 Parents: a7e8b95 Author: Francesco Chicchiriccò Authored: Tue Sep 5 09:12:50 2017 +0200 Committer: Francesco Chicchiriccò Committed: Tue Sep 5 09:34:41 2017 +0200 ---------------------------------------------------------------------- .../java/data/AbstractAnyDataBinder.java | 8 ------ .../java/data/AnyObjectDataBinderImpl.java | 26 +++----------------- .../java/data/UserDataBinderImpl.java | 26 +++----------------- 3 files changed, 8 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/df4bd83c/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java ---------------------------------------------------------------------- diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java index b37c5a2..a0620e6 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java @@ -43,7 +43,6 @@ import org.apache.syncope.common.lib.types.ResourceOperation; import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException; import org.apache.syncope.core.persistence.api.dao.AllowedSchemas; import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; -import org.apache.syncope.core.persistence.api.dao.AnySearchDAO; import org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO; import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO; import org.apache.syncope.core.persistence.api.dao.GroupDAO; @@ -51,7 +50,6 @@ import org.apache.syncope.core.persistence.api.dao.NotFoundException; import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; -import org.apache.syncope.core.persistence.api.dao.PolicyDAO; import org.apache.syncope.core.persistence.api.dao.RealmDAO; import org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO; import org.apache.syncope.core.persistence.api.dao.UserDAO; @@ -122,15 +120,9 @@ abstract class AbstractAnyDataBinder { protected ExternalResourceDAO resourceDAO; @Autowired - protected PolicyDAO policyDAO; - - @Autowired protected RelationshipTypeDAO relationshipTypeDAO; @Autowired - protected AnySearchDAO searchDAO; - - @Autowired protected EntityFactory entityFactory; @Autowired http://git-wip-us.apache.org/repos/asf/syncope/blob/df4bd83c/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java ---------------------------------------------------------------------- diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java index 020ee74..40bb036 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java @@ -158,11 +158,6 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT); if (anyObject.getRealm() != null) { // relationships - Collection assignableAnyObjects = anyObjectTO.getRelationships().isEmpty() - ? Collections.emptyList() - : searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), AnyTypeKind.ANY_OBJECT).stream(). - map(a -> a.getKey()).collect(Collectors.toList()); - anyObjectTO.getRelationships().forEach(relationshipTO -> { if (StringUtils.isBlank(relationshipTO.getRightType()) || AnyTypeKind.USER.name().equals(relationshipTO.getRightType()) @@ -177,7 +172,7 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An AnyObject otherEnd = anyObjectDAO.find(relationshipTO.getRightKey()); if (otherEnd == null) { LOG.debug("Ignoring invalid anyObject " + relationshipTO.getRightKey()); - } else if (assignableAnyObjects.contains(otherEnd.getKey())) { + } else if (anyObject.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) { RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTO.getType()); if (relationshipType == null) { LOG.debug("Ignoring invalid relationship type {}", relationshipTO.getType()); @@ -201,11 +196,6 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An }); // memberships - Collection assignableGroups = anyObjectTO.getMemberships().isEmpty() - ? Collections.emptyList() - : searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), AnyTypeKind.GROUP).stream(). - map(g -> g.getKey()).collect(Collectors.toList()); - anyObjectTO.getMemberships().forEach(membershipTO -> { Group group = membershipTO.getRightKey() == null ? groupDAO.findByName(membershipTO.getGroupName()) @@ -213,7 +203,7 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An if (group == null) { LOG.debug("Ignoring invalid group " + membershipTO.getRightKey() + " / " + membershipTO.getGroupName()); - } else if (assignableGroups.contains(group.getKey())) { + } else if (anyObject.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) { AMembership membership = entityFactory.newEntity(AMembership.class); membership.setRightEnd(group); membership.setLeftEnd(anyObject); @@ -275,10 +265,6 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An Set toBeProvisioned = new HashSet<>(); // relationships - Collection assignableAnyObjects = - searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), AnyTypeKind.ANY_OBJECT).stream(). - map(a -> a.getKey()).collect(Collectors.toList()); - anyObjectPatch.getRelationships().stream(). filter(patch -> patch.getRelationshipTO() != null).forEachOrdered((patch) -> { RelationshipType relationshipType = relationshipTypeDAO.find(patch.getRelationshipTO().getType()); @@ -309,7 +295,7 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getRightKey()); if (otherEnd == null) { LOG.debug("Ignoring invalid any object {}", patch.getRelationshipTO().getRightKey()); - } else if (assignableAnyObjects.contains(otherEnd.getKey())) { + } else if (anyObject.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) { ARelationship newRelationship = entityFactory.newEntity(ARelationship.class); newRelationship.setType(relationshipType); newRelationship.setRightEnd(otherEnd); @@ -335,10 +321,6 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues); // memberships - Collection assignableGroups = - searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), AnyTypeKind.GROUP).stream(). - map(g -> g.getKey()).collect(Collectors.toList()); - anyObjectPatch.getMemberships().stream(). filter((membPatch) -> (membPatch.getGroup() != null)).forEachOrdered(membPatch -> { Optional membership = anyObject.getMembership(membPatch.getGroup()); @@ -356,7 +338,7 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An Group group = groupDAO.find(membPatch.getGroup()); if (group == null) { LOG.debug("Ignoring invalid group {}", membPatch.getGroup()); - } else if (assignableGroups.contains(group.getKey())) { + } else if (anyObject.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) { AMembership newMembership = entityFactory.newEntity(AMembership.class); newMembership.setRightEnd(group); newMembership.setLeftEnd(anyObject); http://git-wip-us.apache.org/repos/asf/syncope/blob/df4bd83c/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java ---------------------------------------------------------------------- diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java index d1ce405..989a076 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java @@ -203,16 +203,11 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.USER); if (user.getRealm() != null) { // relationships - Collection assignableAnyObjects = userTO.getRelationships().isEmpty() - ? Collections.emptyList() - : searchDAO.searchAssignable(user.getRealm().getFullPath(), AnyTypeKind.ANY_OBJECT).stream(). - map(a -> a.getKey()).collect(Collectors.toList()); - userTO.getRelationships().forEach(relationshipTO -> { AnyObject otherEnd = anyObjectDAO.find(relationshipTO.getRightKey()); if (otherEnd == null) { LOG.debug("Ignoring invalid anyObject " + relationshipTO.getRightKey()); - } else if (assignableAnyObjects.contains(otherEnd.getKey())) { + } else if (user.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) { RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTO.getType()); if (relationshipType == null) { LOG.debug("Ignoring invalid relationship type {}", relationshipTO.getType()); @@ -235,11 +230,6 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat }); // memberships - Collection assignableGroups = userTO.getMemberships().isEmpty() - ? Collections.emptyList() - : searchDAO.searchAssignable(user.getRealm().getFullPath(), AnyTypeKind.GROUP).stream(). - map(g -> g.getKey()).collect(Collectors.toList()); - userTO.getMemberships().forEach(membershipTO -> { Group group = membershipTO.getRightKey() == null ? groupDAO.findByName(membershipTO.getGroupName()) @@ -247,7 +237,7 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat if (group == null) { LOG.debug("Ignoring invalid group " + membershipTO.getRightKey() + " / " + membershipTO.getGroupName()); - } else if (assignableGroups.contains(group.getKey())) { + } else if (user.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) { UMembership membership = entityFactory.newEntity(UMembership.class); membership.setRightEnd(group); membership.setLeftEnd(user); @@ -378,10 +368,6 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat Set toBeProvisioned = new HashSet<>(); // relationships - Collection assignableAnyObjects = - searchDAO.searchAssignable(user.getRealm().getFullPath(), AnyTypeKind.ANY_OBJECT).stream(). - map(a -> a.getKey()).collect(Collectors.toList()); - userPatch.getRelationships().stream(). filter(patch -> patch.getRelationshipTO() != null).forEachOrdered((patch) -> { RelationshipType relationshipType = relationshipTypeDAO.find(patch.getRelationshipTO().getType()); @@ -402,7 +388,7 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getRightKey()); if (otherEnd == null) { LOG.debug("Ignoring invalid any object {}", patch.getRelationshipTO().getRightKey()); - } else if (assignableAnyObjects.contains(otherEnd.getKey())) { + } else if (user.getRealm().getFullPath().startsWith(otherEnd.getRealm().getFullPath())) { URelationship newRelationship = entityFactory.newEntity(URelationship.class); newRelationship.setType(relationshipType); newRelationship.setRightEnd(otherEnd); @@ -427,10 +413,6 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues); // memberships - Collection assignableGroups = - searchDAO.searchAssignable(user.getRealm().getFullPath(), AnyTypeKind.GROUP).stream(). - map(g -> g.getKey()).collect(Collectors.toList()); - userPatch.getMemberships().stream(). filter(membPatch -> membPatch.getGroup() != null).forEachOrdered((membPatch) -> { Optional membership = user.getMembership(membPatch.getGroup()); @@ -449,7 +431,7 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat Group group = groupDAO.find(membPatch.getGroup()); if (group == null) { LOG.debug("Ignoring invalid group {}", membPatch.getGroup()); - } else if (assignableGroups.contains(group.getKey())) { + } else if (user.getRealm().getFullPath().startsWith(group.getRealm().getFullPath())) { UMembership newMembership = entityFactory.newEntity(UMembership.class); newMembership.setRightEnd(group); newMembership.setLeftEnd(user);