You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by md...@apache.org on 2013/11/18 09:13:31 UTC

svn commit: r1542946 - in /syncope/trunk: build-tools/src/main/resources/ core/src/main/java/org/apache/syncope/core/rest/data/ core/src/main/java/org/apache/syncope/core/util/ core/src/test/java/org/apache/syncope/core/persistence/dao/ core/src/test/j...

Author: mdisabatino
Date: Mon Nov 18 08:13:31 2013
New Revision: 1542946

URL: http://svn.apache.org/r1542946
Log:
SYNCOPE-436 Merge from 1_1_X

Modified:
    syncope/trunk/build-tools/src/main/resources/content.ldif
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
    syncope/trunk/core/src/test/resources/content.xml

Modified: syncope/trunk/build-tools/src/main/resources/content.ldif
URL: http://svn.apache.org/viewvc/syncope/trunk/build-tools/src/main/resources/content.ldif?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/build-tools/src/main/resources/content.ldif (original)
+++ syncope/trunk/build-tools/src/main/resources/content.ldif Mon Nov 18 08:13:31 2013
@@ -43,3 +43,4 @@ mail: syncFromLDAP@syncope.apache.org
 sn: Surname
 uid: syncFromLDAP
 userpassword:: cGFzc3dvcmQxMjM=
+givenname: syncFromLDAP

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java Mon Nov 18 08:13:31 2013
@@ -189,10 +189,6 @@ public abstract class AbstractAttributab
 
             if (virtualSchema == null) {
                 LOG.debug("Ignoring invalid virtual schema {}", virSchemaName);
-            } else if (virtualSchema.isReadonly()) {
-                virtualSchema = null;
-
-                LOG.debug("Ignoring readonly virtual schema {}", virtualSchema);
             }
         }
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java Mon Nov 18 08:13:31 2013
@@ -32,6 +32,8 @@ import org.apache.commons.lang3.StringUt
 import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.types.IntMappingType;
 import org.apache.syncope.common.types.AttributeSchemaType;
+import static org.apache.syncope.common.types.IntMappingType.RoleVirtualSchema;
+import static org.apache.syncope.common.types.IntMappingType.UserVirtualSchema;
 import org.apache.syncope.core.connid.PasswordGenerator;
 import org.apache.syncope.core.persistence.beans.AbstractAttr;
 import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
@@ -40,6 +42,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
 import org.apache.syncope.core.persistence.beans.AbstractNormalSchema;
 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;
@@ -55,6 +58,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.user.USchema;
 import org.apache.syncope.core.persistence.beans.user.UVirSchema;
 import org.apache.syncope.core.persistence.dao.SchemaDAO;
+import org.apache.syncope.core.persistence.dao.VirSchemaDAO;
 import org.identityconnectors.framework.common.FrameworkUtil;
 import org.identityconnectors.framework.common.objects.Attribute;
 import org.identityconnectors.framework.common.objects.AttributeBuilder;
@@ -163,16 +167,27 @@ public final class MappingUtil {
 
         AbstractNormalSchema schema = null;
         AttributeSchemaType schemaType;
+        Map.Entry<String, Attribute> result = null;
+        final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
         switch (mapItem.getIntMappingType()) {
             case UserSchema:
             case RoleSchema:
             case MembershipSchema:
-                final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
                 final SchemaDAO schemaDAO = context.getBean(SchemaDAO.class);
                 schema = schemaDAO.find(mapItem.getIntAttrName(),
                         MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
                 schemaType = schema == null ? AttributeSchemaType.String : schema.getType();
                 break;
+            case UserVirtualSchema:
+            case RoleVirtualSchema:
+                final VirSchemaDAO virSchemaDAO = context.getBean(VirSchemaDAO.class);
+                final AbstractVirSchema virSchema = virSchemaDAO.find(mapItem.getIntAttrName(),
+                        MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
+                if (virSchema.isReadonly()) {
+                    return result;
+                }
+                schemaType = AttributeSchemaType.String;
+                break;
 
             default:
                 schemaType = AttributeSchemaType.String;
@@ -200,8 +215,6 @@ public final class MappingUtil {
             }
         }
 
-        Map.Entry<String, Attribute> result;
-
         if (mapItem.isAccountid()) {
             result = new AbstractMap.SimpleEntry<String, Attribute>(objValues.iterator().next().toString(), null);
         } else if (mapItem.isPassword() && subject instanceof SyncopeUser) {

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/persistence/dao/VirSchemaTest.java Mon Nov 18 08:13:31 2013
@@ -45,7 +45,7 @@ public class VirSchemaTest extends Abstr
     @Test
     public void findAll() {
         List<UVirSchema> list = virSchemaDAO.findAll(UVirSchema.class);
-        assertEquals(1, list.size());
+        assertEquals(2, list.size());
     }
 
     @Test

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Mon Nov 18 08:13:31 2013
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import javax.ws.rs.core.Response;
 import org.apache.syncope.common.mod.UserMod;
@@ -57,6 +58,7 @@ import org.apache.syncope.common.types.P
 import org.apache.syncope.common.types.TaskType;
 import org.apache.syncope.common.types.TraceLevel;
 import org.apache.syncope.common.validation.SyncopeClientException;
+import static org.apache.syncope.core.rest.AbstractTest.attributeTO;
 import org.apache.syncope.core.sync.TestSyncActions;
 import org.apache.syncope.core.sync.TestSyncRule;
 import org.apache.syncope.core.sync.impl.SyncJob;
@@ -391,21 +393,28 @@ public class TaskTestITCase extends Abst
         // Update sync task
         SyncTaskTO task = taskService.read(11L);
         assertNotNull(task);
+        
+        //  add role template
+        final UserTO userTemplate = task.getUserTemplate();
+        userTemplate.getResources().add("resource-ldap");
+        userTemplate.getVirAttrs().add(attributeTO("virtualReadOnly", ""));
+
+        task.setUserTemplate(userTemplate);
 
         //  add user template
-        RoleTO template = new RoleTO();
-        template.setParent(8L);
-        template.getRAttrTemplates().add("show");
-        template.getAttrs().add(attributeTO("show", "'true'"));
+        RoleTO roleTemplate = new RoleTO();
+        roleTemplate.setParent(8L);
+        roleTemplate.getRAttrTemplates().add("show");
+        roleTemplate.getAttrs().add(attributeTO("show", "'true'"));
 
-        task.setRoleTemplate(template);
+        task.setRoleTemplate(roleTemplate);
 
         taskService.update(task.getId(), task);
         SyncTaskTO actual = taskService.read(task.getId());
         assertNotNull(actual);
         assertEquals(task.getId(), actual.getId());
-        assertEquals(template, actual.getRoleTemplate());
-        assertEquals(new UserTO(), actual.getUserTemplate());
+        assertEquals(roleTemplate, actual.getRoleTemplate());
+        assertEquals(userTemplate, actual.getUserTemplate());
 
         TaskExecTO execution = execSyncTask(actual.getId(), 20, false);
 
@@ -922,4 +931,35 @@ public class TaskTestITCase extends Abst
 
         assertFalse(taskService.list(TaskType.PROPAGATION).containsAll(after));
     }
+
+    @Test
+    public void issueSYNCOPE436() throws InvalidSearchConditionException {
+
+        SyncTaskTO task = taskService.read(11L);
+        assertNotNull(task);
+
+        final UserTO template = task.getUserTemplate();
+        template.getResources().add("resource-ldap");
+        template.getVirAttrs().add(attributeTO("virtualReadOnly", ""));
+        task.setUserTemplate(template);
+
+        taskService.update(task.getId(), task);
+        TaskExecTO execution = execSyncTask(11L, 50, false);
+
+        final String status = execution.getStatus();
+        assertNotNull(status);
+        assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());
+
+        final AttributableCond usernameLeafCond = new AttributableCond(AttributeCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("syncFromLDAP");
+
+        final List<UserTO> matchingUsers = userService.search(NodeCond.getLeafCond(usernameLeafCond));
+        assertNotNull(matchingUsers);
+        assertEquals(1, matchingUsers.size());
+
+        final UserTO syncUser = matchingUsers.iterator().next();
+        final AttributeTO virAttributeTO = syncUser.getVirAttrMap().get("virtualReadOnly");
+        assertEquals("syncFromLDAP", virAttributeTO.getValues().get(0));
+    }
 }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Mon Nov 18 08:13:31 2013
@@ -73,8 +73,10 @@ import org.apache.syncope.common.util.Co
 import org.apache.syncope.common.validation.SyncopeClientException;
 import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
 import org.apache.syncope.core.persistence.dao.NotFoundException;
+import static org.apache.syncope.core.rest.AbstractTest.attributeTO;
 import org.apache.syncope.core.workflow.ActivitiDetector;
 import org.identityconnectors.framework.common.objects.OperationalAttributes;
+import static org.junit.Assert.assertTrue;
 import org.junit.Assume;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
@@ -2285,5 +2287,17 @@ public class UserTestITCase extends Abst
         assertTrue(userTO.getPropagationStatusTOs().get(0).getFailureReason().
                 startsWith("Not attempted because there are mandatory attributes without value(s): [__PASSWORD__]"));
     }
+    
+    @Test
+    public void issueSYNCOPE436() {
+        UserTO userTO = getUniqueSampleTO("syncope436@syncope.apache.org");
+        userTO.getMemberships().clear();
+        userTO.getResources().clear();
+        userTO.getResources().add(RESOURCE_NAME_LDAP);
+        userTO.getVirAttrs().add(attributeTO("virtualReadOnly", "readOnly"));
+        userTO = createUser(userTO);
+        //Finding no values because the virtual attribute is readonly 
+        assertTrue(userTO.getVirAttrMap().get("virtualReadOnly").getValues().isEmpty());
+    }
 
 }

Modified: syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/resources/content.xml?rev=1542946&r1=1542945&r2=1542946&view=diff
==============================================================================
--- syncope/trunk/core/src/test/resources/content.xml (original)
+++ syncope/trunk/core/src/test/resources/content.xml Mon Nov 18 08:13:31 2013
@@ -282,6 +282,8 @@ under the License.
     
   <UVirAttr id="1000" virSchema_name="virtualdata" owner_id="3"/>
 
+  <UVirSchema name="virtualReadOnly" READONLY="1"/>
+  
   <UDerAttr id="100" derSchema_name="cn" owner_id="3"/>
   <UDerAttr id="101" derSchema_name="cn" owner_id="1"/>
 
@@ -747,6 +749,9 @@ under the License.
   <UMappingItem id="318" accountid="0" password="0" mapping_id="11"
                 extAttrName="mail" intAttrName="userId" intMappingType="UserSchema"
                 mandatoryCondition="false" purpose="BOTH"/>
+  <UMappingItem id="319" accountid="0" password="0" mapping_id="11"
+                  extAttrName="givenname" intAttrName="virtualReadOnly" intMappingType="UserVirtualSchema"
+                  mandatoryCondition="false" purpose="BOTH"/>
   <RMapping id="1" resource_name="resource-ldap"
             accountlink="&apos;cn=&apos; + name + &apos;,ou=groups,o=isp&apos;"/>
   <RMappingItem id="1" accountid="1" password="0" mapping_id="1"