You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/01/22 17:44:43 UTC

[4/5] syncope git commit: [SYNCOPE-756] Fix

[SYNCOPE-756] Fix


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/02abafa8
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/02abafa8
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/02abafa8

Branch: refs/heads/master
Commit: 02abafa83422c5b657129dd587610556a0d8623a
Parents: e684e61
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Jan 22 17:16:30 2016 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Fri Jan 22 17:16:30 2016 +0100

----------------------------------------------------------------------
 .../java/data/AnyObjectDataBinderImpl.java      | 97 ++++++++++++--------
 .../fit/core/reference/AnyObjectITCase.java     | 15 +++
 2 files changed, 75 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/02abafa8/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 19684b2..fbd090c 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
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Set;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Transformer;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.SyncopeClientCompositeException;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.patch.AnyObjectPatch;
@@ -152,28 +153,39 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An
                     searchDAO.search(SearchCond.getLeafCond(assignableCond), AnyTypeKind.ANY_OBJECT);
 
             for (RelationshipTO relationshipTO : anyObjectTO.getRelationships()) {
-                AnyObject otherEnd = anyObjectDAO.find(relationshipTO.getRightKey());
-                if (otherEnd == null) {
-                    LOG.debug("Ignoring invalid anyObject " + relationshipTO.getRightKey());
-                } else if (assignableAnyObjects.contains(otherEnd)) {
-                    RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTO.getType());
-                    if (relationshipType == null) {
-                        LOG.debug("Ignoring invalid relationship type {}", relationshipTO.getType());
+                if (StringUtils.isBlank(relationshipTO.getRightType())
+                        || AnyTypeKind.USER.name().equals(relationshipTO.getRightType())
+                        || AnyTypeKind.GROUP.name().equals(relationshipTO.getRightType())) {
+
+                    SyncopeClientException invalidAnyType =
+                            SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
+                    invalidAnyType.getElements().add(AnyType.class.getSimpleName()
+                            + " not allowed for relationship: " + relationshipTO.getRightType());
+                    scce.addException(invalidAnyType);
+                } else {
+                    AnyObject otherEnd = anyObjectDAO.find(relationshipTO.getRightKey());
+                    if (otherEnd == null) {
+                        LOG.debug("Ignoring invalid anyObject " + relationshipTO.getRightKey());
+                    } else if (assignableAnyObjects.contains(otherEnd)) {
+                        RelationshipType relationshipType = relationshipTypeDAO.find(relationshipTO.getType());
+                        if (relationshipType == null) {
+                            LOG.debug("Ignoring invalid relationship type {}", relationshipTO.getType());
+                        } else {
+                            ARelationship relationship = entityFactory.newEntity(ARelationship.class);
+                            relationship.setType(relationshipType);
+                            relationship.setRightEnd(anyObject);
+                            relationship.setLeftEnd(anyObject);
+
+                            anyObject.add(relationship);
+                        }
                     } else {
-                        ARelationship relationship = entityFactory.newEntity(ARelationship.class);
-                        relationship.setType(relationshipType);
-                        relationship.setRightEnd(anyObject);
-                        relationship.setLeftEnd(anyObject);
+                        LOG.error("{} cannot be assigned to {}", otherEnd, anyObject);
 
-                        anyObject.add(relationship);
+                        SyncopeClientException unassignabled =
+                                SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
+                        unassignabled.getElements().add("Cannot be assigned: " + otherEnd);
+                        scce.addException(unassignabled);
                     }
-                } else {
-                    LOG.error("{} cannot be assigned to {}", otherEnd, anyObject);
-
-                    SyncopeClientException unassignabled =
-                            SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
-                    unassignabled.getElements().add("Cannot be assigned: " + otherEnd);
-                    scce.addException(unassignabled);
                 }
             }
 
@@ -249,25 +261,36 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An
                     }
 
                     if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
-                        AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getRightKey());
-                        if (otherEnd == null) {
-                            LOG.debug("Ignoring invalid any object {}", patch.getRelationshipTO().getRightKey());
-                        } else if (assignableAnyObjects.contains(otherEnd)) {
-                            relationship = entityFactory.newEntity(ARelationship.class);
-                            relationship.setType(relationshipType);
-                            relationship.setRightEnd(otherEnd);
-                            relationship.setLeftEnd(anyObject);
-
-                            anyObject.add(relationship);
-
-                            toBeProvisioned.addAll(otherEnd.getResourceNames());
+                        if (StringUtils.isBlank(patch.getRelationshipTO().getRightType())
+                                || AnyTypeKind.USER.name().equals(patch.getRelationshipTO().getRightType())
+                                || AnyTypeKind.GROUP.name().equals(patch.getRelationshipTO().getRightType())) {
+
+                            SyncopeClientException invalidAnyType =
+                                    SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
+                            invalidAnyType.getElements().add(AnyType.class.getSimpleName()
+                                    + " not allowed for relationship: " + patch.getRelationshipTO().getRightType());
+                            scce.addException(invalidAnyType);
                         } else {
-                            LOG.error("{} cannot be assigned to {}", otherEnd, anyObject);
-
-                            SyncopeClientException unassignabled =
-                                    SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
-                            unassignabled.getElements().add("Cannot be assigned: " + otherEnd);
-                            scce.addException(unassignabled);
+                            AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getRightKey());
+                            if (otherEnd == null) {
+                                LOG.debug("Ignoring invalid any object {}", patch.getRelationshipTO().getRightKey());
+                            } else if (assignableAnyObjects.contains(otherEnd)) {
+                                relationship = entityFactory.newEntity(ARelationship.class);
+                                relationship.setType(relationshipType);
+                                relationship.setRightEnd(otherEnd);
+                                relationship.setLeftEnd(anyObject);
+
+                                anyObject.add(relationship);
+
+                                toBeProvisioned.addAll(otherEnd.getResourceNames());
+                            } else {
+                                LOG.error("{} cannot be assigned to {}", otherEnd, anyObject);
+
+                                SyncopeClientException unassignabled =
+                                        SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
+                                unassignabled.getElements().add("Cannot be assigned: " + otherEnd);
+                                scce.addException(unassignabled);
+                            }
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/02abafa8/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
index 192fa76..6cbcf39 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
@@ -34,6 +34,8 @@ import org.apache.syncope.common.lib.to.AnyObjectTO;
 import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.MembershipTO;
 import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.RelationshipTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.ClientExceptionType;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.syncope.common.rest.api.beans.AnyListQuery;
@@ -191,4 +193,17 @@ public class AnyObjectITCase extends AbstractITCase {
             assertEquals(ClientExceptionType.NotFound, e.getType());
         }
     }
+
+    @Test
+    public void issueSYNCOPE756() {
+        AnyObjectTO anyObjectTO = getSampleTO("issueSYNCOPE756");
+        anyObjectTO.getRelationships().add(new RelationshipTO.Builder().right(AnyTypeKind.USER.name(), 1).build());
+
+        try {
+            createAnyObject(anyObjectTO).getAny();
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
+        }
+    }
 }