syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: [SYNCOPE-1199] Simpler check for assignable groups / any objects
Date Tue, 05 Sep 2017 07:36:01 GMT
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ò <ilgrosso@apache.org>
Authored: Tue Sep 5 09:12:50 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
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<String> assignableAnyObjects = anyObjectTO.getRelationships().isEmpty()
-                    ? Collections.<String>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<String> assignableGroups = anyObjectTO.getMemberships().isEmpty()
-                    ? Collections.<String>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<String> toBeProvisioned = new HashSet<>();
 
         // relationships
-        Collection<String> 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<String> 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<? extends AMembership> 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<String> assignableAnyObjects = userTO.getRelationships().isEmpty()
-                    ? Collections.<String>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<String> assignableGroups = userTO.getMemberships().isEmpty()
-                    ? Collections.<String>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<String> toBeProvisioned = new HashSet<>();
 
         // relationships
-        Collection<String> 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<String> 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<? extends UMembership> 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);


Mime
View raw message