syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject syncope git commit: [SYNCOPE-888] improves mapped internal attribute evaluation
Date Mon, 18 Jul 2016 09:07:15 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 0016c6ac2 -> 5b4cf31e5


[SYNCOPE-888] improves mapped internal attribute evaluation


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

Branch: refs/heads/master
Commit: 5b4cf31e55e2fe245f18f08e2e5e085a7463a004
Parents: 0016c6a
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Mon Jul 18 11:06:35 2016 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Mon Jul 18 11:06:35 2016 +0200

----------------------------------------------------------------------
 .../java/data/ResourceDataBinderImpl.java       | 149 ++++++++++---------
 .../apache/syncope/fit/core/ResourceITCase.java |  41 ++++-
 2 files changed, 119 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/5b4cf31e/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderImpl.java
index 1261b58..53d121c 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ResourceDataBinderImpl.java
@@ -299,8 +299,8 @@ public class ResourceDataBinderImpl implements ResourceDataBinder {
 
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
         SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
-        SyncopeClientException requiredValuesMissing =
-                SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
+        SyncopeClientException requiredValuesMissing = SyncopeClientException.build(
+                ClientExceptionType.RequiredValuesMissing);
 
         for (MappingItemTO itemTO : mappingTO.getItems()) {
             if (itemTO == null) {
@@ -314,87 +314,96 @@ public class ResourceDataBinderImpl implements ResourceDataBinder {
                         itemTO.getIntAttrName(),
                         mapping.getProvision().getAnyType().getKind());
 
-                boolean allowed = true;
-                if (intAttrName.getSchemaType() != null
-                        && intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject()
== null) {
-
-                    switch (intAttrName.getSchemaType()) {
-                        case PLAIN:
-                            allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
-                            break;
-
-                        case DERIVED:
-                            allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
-                            break;
-
-                        case VIRTUAL:
-                            allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
-                            break;
-
-                        default:
+                if (intAttrName.getSchemaType() == null && intAttrName.getField()
== null) {
+                    LOG.error("'{}' not existing", itemTO.getIntAttrName());
+                    invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not
existing");
+                } else {
+                    boolean allowed = true;
+                    if (intAttrName.getSchemaType() != null
+                            && intAttrName.getEnclosingGroup() == null
+                            && intAttrName.getRelatedAnyObject() == null) {
+                        switch (intAttrName.getSchemaType()) {
+                            case PLAIN:
+                                allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
+                                break;
+
+                            case DERIVED:
+                                allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
+                                break;
+
+                            case VIRTUAL:
+                                allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
+                                break;
+
+                            default:
+                        }
                     }
-                }
 
-                if (allowed) {
-                    // no mandatory condition implies mandatory condition false
-                    if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null
-                            ? "false" : itemTO.getMandatoryCondition())) {
+                    if (allowed) {
+                        // no mandatory condition implies mandatory condition false
+                        if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() ==
null
+                                ? "false" : itemTO.getMandatoryCondition())) {
 
-                        SyncopeClientException invalidMandatoryCondition =
-                                SyncopeClientException.build(ClientExceptionType.InvalidValues);
-                        invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
-                        scce.addException(invalidMandatoryCondition);
-                    }
-
-                    MappingItem item = SerializationUtils.clone(prototype);
-                    BeanUtils.copyProperties(itemTO, item, MAPPINGITEM_IGNORE_PROPERTIES);
-                    item.setMapping(mapping);
-                    if (item.isConnObjectKey()) {
-                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
-                            invalidMapping.getElements().add("Virtual attributes cannot be
set as ConnObjectKey");
+                            SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(
+                                    ClientExceptionType.InvalidValues);
+                            invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
+                            scce.addException(invalidMandatoryCondition);
                         }
-                        if ("password".equals(intAttrName.getField())) {
-                            invalidMapping.getElements().add("Password attributes cannot
be set as ConnObjectKey");
-                        }
-
-                        mapping.setConnObjectKeyItem(item);
-                    } else {
-                        mapping.add(item);
-                    }
 
-                    if (intAttrName.getEnclosingGroup() != null
-                            && item.getPurpose() != MappingPurpose.PROPAGATION) {
+                        MappingItem item = SerializationUtils.clone(prototype);
+                        BeanUtils.copyProperties(itemTO, item, MAPPINGITEM_IGNORE_PROPERTIES);
+                        item.setMapping(mapping);
+                        if (item.isConnObjectKey()) {
+                            if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
+                                invalidMapping.getElements().
+                                        add("Virtual attributes cannot be set as ConnObjectKey");
+                            }
+                            if ("password".equals(intAttrName.getField())) {
+                                invalidMapping.getElements().add(
+                                        "Password attributes cannot be set as ConnObjectKey");
+                            }
+
+                            mapping.setConnObjectKeyItem(item);
+                        } else {
+                            mapping.add(item);
+                        }
 
-                        invalidMapping.getElements().add(
-                                "Only " + MappingPurpose.PROPAGATION.name() + " allowed when
referring to groups");
-                    }
-                    if (intAttrName.getRelatedAnyObject() != null
-                            && item.getPurpose() != MappingPurpose.PROPAGATION) {
+                        if (intAttrName.getEnclosingGroup() != null
+                                && item.getPurpose() != MappingPurpose.PROPAGATION)
{
 
-                        invalidMapping.getElements().add(
-                                "Only " + MappingPurpose.PROPAGATION.name() + " allowed when
referring to any objects");
-                    }
-                    if (intAttrName.getSchemaType() == SchemaType.DERIVED
-                            && item.getPurpose() != MappingPurpose.PROPAGATION) {
+                            invalidMapping.getElements().add(
+                                    "Only " + MappingPurpose.PROPAGATION.name()
+                                    + " allowed when referring to groups");
+                        }
+                        if (intAttrName.getRelatedAnyObject() != null
+                                && item.getPurpose() != MappingPurpose.PROPAGATION)
{
 
-                        invalidMapping.getElements().add(
-                                "Only " + MappingPurpose.PROPAGATION.name() + " allowed for
derived");
-                    }
-                    if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
-                        if (item.getPurpose() != MappingPurpose.PROPAGATION) {
                             invalidMapping.getElements().add(
-                                    "Only " + MappingPurpose.PROPAGATION.name() + " allowed
for virtual");
+                                    "Only " + MappingPurpose.PROPAGATION.name()
+                                    + " allowed when referring to any objects");
                         }
+                        if (intAttrName.getSchemaType() == SchemaType.DERIVED
+                                && item.getPurpose() != MappingPurpose.PROPAGATION)
{
 
-                        VirSchema schema = virSchemaDAO.find(item.getIntAttrName());
-                        if (schema != null && schema.getProvision().equals(item.getMapping().getProvision()))
{
                             invalidMapping.getElements().add(
-                                    "No need to map virtual schema on linking resource");
+                                    "Only " + MappingPurpose.PROPAGATION.name() + " allowed
for derived");
+                        }
+                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
+                            if (item.getPurpose() != MappingPurpose.PROPAGATION) {
+                                invalidMapping.getElements().add(
+                                        "Only " + MappingPurpose.PROPAGATION.name() + " allowed
for virtual");
+                            }
+
+                            VirSchema schema = virSchemaDAO.find(item.getIntAttrName());
+                            if (schema != null && schema.getProvision().equals(item.getMapping().getProvision()))
{
+                                invalidMapping.getElements().add(
+                                        "No need to map virtual schema on linking resource");
+                            }
                         }
+                    } else {
+                        LOG.error("'{}' not allowed", itemTO.getIntAttrName());
+                        invalidMapping.getElements().add("'" + itemTO.getIntAttrName() +
"' not allowed");
                     }
-                } else {
-                    LOG.error("{} not allowed", itemTO.getIntAttrName());
-                    invalidMapping.getElements().add(itemTO.getIntAttrName() + " not allowed");
                 }
             }
         }
@@ -476,7 +485,7 @@ public class ResourceDataBinderImpl implements ResourceDataBinder {
             orgUnitTO.setSyncToken(orgUnit.getSerializedSyncToken());
             orgUnitTO.setExtAttrName(orgUnit.getExtAttrName());
             orgUnitTO.setConnObjectLink(orgUnit.getConnObjectLink());
-            
+
             resourceTO.setOrgUnit(orgUnitTO);
         }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/5b4cf31e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ResourceITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ResourceITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ResourceITCase.java
index 8fa5aca..b0b03eb 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ResourceITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ResourceITCase.java
@@ -663,7 +663,7 @@ public class ResourceITCase extends AbstractITCase {
         mapping.setConnObjectKeyItem(item);
 
         item = new MappingItemTO();
-        item.setIntAttrName("owner");
+        item.setIntAttrName("userOwner");
         item.setExtAttrName("owner");
         item.setPurpose(MappingPurpose.BOTH);
         mapping.add(item);
@@ -759,4 +759,43 @@ public class ResourceITCase extends AbstractITCase {
             assertEquals(ClientExceptionType.InvalidMapping, e.getType());
         }
     }
+
+    @Test
+    public void issueSYNCOPE888() {
+        String resourceKey = RESOURCE_NAME_CREATE_WRONG;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceKey);
+        resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
+
+        ProvisionTO provisionTO = new ProvisionTO();
+        provisionTO.setAnyType(AnyTypeKind.USER.name());
+        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
+        resourceTO.getProvisions().add(provisionTO);
+
+        MappingTO mapping = new MappingTO();
+        provisionTO.setMapping(mapping);
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntAttrName("key");
+        item.setExtAttrName("userId");
+        item.setConnObjectKey(true);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(item);
+
+        // Add mapping for a not existing internal attribute
+        item = new MappingItemTO();
+        item.setIntAttrName("locatio");
+        item.setExtAttrName("location");
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.add(item);
+
+        try {
+            createResource(resourceTO);
+            fail("Create should not have worked");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidMapping, e.getType());
+            assertEquals(1, e.getElements().size());
+            assertEquals("'locatio' not existing", e.getElements().iterator().next());
+        }
+    }
 }


Mime
View raw message