You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2014/11/06 09:46:41 UTC
git commit: [SYNCOPE-598] fixed
Repository: syncope
Updated Branches:
refs/heads/1_2_X 84587034c -> 4d264368e
[SYNCOPE-598] fixed
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4d264368
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4d264368
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4d264368
Branch: refs/heads/1_2_X
Commit: 4d264368ed1df29e13690e9c6b05b651a366f273
Parents: 8458703
Author: fmartelli <fa...@gmail.com>
Authored: Thu Nov 6 09:46:13 2014 +0100
Committer: fmartelli <fa...@gmail.com>
Committed: Thu Nov 6 09:46:13 2014 +0100
----------------------------------------------------------------------
.../impl/AbstractSubjectPushResultHandler.java | 60 +++++-----
.../apache/syncope/core/sync/impl/PushJob.java | 4 +-
.../core/sync/impl/RolePushResultHandler.java | 2 +-
.../syncope/core/rest/TaskTestITCase.java | 119 ++++++++++++++++++-
4 files changed, 151 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/4d264368/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectPushResultHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectPushResultHandler.java b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectPushResultHandler.java
index a34e634..f8cb658 100644
--- a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectPushResultHandler.java
+++ b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectPushResultHandler.java
@@ -73,9 +73,9 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
protected abstract ConnectorObject getRemoteObject(final String accountId);
@Transactional
- public boolean handle(final AbstractSubject subject) {
+ public boolean handle(final long subjectId) {
try {
- doHandle(subject);
+ doHandle(subjectId);
return true;
} catch (JobExecutionException e) {
LOG.error("Synchronization failed", e);
@@ -83,30 +83,30 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
}
}
- protected final void doHandle(final AbstractSubject subject)
+ protected final void doHandle(final long subjectId)
throws JobExecutionException {
if (profile.getResults() == null) {
profile.setResults(new ArrayList<SyncResult>());
}
- final AbstractSubject toBeHandled = getSubject(subject.getId());
+ final AbstractSubject subject = getSubject(subjectId);
- final AttributableUtil attrUtil = AttributableUtil.getInstance(toBeHandled);
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(subject);
final SyncResult result = new SyncResult();
profile.getResults().add(result);
- result.setId(toBeHandled.getId());
+ result.setId(subject.getId());
result.setSubjectType(attrUtil.getType());
- result.setName(getName(toBeHandled));
+ result.setName(getName(subject));
- final Boolean enabled = toBeHandled instanceof SyncopeUser && profile.getSyncTask().isSyncStatus()
- ? ((SyncopeUser) toBeHandled).isSuspended() ? Boolean.FALSE : Boolean.TRUE
+ final Boolean enabled = subject instanceof SyncopeUser && profile.getSyncTask().isSyncStatus()
+ ? ((SyncopeUser) subject).isSuspended() ? Boolean.FALSE : Boolean.TRUE
: null;
LOG.debug("Propagating {} with ID {} towards {}",
- attrUtil.getType(), toBeHandled.getId(), profile.getSyncTask().getResource());
+ attrUtil.getType(), subject.getId(), profile.getSyncTask().getResource());
Object output = null;
Result resultStatus = null;
@@ -138,37 +138,37 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
switch (profile.getSyncTask().getUnmatchingRule()) {
case ASSIGN:
for (PushActions action : profile.getActions()) {
- action.beforeAssign(this.getProfile(), toBeHandled);
+ action.beforeAssign(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformCreate()) {
LOG.debug("PushTask not configured for create");
} else {
- assign(toBeHandled, status);
+ assign(subject, status);
}
break;
case PROVISION:
for (PushActions action : profile.getActions()) {
- action.beforeProvision(this.getProfile(), toBeHandled);
+ action.beforeProvision(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformCreate()) {
LOG.debug("PushTask not configured for create");
} else {
- provision(toBeHandled, status);
+ provision(subject, status);
}
break;
case UNLINK:
for (PushActions action : profile.getActions()) {
- action.beforeUnlink(this.getProfile(), toBeHandled);
+ action.beforeUnlink(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformUpdate()) {
LOG.debug("PushTask not configured for update");
} else {
- link(toBeHandled, true);
+ link(subject, true);
}
break;
@@ -183,60 +183,60 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
switch (profile.getSyncTask().getMatchingRule()) {
case UPDATE:
for (PushActions action : profile.getActions()) {
- action.beforeUpdate(this.getProfile(), toBeHandled);
+ action.beforeUpdate(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformUpdate()) {
LOG.debug("PushTask not configured for update");
} else {
- update(toBeHandled, status);
+ update(subject, status);
}
break;
case DEPROVISION:
for (PushActions action : profile.getActions()) {
- action.beforeDeprovision(this.getProfile(), toBeHandled);
+ action.beforeDeprovision(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformDelete()) {
LOG.debug("PushTask not configured for delete");
} else {
- deprovision(toBeHandled);
+ deprovision(subject);
}
break;
case UNASSIGN:
for (PushActions action : profile.getActions()) {
- action.beforeUnassign(this.getProfile(), toBeHandled);
+ action.beforeUnassign(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformDelete()) {
LOG.debug("PushTask not configured for delete");
} else {
- unassign(toBeHandled);
+ unassign(subject);
}
break;
case LINK:
for (PushActions action : profile.getActions()) {
- action.beforeLink(this.getProfile(), toBeHandled);
+ action.beforeLink(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformUpdate()) {
LOG.debug("PushTask not configured for update");
} else {
- link(toBeHandled, false);
+ link(subject, false);
}
break;
case UNLINK:
for (PushActions action : profile.getActions()) {
- action.beforeUnlink(this.getProfile(), toBeHandled);
+ action.beforeUnlink(this.getProfile(), subject);
}
if (!profile.getSyncTask().isPerformUpdate()) {
LOG.debug("PushTask not configured for update");
} else {
- link(toBeHandled, true);
+ link(subject, true);
}
break;
@@ -246,7 +246,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
}
for (PushActions action : profile.getActions()) {
- action.after(this.getProfile(), toBeHandled, result);
+ action.after(this.getProfile(), subject, result);
}
result.setStatus(SyncResult.Status.SUCCESS);
@@ -258,7 +258,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
resultStatus = AuditElements.Result.FAILURE;
output = e;
- LOG.warn("Error pushing {} towards {}", toBeHandled, profile.getSyncTask().getResource(), e);
+ LOG.warn("Error pushing {} towards {}", subject, profile.getSyncTask().getResource(), e);
throw new JobExecutionException(e);
} finally {
notificationManager.createTasks(
@@ -269,7 +269,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
resultStatus,
beforeObj,
output,
- toBeHandled);
+ subject);
auditManager.audit(
AuditElements.EventCategoryType.PUSH,
AttributableType.USER.name().toLowerCase(),
@@ -278,7 +278,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
resultStatus,
beforeObj,
output,
- toBeHandled);
+ subject);
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/4d264368/core/src/main/java/org/apache/syncope/core/sync/impl/PushJob.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/sync/impl/PushJob.java b/core/src/main/java/org/apache/syncope/core/sync/impl/PushJob.java
index d323fdb..73e1d48 100644
--- a/core/src/main/java/org/apache/syncope/core/sync/impl/PushJob.java
+++ b/core/src/main/java/org/apache/syncope/core/sync/impl/PushJob.java
@@ -116,7 +116,7 @@ public class PushJob extends AbstractSyncJob<PushTask, PushActions> {
for (SyncopeUser localUser : localUsers) {
try {
// user propagation
- uhandler.handle(localUser);
+ uhandler.handle(localUser.getId());
} catch (Exception e) {
LOG.warn("Failure pushing user '{}' on '{}'", localUser, pushTask.getResource(), e);
throw new JobExecutionException("While pushing users on connector", e);
@@ -131,7 +131,7 @@ public class PushJob extends AbstractSyncJob<PushTask, PushActions> {
for (SyncopeRole localRole : localRoles) {
try {
// role propagation
- rhandler.handle(localRole);
+ rhandler.handle(localRole.getId());
} catch (Exception e) {
LOG.warn("Failure pushing role '{}' on '{}'", localRole, pushTask.getResource(), e);
throw new JobExecutionException("While pushing roles on connector", e);
http://git-wip-us.apache.org/repos/asf/syncope/blob/4d264368/core/src/main/java/org/apache/syncope/core/sync/impl/RolePushResultHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/sync/impl/RolePushResultHandler.java b/core/src/main/java/org/apache/syncope/core/sync/impl/RolePushResultHandler.java
index 6c861d4..c29b49e 100644
--- a/core/src/main/java/org/apache/syncope/core/sync/impl/RolePushResultHandler.java
+++ b/core/src/main/java/org/apache/syncope/core/sync/impl/RolePushResultHandler.java
@@ -123,7 +123,7 @@ public class RolePushResultHandler extends AbstractSubjectPushResultHandler {
try {
return roleDataBinder.getRoleFromId(id);
} catch (Exception e) {
- LOG.warn("Error retrieving user {}", id, e);
+ LOG.warn("Error retrieving role {}", id, e);
return null;
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/4d264368/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
index 9428a81..468b8f9 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
@@ -18,7 +18,6 @@
*/
package org.apache.syncope.core.rest;
-import static org.apache.syncope.core.rest.AbstractTest.userService;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -63,14 +62,22 @@ import org.apache.syncope.common.to.SyncTaskTO;
import org.apache.syncope.common.to.TaskExecTO;
import org.apache.syncope.common.to.AbstractTaskTO;
import org.apache.syncope.common.reqres.PagedResult;
+import org.apache.syncope.common.services.ResourceService;
+import org.apache.syncope.common.to.MappingItemTO;
+import org.apache.syncope.common.to.MappingTO;
import org.apache.syncope.common.to.PushTaskTO;
+import org.apache.syncope.common.to.SchemaTO;
import org.apache.syncope.common.to.UserTO;
+import org.apache.syncope.common.types.AttributableType;
+import org.apache.syncope.common.types.AttributeSchemaType;
import org.apache.syncope.common.types.CipherAlgorithm;
import org.apache.syncope.common.types.ConnConfProperty;
import org.apache.syncope.common.types.IntMappingType;
+import org.apache.syncope.common.types.MappingPurpose;
import org.apache.syncope.common.types.MatchingRule;
import org.apache.syncope.common.types.PropagationTaskExecStatus;
import org.apache.syncope.common.types.ResourceDeassociationActionType;
+import org.apache.syncope.common.types.SchemaType;
import org.apache.syncope.common.types.TaskType;
import org.apache.syncope.common.types.TraceLevel;
import org.apache.syncope.common.types.SubjectType;
@@ -1268,4 +1275,114 @@ public class TaskTestITCase extends AbstractTest {
connectorService.update(ldapResource.getConnectorId(), resourceConnector);
deleteUser(updatedUser.getId());
}
+
+ @Test
+ public void issueSYNCOPE598() {
+ // create a new role schema
+ final SchemaTO schemaTO = new SchemaTO();
+ schemaTO.setName("LDAPGroupName" + getUUIDString());
+ schemaTO.setType(AttributeSchemaType.String);
+ schemaTO.setMandatoryCondition("true");
+
+ final SchemaTO newSchemaTO = createSchema(AttributableType.ROLE, SchemaType.NORMAL, schemaTO);
+ assertEquals(schemaTO, newSchemaTO);
+
+ // create a new sample role
+ RoleTO roleTO = new RoleTO();
+ roleTO.setName("all" + getUUIDString());
+ roleTO.setParent(8L);
+
+ roleTO.getRAttrTemplates().add(newSchemaTO.getName());
+ roleTO.getAttrs().add(attributeTO(newSchemaTO.getName(), "all"));
+
+ roleTO = createRole(roleTO);
+ assertNotNull(roleTO);
+
+ String resourceName = "resource-ldap-roleonly";
+ ResourceTO newResourceTO = null;
+
+ try {
+ // Create resource ad-hoc
+ ResourceTO resourceTO = new ResourceTO();
+ resourceTO.setName(resourceName);
+ resourceTO.setConnectorId(105L);
+
+ final MappingTO umapping = new MappingTO();
+ MappingItemTO item = new MappingItemTO();
+ item.setIntMappingType(IntMappingType.Username);
+ item.setExtAttrName("cn");
+ item.setAccountid(true);
+ item.setPurpose(MappingPurpose.PROPAGATION);
+ item.setMandatoryCondition("true");
+ umapping.setAccountIdItem(item);
+
+ item = new MappingItemTO();
+ item.setIntMappingType(IntMappingType.UserSchema);
+ item.setExtAttrName("surname");
+ item.setIntAttrName("sn");
+ item.setPurpose(MappingPurpose.BOTH);
+ umapping.addItem(item);
+
+ item = new MappingItemTO();
+ item.setIntMappingType(IntMappingType.UserSchema);
+ item.setExtAttrName("email");
+ item.setIntAttrName("mail");
+ item.setPurpose(MappingPurpose.BOTH);
+ umapping.addItem(item);
+
+ item = new MappingItemTO();
+ item.setIntMappingType(IntMappingType.Password);
+ item.setPassword(true);
+ item.setPurpose(MappingPurpose.BOTH);
+ item.setMandatoryCondition("true");
+ umapping.addItem(item);
+
+ umapping.setAccountLink("'cn=' + username + ',ou=people,o=isp'");
+
+ final MappingTO rmapping = new MappingTO();
+
+ item = new MappingItemTO();
+ item.setIntMappingType(IntMappingType.RoleSchema);
+ item.setExtAttrName("cn");
+ item.setIntAttrName(newSchemaTO.getName());
+ item.setAccountid(true);
+ item.setPurpose(MappingPurpose.BOTH);
+ rmapping.setAccountIdItem(item);
+
+ rmapping.setAccountLink("'cn=' + " + newSchemaTO.getName() + " + ',ou=groups,o=isp'");
+
+ resourceTO.setRmapping(rmapping);
+
+ Response response = resourceService.create(resourceTO);
+ newResourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+
+ assertNotNull(newResourceTO);
+ assertNull(newResourceTO.getUmapping());
+ assertNotNull(newResourceTO.getRmapping());
+
+ // create push task ad-hoc
+ final PushTaskTO task = new PushTaskTO();
+ task.setName("issueSYNCOPE598");
+ task.setResource(resourceName);
+ task.setPerformCreate(true);
+ task.setPerformDelete(true);
+ task.setPerformUpdate(true);
+ task.setUnmatchingRule(UnmatchingRule.ASSIGN);
+ task.setMatchingRule(MatchingRule.UPDATE);
+
+ response = taskService.create(task);
+ final PushTaskTO push = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
+
+ assertNotNull(push);
+
+ // execute the new task
+ final TaskExecTO pushExec = execSyncTask(push.getId(), 50, false);
+ assertTrue(PropagationTaskExecStatus.valueOf(pushExec.getStatus()).isSuccessful());
+ } finally {
+ roleService.delete(roleTO.getId());
+ if (newResourceTO != null) {
+ resourceService.delete(resourceName);
+ }
+ }
+ }
}