[SYNCOPE-944] fixes assignable groups collection used to verify group 
assignment validity


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

Branch: refs/heads/master
Commit: 1c1db2405b431e4782b15195dee83732754f64e8
Parents: 7fb3434
Author: fmartelli <fabio.marte...@gmail.com>
Authored: Fri Sep 16 16:47:57 2016 +0200
Committer: fmartelli <fabio.marte...@gmail.com>
Committed: Fri Sep 16 16:53:21 2016 +0200

----------------------------------------------------------------------
 .../java/data/AnyObjectDataBinderImpl.java      | 28 +++++++++++---------
 .../java/data/UserDataBinderImpl.java           | 28 +++++++++++---------
 2 files changed, 32 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/1c1db240/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 0a477cf..7494009 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
@@ -170,8 +170,9 @@ public class AnyObjectDataBinderImpl extends 
AbstractAnyDataBinder implements An
             
assignableCond.setRealmFullPath(anyObject.getRealm().getFullPath());
 
             // relationships
-            List<AnyObject> assignableAnyObjects =
-                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.ANY_OBJECT);
+            Collection<String> assignableAnyObjects = CollectionUtils.collect(
+                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.ANY_OBJECT),
+                    EntityUtils.keyTransformer());
 
             for (RelationshipTO relationshipTO : 
anyObjectTO.getRelationships()) {
                 if (StringUtils.isBlank(relationshipTO.getRightType())
@@ -187,7 +188,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)) {
+                    } else if 
(assignableAnyObjects.contains(otherEnd.getKey())) {
                         RelationshipType relationshipType = 
relationshipTypeDAO.find(relationshipTO.getType());
                         if (relationshipType == null) {
                             LOG.debug("Ignoring invalid relationship type {}", 
relationshipTO.getType());
@@ -211,8 +212,9 @@ public class AnyObjectDataBinderImpl extends 
AbstractAnyDataBinder implements An
             }
 
             // memberships
-            List<Group> assignableGroups =
-                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.GROUP);
+            Collection<String> assignableGroups = CollectionUtils.collect(
+                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.GROUP),
+                    EntityUtils.keyTransformer());
 
             for (MembershipTO membershipTO : anyObjectTO.getMemberships()) {
                 Group group = membershipTO.getRightKey() == null
@@ -221,7 +223,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)) {
+                } else if (assignableGroups.contains(group.getKey())) {
                     AMembership membership = 
entityFactory.newEntity(AMembership.class);
                     membership.setRightEnd(group);
                     membership.setLeftEnd(anyObject);
@@ -283,8 +285,9 @@ public class AnyObjectDataBinderImpl extends 
AbstractAnyDataBinder implements An
         Set<String> toBeProvisioned = new HashSet<>();
 
         // relationships
-        List<AnyObject> assignableAnyObjects =
-                searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), 
AnyTypeKind.ANY_OBJECT);
+        Collection<String> assignableAnyObjects = CollectionUtils.collect(
+                searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), 
AnyTypeKind.ANY_OBJECT),
+                EntityUtils.keyTransformer());
 
         for (RelationshipPatch patch : anyObjectPatch.getRelationships()) {
             if (patch.getRelationshipTO() != null) {
@@ -315,7 +318,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)) {
+                            } else if 
(assignableAnyObjects.contains(otherEnd.getKey())) {
                                 relationship = 
entityFactory.newEntity(ARelationship.class);
                                 relationship.setType(relationshipType);
                                 relationship.setRightEnd(otherEnd);
@@ -342,8 +345,9 @@ public class AnyObjectDataBinderImpl extends 
AbstractAnyDataBinder implements An
         SyncopeClientException invalidValues = 
SyncopeClientException.build(ClientExceptionType.InvalidValues);
 
         // memberships
-        List<Group> assignableGroups =
-                searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), 
AnyTypeKind.GROUP);
+        Collection<String> assignableGroups = CollectionUtils.collect(
+                searchDAO.searchAssignable(anyObject.getRealm().getFullPath(), 
AnyTypeKind.GROUP),
+                EntityUtils.keyTransformer());
 
         for (MembershipPatch membPatch : anyObjectPatch.getMemberships()) {
             if (membPatch.getGroup() != null) {
@@ -363,7 +367,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)) {
+                    } else if (assignableGroups.contains(group.getKey())) {
                         membership = 
entityFactory.newEntity(AMembership.class);
                         membership.setRightEnd(group);
                         membership.setLeftEnd(anyObject);

http://git-wip-us.apache.org/repos/asf/syncope/blob/1c1db240/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 11396d7..eeef4fd 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
@@ -196,14 +196,15 @@ public class UserDataBinderImpl extends 
AbstractAnyDataBinder implements UserDat
             assignableCond.setRealmFullPath(user.getRealm().getFullPath());
 
             // relationships
-            List<AnyObject> assignableAnyObjects =
-                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.ANY_OBJECT);
+            Collection<String> assignableAnyObjects = CollectionUtils.collect(
+                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.ANY_OBJECT),
+                    EntityUtils.keyTransformer());
 
             for (RelationshipTO relationshipTO : userTO.getRelationships()) {
                 AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getRightKey());
                 if (otherEnd == null) {
                     LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getRightKey());
-                } else if (assignableAnyObjects.contains(otherEnd)) {
+                } else if (assignableAnyObjects.contains(otherEnd.getKey())) {
                     RelationshipType relationshipType = 
relationshipTypeDAO.find(relationshipTO.getType());
                     if (relationshipType == null) {
                         LOG.debug("Ignoring invalid relationship type {}", 
relationshipTO.getType());
@@ -227,8 +228,9 @@ public class UserDataBinderImpl extends 
AbstractAnyDataBinder implements UserDat
             }
 
             // memberships
-            List<Group> assignableGroups =
-                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.GROUP);
+            Collection<String> assignableGroups = CollectionUtils.collect(
+                    searchDAO.search(SearchCond.getLeafCond(assignableCond), 
AnyTypeKind.GROUP),
+                    EntityUtils.keyTransformer());
 
             for (MembershipTO membershipTO : userTO.getMemberships()) {
                 Group group = membershipTO.getRightKey() == null
@@ -237,7 +239,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)) {
+                } else if (assignableGroups.contains(group.getKey())) {
                     UMembership membership = 
entityFactory.newEntity(UMembership.class);
                     membership.setRightEnd(group);
                     membership.setLeftEnd(user);
@@ -389,8 +391,9 @@ public class UserDataBinderImpl extends 
AbstractAnyDataBinder implements UserDat
         Set<String> toBeProvisioned = new HashSet<>();
 
         // relationships
-        List<AnyObject> assignableAnyObjects =
-                searchDAO.searchAssignable(user.getRealm().getFullPath(), 
AnyTypeKind.ANY_OBJECT);
+        Collection<String> assignableAnyObjects = CollectionUtils.collect(
+                searchDAO.searchAssignable(user.getRealm().getFullPath(), 
AnyTypeKind.ANY_OBJECT),
+                EntityUtils.keyTransformer());
 
         for (RelationshipPatch patch : userPatch.getRelationships()) {
             if (patch.getRelationshipTO() != null) {
@@ -411,7 +414,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)) {
+                        } else if 
(assignableAnyObjects.contains(otherEnd.getKey())) {
                             relationship = 
entityFactory.newEntity(URelationship.class);
                             relationship.setType(relationshipType);
                             relationship.setRightEnd(otherEnd);
@@ -437,8 +440,9 @@ public class UserDataBinderImpl extends 
AbstractAnyDataBinder implements UserDat
         SyncopeClientException invalidValues = 
SyncopeClientException.build(ClientExceptionType.InvalidValues);
 
         // memberships
-        List<Group> assignableGroups =
-                searchDAO.searchAssignable(user.getRealm().getFullPath(), 
AnyTypeKind.GROUP);
+        Collection<String> assignableGroups = CollectionUtils.collect(
+                searchDAO.searchAssignable(user.getRealm().getFullPath(), 
AnyTypeKind.GROUP),
+                EntityUtils.keyTransformer());
 
         for (MembershipPatch membPatch : userPatch.getMemberships()) {
             if (membPatch.getGroup() != null) {
@@ -459,7 +463,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)) {
+                    } else if (assignableGroups.contains(group.getKey())) {
                         membership = 
entityFactory.newEntity(UMembership.class);
                         membership.setRightEnd(group);
                         membership.setLeftEnd(user);

Reply via email to