syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdisabat...@apache.org
Subject [1/4] syncope git commit: [SYNCOPE-645] Provide a validator for resource user mapping
Date Thu, 19 Feb 2015 11:50:12 GMT
Repository: syncope
Updated Branches:
  refs/heads/master fc06e742d -> 9cbeffd39


[SYNCOPE-645] Provide a validator for resource user mapping


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

Branch: refs/heads/master
Commit: 8c38a41fff9c87f7eb62d43303926094f53909de
Parents: d01ed12
Author: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Authored: Thu Feb 19 09:35:29 2015 +0100
Committer: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Committed: Thu Feb 19 09:35:29 2015 +0100

----------------------------------------------------------------------
 .../entity/ExternalResourceValidator.java       | 12 ++++++++++
 .../core/persistence/dao/ResourceTest.java      | 23 ++++++++++++++++++++
 2 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/8c38a41f/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/ExternalResourceValidator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/ExternalResourceValidator.java
b/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/ExternalResourceValidator.java
index eed7add..124033d 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/ExternalResourceValidator.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/ExternalResourceValidator.java
@@ -20,11 +20,13 @@ package org.apache.syncope.core.persistence.validation.entity;
 
 import javax.validation.ConstraintValidatorContext;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.types.AttributableType;
 import org.apache.syncope.common.types.EntityViolationType;
 import org.apache.syncope.core.persistence.beans.AbstractMapping;
 import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
 import org.apache.syncope.core.persistence.beans.ExternalResource;
 import org.apache.syncope.core.propagation.PropagationActions;
+import org.apache.syncope.core.persistence.beans.user.UMapping;
 
 public class ExternalResourceValidator extends AbstractValidator<ExternalResourceCheck,
ExternalResource> {
 
@@ -74,6 +76,16 @@ public class ExternalResourceValidator extends AbstractValidator<ExternalResourc
             return false;
         }
 
+        final AbstractMappingItem accountId = mapping.getAccountIdItem();
+        if (mapping instanceof UMapping 
+                && AttributableType.ROLE == accountId.getIntMappingType().getAttributableType())
{
+            context.buildConstraintViolationWithTemplate(
+                    getTemplate(EntityViolationType.InvalidMapping,
+                            "Role attribute as accountId is not permitted")).
+                    addNode("attributableType").addConstraintViolation();
+            return false;
+        }
+
         boolean isValid = true;
 
         int passwords = 0;

http://git-wip-us.apache.org/repos/asf/syncope/blob/8c38a41f/core/src/test/java/org/apache/syncope/core/persistence/dao/ResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/persistence/dao/ResourceTest.java
b/core/src/test/java/org/apache/syncope/core/persistence/dao/ResourceTest.java
index cd6f735..b5a7527 100644
--- a/core/src/test/java/org/apache/syncope/core/persistence/dao/ResourceTest.java
+++ b/core/src/test/java/org/apache/syncope/core/persistence/dao/ResourceTest.java
@@ -263,4 +263,27 @@ public class ResourceTest extends AbstractDAOTest {
             assertTrue(e.hasViolation(EntityViolationType.InvalidName));
         }
     }
+
+    @Test(expected = InvalidEntityException.class)
+    public void issueSYNCOPE645() {
+        ExternalResource resource = new ExternalResource();
+        resource.setName("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        UMapping mapping = new UMapping();
+        resource.setUmapping(mapping);
+
+        final UMappingItem item = new UMappingItem();
+        item.setIntAttrName("icon");
+        item.setExtAttrName("icon");
+        item.setIntMappingType(IntMappingType.RoleSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        // save the resource
+        ExternalResource actual = resourceDAO.save(resource);
+        assertNotNull(actual);
+    }
 }


Mime
View raw message