syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject [16/26] syncope git commit: [SYNCOPE-691] change prepareAttribute method to fix the issue
Date Thu, 10 Sep 2015 12:37:46 GMT
[SYNCOPE-691] change prepareAttribute method to fix the issue


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

Branch: refs/heads/SYNCOPE-156
Commit: 87e75438173ff19b8589af7347bcf0a8b560710b
Parents: 8dd58bc
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Mon Sep 7 15:39:01 2015 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Mon Sep 7 15:39:01 2015 +0200

----------------------------------------------------------------------
 .../persistence/beans/AbstractDerSchema.java    |   3 +
 .../persistence/beans/AbstractNormalSchema.java |   3 +
 .../core/persistence/beans/AbstractSchema.java  |   8 ++
 .../persistence/beans/AbstractVirSchema.java    |   3 +
 .../apache/syncope/core/util/MappingUtil.java   |  13 ++-
 .../syncope/core/rest/VirAttrTestITCase.java    | 100 ++++++++++++++++++-
 6 files changed, 121 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerSchema.java
b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerSchema.java
index a810045..0c7aec4 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerSchema.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractDerSchema.java
@@ -54,6 +54,7 @@ public abstract class AbstractDerSchema extends AbstractSchema {
         this.expression = expression;
     }
 
+    @Override
     public AttributeSchemaType getType() {
         return AttributeSchemaType.String;
     }
@@ -62,6 +63,7 @@ public abstract class AbstractDerSchema extends AbstractSchema {
         return Boolean.FALSE.toString().toLowerCase();
     }
 
+    @Override
     public boolean isMultivalue() {
         return Boolean.TRUE;
     }
@@ -70,6 +72,7 @@ public abstract class AbstractDerSchema extends AbstractSchema {
         return Boolean.FALSE;
     }
 
+    @Override
     public boolean isReadonly() {
         return Boolean.FALSE;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractNormalSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractNormalSchema.java
b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractNormalSchema.java
index 2d0755c..d6f95e5 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractNormalSchema.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractNormalSchema.java
@@ -115,6 +115,7 @@ public abstract class AbstractNormalSchema extends AbstractSchema {
         this.name = name;
     }
 
+    @Override
     public AttributeSchemaType getType() {
         return type;
     }
@@ -131,6 +132,7 @@ public abstract class AbstractNormalSchema extends AbstractSchema {
         this.mandatoryCondition = mandatoryCondition;
     }
 
+    @Override
     public boolean isMultivalue() {
         return isBooleanAsInteger(multivalue);
     }
@@ -147,6 +149,7 @@ public abstract class AbstractNormalSchema extends AbstractSchema {
         this.uniqueConstraint = getBooleanAsInteger(uniquevalue);
     }
 
+    @Override
     public boolean isReadonly() {
         return isBooleanAsInteger(readonly);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
index 8028b10..410a503 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractSchema.java
@@ -18,6 +18,8 @@
  */
 package org.apache.syncope.core.persistence.beans;
 
+import org.apache.syncope.common.types.AttributeSchemaType;
+
 public abstract class AbstractSchema extends AbstractBaseBean {
 
     private static final long serialVersionUID = 2251957673265528044L;
@@ -25,4 +27,10 @@ public abstract class AbstractSchema extends AbstractBaseBean {
     public abstract String getName();
 
     public abstract void setName(String name);
+
+    public abstract AttributeSchemaType getType();
+
+    public abstract boolean isMultivalue();
+
+    public abstract boolean isReadonly();
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractVirSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractVirSchema.java
b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractVirSchema.java
index 1f0f157..ec0312e 100644
--- a/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractVirSchema.java
+++ b/core/src/main/java/org/apache/syncope/core/persistence/beans/AbstractVirSchema.java
@@ -55,6 +55,7 @@ public abstract class AbstractVirSchema extends AbstractSchema {
         this.name = name;
     }
 
+    @Override
     public AttributeSchemaType getType() {
         return AttributeSchemaType.String;
     }
@@ -63,6 +64,7 @@ public abstract class AbstractVirSchema extends AbstractSchema {
         return Boolean.FALSE.toString().toLowerCase();
     }
 
+    @Override
     public boolean isMultivalue() {
         return Boolean.TRUE;
     }
@@ -71,6 +73,7 @@ public abstract class AbstractVirSchema extends AbstractSchema {
         return Boolean.FALSE;
     }
 
+    @Override
     public boolean isReadonly() {
         return isBooleanAsInteger(readonly);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java b/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
index f6dc331..a504dc2 100644
--- a/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
+++ b/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
@@ -43,10 +43,9 @@ import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
 import org.apache.syncope.core.persistence.beans.AbstractAttributable;
 import org.apache.syncope.core.persistence.beans.AbstractDerAttr;
 import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
-import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
+import org.apache.syncope.core.persistence.beans.AbstractSchema;
 import org.apache.syncope.core.persistence.beans.AbstractSubject;
 import org.apache.syncope.core.persistence.beans.AbstractVirAttr;
-import org.apache.syncope.core.persistence.beans.AbstractVirSchema;
 import org.apache.syncope.core.persistence.beans.ExternalResource;
 import org.apache.syncope.core.persistence.beans.membership.MDerSchema;
 import org.apache.syncope.core.persistence.beans.membership.MSchema;
@@ -209,8 +208,8 @@ public final class MappingUtil {
             }
         }
 
-        final Attribute accountIdExtAttr =
-                AttributeUtil.find(attrUtil.getAccountIdItem(resource).getExtAttrName(),
attributes);
+        final Attribute accountIdExtAttr = AttributeUtil.find(attrUtil.getAccountIdItem(resource).getExtAttrName(),
+                attributes);
         if (accountIdExtAttr != null) {
             attributes.remove(accountIdExtAttr);
             attributes.add(AttributeBuilder.build(attrUtil.getAccountIdItem(resource).getExtAttrName(),
accountId));
@@ -287,7 +286,7 @@ public final class MappingUtil {
                 resource, mapItem, attributables, vAttrsToBeRemoved, vAttrsToBeUpdated, membVAttrsToBeRemoved,
                 membVAttrsToBeUpdated);
 
-        AbstractNormalSchema schema = null;
+        AbstractSchema schema = null;
         boolean readOnlyVirSchema = false;
         AttributeSchemaType schemaType;
         final Map.Entry<String, Attribute> result;
@@ -306,9 +305,9 @@ public final class MappingUtil {
             case RoleVirtualSchema:
             case MembershipVirtualSchema:
                 VirSchemaDAO virSchemaDAO = context.getBean(VirSchemaDAO.class);
-                AbstractVirSchema virSchema = virSchemaDAO.find(mapItem.getIntAttrName(),
+                schema = virSchemaDAO.find(mapItem.getIntAttrName(),
                         MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
-                readOnlyVirSchema = (virSchema != null && virSchema.isReadonly());
+                readOnlyVirSchema = (schema != null && schema.isReadonly());
                 schemaType = AttributeSchemaType.String;
                 break;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/87e75438/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java
index 5c72114..e065998 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java
@@ -23,7 +23,9 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -100,8 +102,8 @@ public class VirAttrTestITCase extends AbstractTest {
         assertEquals(RESOURCE_NAME_WS2, userTO.getPropagationStatusTOs().get(0).getResource());
         assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationStatusTOs().get(0).getStatus());
 
-        ConnObjectTO connObjectTO =
-                resourceService.getConnectorObject(RESOURCE_NAME_WS2, SubjectType.USER, userTO.getId());
+        ConnObjectTO connObjectTO = resourceService.getConnectorObject(RESOURCE_NAME_WS2,
SubjectType.USER, userTO.
+                getId());
         assertNotNull(connObjectTO);
         assertEquals("virtualvalue", connObjectTO.getAttrMap().get("NAME").getValues().get(0));
         // ----------------------------------
@@ -869,4 +871,98 @@ public class VirAttrTestITCase extends AbstractTest {
         resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
         // -------------------------------------------
     }
+
+    @Test
+    public void issueSYNCOPE691() {
+        final String res = RESOURCE_NAME_LDAP + "691";
+
+        ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
+        ldap.setName(res);
+
+        try {
+            List<MappingItemTO> toBeRemoved = new ArrayList<MappingItemTO>();
+
+            // change mapping of resource-csv
+            for (MappingItemTO item : ldap.getUmapping().getItems()) {
+                if ("mail".equals(item.getExtAttrName())) {
+                    toBeRemoved.add(item);
+                }
+            }
+
+            ldap.getUmapping().getItems().removeAll(toBeRemoved);
+
+            final MappingItemTO mail = new MappingItemTO();
+            // unset internal attribute mail and set virtual attribute virtualdata as mapped
to external email
+            mail.setIntMappingType(IntMappingType.UserVirtualSchema);
+            mail.setIntAttrName("virtualdata");
+            mail.setPurpose(MappingPurpose.BOTH);
+            mail.setExtAttrName("mail");
+
+            ldap.getUmapping().getItems().add(mail);
+
+            resourceService.create(ldap);
+
+            ldap = resourceService.read(res);
+            assertNotNull(ldap.getUmapping());
+
+            boolean found = false;
+            for (MappingItemTO item : ldap.getUmapping().getItems()) {
+                if ("mail".equals(item.getExtAttrName()) && "virtualdata".equals(item.getIntAttrName()))
{
+                    found = true;
+                }
+            }
+
+            assertTrue(found);
+
+            // create a new user
+            UserTO userTO = UserTestITCase.getUniqueSampleTO("syncope691@syncope.apache.org");
+            userTO.getResources().clear();
+            userTO.getMemberships().clear();
+            userTO.getDerAttrs().clear();
+            userTO.getVirAttrs().clear();
+
+            final AttributeTO emailTO = new AttributeTO();
+            emailTO.setSchema("virtualdata");
+            emailTO.getValues().add("test@issue691.dom1.org");
+            emailTO.getValues().add("test@issue691.dom2.org");
+
+            userTO.getVirAttrs().add(emailTO);
+            // assign resource-csv to user
+            userTO.getResources().add(res);
+            // save user
+            UserTO created = createUser(userTO);
+            // make std controls about user
+            assertNotNull(created);
+            assertTrue(res.equals(created.getResources().iterator().next()));
+
+            assertEquals(2, created.getVirAttrs().iterator().next().getValues().size(), 0);
+            assertTrue(created.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom1.org"));
+            assertTrue(created.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom2.org"));
+
+            // update user
+            UserMod userMod = new UserMod();
+            userMod.setId(created.getId());
+            //modify virtual attribute
+            userMod.getVirAttrsToRemove().add("virtualdata");
+
+            final AttributeMod emailMod = new AttributeMod();
+            emailMod.setSchema("virtualdata");
+            emailMod.getValuesToBeAdded().add("test@issue691.dom3.org");
+            emailMod.getValuesToBeAdded().add("test@issue691.dom4.org");
+
+            userMod.getVirAttrsToUpdate().add(emailMod);
+
+            final UserTO updated = updateUser(userMod);
+            assertNotNull(updated);
+            assertEquals(2, updated.getVirAttrs().iterator().next().getValues().size(), 0);
+            assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom3.org"));
+            assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom4.org"));
+        } finally {
+            try {
+                resourceService.delete(res);
+            } catch (Exception ignore) {
+                // ignore
+            }
+        }
+    }
 }


Mime
View raw message