syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdisabat...@apache.org
Subject syncope git commit: [SYNCOPE-648] Add matching/unmatching events to notification and audit
Date Tue, 17 Mar 2015 15:10:01 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X b63021933 -> 89d5ad43c


[SYNCOPE-648] Add matching/unmatching events to notification and audit


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

Branch: refs/heads/1_2_X
Commit: 89d5ad43cf26454092dbd04446a0d9a6f5192f4a
Parents: b630219
Author: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Authored: Tue Mar 17 16:09:35 2015 +0100
Committer: Marco Di Sabatino Di Diodoro <mdisabatino@apache.org>
Committed: Tue Mar 17 16:09:35 2015 +0100

----------------------------------------------------------------------
 .../syncope/common/types/MatchingRule.java      |  7 ++-
 .../syncope/common/types/UnmatchingRule.java    |  7 ++-
 .../core/rest/controller/LoggerController.java  | 18 +++++++-
 .../impl/AbstractSubjectPushResultHandler.java  | 12 +++--
 .../impl/AbstractSubjectSyncResultHandler.java  | 47 +++++++++++++++++---
 .../syncope/core/sync/impl/AbstractSyncJob.java | 33 +++++++++++---
 .../syncope/core/rest/TaskTestITCase.java       | 44 ++++++++++++++++++
 7 files changed, 150 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/common/src/main/java/org/apache/syncope/common/types/MatchingRule.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/syncope/common/types/MatchingRule.java b/common/src/main/java/org/apache/syncope/common/types/MatchingRule.java
index 51933fc..ff36dec 100644
--- a/common/src/main/java/org/apache/syncope/common/types/MatchingRule.java
+++ b/common/src/main/java/org/apache/syncope/common/types/MatchingRule.java
@@ -49,6 +49,11 @@ public enum MatchingRule {
     /**
      * Just link resource without performing any (de-)provisioning operation.
      */
-    LINK
+    LINK;
+
+    public static String toEventName(final MatchingRule rule) {
+        return new StringBuilder(MatchingRule.class.getSimpleName()).
+                append("_").append(rule.name()).toString().toLowerCase();
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/common/src/main/java/org/apache/syncope/common/types/UnmatchingRule.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/syncope/common/types/UnmatchingRule.java b/common/src/main/java/org/apache/syncope/common/types/UnmatchingRule.java
index d57aacf..224cf63 100644
--- a/common/src/main/java/org/apache/syncope/common/types/UnmatchingRule.java
+++ b/common/src/main/java/org/apache/syncope/common/types/UnmatchingRule.java
@@ -42,6 +42,11 @@ public enum UnmatchingRule {
      * Just unlink resource without performing any (de-)provisioning operation.
      * In case of sync task UNLINK and IGNORE will coincide.
      */
-    UNLINK
+    UNLINK;
+
+    public static String toEventName(final UnmatchingRule rule) {
+        return new StringBuilder(UnmatchingRule.class.getSimpleName()).
+                append("_").append(rule.name()).toString().toLowerCase();
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/core/src/main/java/org/apache/syncope/core/rest/controller/LoggerController.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/rest/controller/LoggerController.java
b/core/src/main/java/org/apache/syncope/core/rest/controller/LoggerController.java
index a4e53b8..f38d0b2 100644
--- a/core/src/main/java/org/apache/syncope/core/rest/controller/LoggerController.java
+++ b/core/src/main/java/org/apache/syncope/core/rest/controller/LoggerController.java
@@ -41,6 +41,8 @@ import org.apache.syncope.common.types.LoggerType;
 import org.apache.syncope.common.types.ResourceOperation;
 import org.apache.syncope.common.util.BeanUtils;
 import org.apache.syncope.common.SyncopeClientException;
+import org.apache.syncope.common.types.MatchingRule;
+import org.apache.syncope.common.types.UnmatchingRule;
 import org.apache.syncope.core.persistence.beans.ExternalResource;
 import org.apache.syncope.core.persistence.beans.SchedTask;
 import org.apache.syncope.core.persistence.beans.SyncTask;
@@ -217,7 +219,7 @@ public class LoggerController extends AbstractTransactionalController<LoggerTO>
             final String packageSearchPath =
                     ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                     + ClassUtils.convertClassNameToResourcePath(
-                    SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName()))
+                            SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName()))
                     + "/" + "**/*.class";
 
             final Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
@@ -239,7 +241,7 @@ public class LoggerController extends AbstractTransactionalController<LoggerTO>
                     }
                 }
             }
-            
+
             //SYNCOPE-608
             final EventCategoryTO authenticationControllerEvents = new EventCategoryTO();
             authenticationControllerEvents.setCategory("AuthenticationController");
@@ -270,6 +272,18 @@ public class LoggerController extends AbstractTransactionalController<LoggerTO>
                         pushEventCategoryTO.getEvents().add(resourceOperation.name().toLowerCase());
                     }
 
+                    for (UnmatchingRule unmatching : UnmatchingRule.values()) {
+                        String event = UnmatchingRule.toEventName(unmatching);
+                        syncEventCategoryTO.getEvents().add(event);
+                        pushEventCategoryTO.getEvents().add(event);
+                    }
+
+                    for (MatchingRule matching : MatchingRule.values()) {
+                        String event = MatchingRule.toEventName(matching);
+                        syncEventCategoryTO.getEvents().add(event);
+                        pushEventCategoryTO.getEvents().add(event);
+                    }
+
                     events.add(propEventCategoryTO);
                     events.add(syncEventCategoryTO);
                     events.add(pushEventCategoryTO);

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/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 f8cb658..e8954e9 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
@@ -132,7 +132,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
         } else {
             try {
                 if (beforeObj == null) {
-                    operation = profile.getSyncTask().getUnmatchingRule().name().toLowerCase();
+                    operation = UnmatchingRule.toEventName(profile.getSyncTask().getUnmatchingRule());
                     result.setOperation(getResourceOperation(profile.getSyncTask().getUnmatchingRule()));
 
                     switch (profile.getSyncTask().getUnmatchingRule()) {
@@ -172,12 +172,15 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
                             }
 
                             break;
+                        case IGNORE:
+                            LOG.debug("Ignored subjectId: {}", subjectId);
+                            break;
                         default:
                         // do nothing
                     }
 
                 } else {
-                    operation = profile.getSyncTask().getMatchingRule().name().toLowerCase();
+                    operation = MatchingRule.toEventName(profile.getSyncTask().getMatchingRule());
          
                     result.setOperation(getResourceOperation(profile.getSyncTask().getMatchingRule()));
 
                     switch (profile.getSyncTask().getMatchingRule()) {
@@ -240,6 +243,9 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
                             }
 
                             break;
+                        case IGNORE:
+                            LOG.debug("Ignored subjectId: {}", subjectId);
+                            break;
                         default:
                         // do nothing
                     }
@@ -263,7 +269,7 @@ public abstract class AbstractSubjectPushResultHandler extends AbstractSyncopeRe
             } finally {
                 notificationManager.createTasks(
                         AuditElements.EventCategoryType.PUSH,
-                        AttributableType.USER.name().toLowerCase(),
+                        attrUtil.getType().name().toLowerCase(),
                         profile.getSyncTask().getResource().getName(),
                         operation,
                         resultStatus,

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectSyncResultHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectSyncResultHandler.java
b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectSyncResultHandler.java
index ff9bc3d..9a51ebe 100644
--- a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectSyncResultHandler.java
+++ b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSubjectSyncResultHandler.java
@@ -31,7 +31,9 @@ import org.apache.syncope.common.mod.AbstractSubjectMod;
 import org.apache.syncope.common.to.AbstractSubjectTO;
 import org.apache.syncope.common.types.AuditElements;
 import org.apache.syncope.common.types.AuditElements.Result;
+import org.apache.syncope.common.types.MatchingRule;
 import org.apache.syncope.common.types.ResourceOperation;
+import org.apache.syncope.common.types.UnmatchingRule;
 import org.apache.syncope.core.persistence.beans.SyncTask;
 import org.apache.syncope.core.persistence.dao.NotFoundException;
 import org.apache.syncope.core.persistence.dao.UserDAO;
@@ -126,7 +128,7 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                 _delta = action.beforeAssign(this.getProfile(), _delta, transformed);
             }
 
-            create(transformed, _delta, attrUtil, "assign", result);
+            create(transformed, _delta, attrUtil, UnmatchingRule.toEventName(UnmatchingRule.ASSIGN),
result);
         }
 
         return Collections.singletonList(result);
@@ -161,7 +163,7 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                 _delta = action.beforeProvision(this.getProfile(), _delta, transformed);
             }
 
-            create(transformed, _delta, attrUtil, "provision", result);
+            create(transformed, _delta, attrUtil, UnmatchingRule.toEventName(UnmatchingRule.PROVISION),
result);
         }
 
         return Collections.<SyncResult>singletonList(result);
@@ -278,7 +280,7 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         resultStatus = Result.FAILURE;
                     }
                 }
-                audit("update", resultStatus, before, output, delta);
+                audit(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before,
output, delta);
             }
             updResults.add(result);
         }
@@ -361,7 +363,9 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         resultStatus = Result.FAILURE;
                     }
                 }
-                audit(unlink ? "unassign" : "deprovision", resultStatus, before, output,
delta);
+                audit(unlink
+                        ? MatchingRule.toEventName(MatchingRule.UNASSIGN)
+                        : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus,
before, output, delta);
             }
             updResults.add(result);
         }
@@ -444,7 +448,8 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         resultStatus = Result.FAILURE;
                     }
                 }
-                audit(unlink ? "unlink" : "link", resultStatus, before, output, delta);
+                audit(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK)
+                        : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before,
output, delta);
             }
             updResults.add(result);
         }
@@ -500,7 +505,7 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         action.after(this.getProfile(), delta, before, result);
                     }
 
-                    audit("delete", resultStatus, before, output, delta);
+                    audit(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before,
output, delta);
                 }
 
                 delResults.add(result);
@@ -517,6 +522,30 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
         return delResults;
     }
 
+    private List<SyncResult> ignore(SyncDelta delta, final AttributableUtil attrUtil,
final boolean matching)
+            throws JobExecutionException {
+
+        LOG.debug("Subject to ignore {}", delta.getObject().getUid().getUidValue());
+
+        final List<SyncResult> ignoreResults = new ArrayList<SyncResult>();
+        final SyncResult result = new SyncResult();
+
+        result.setId(null);
+        result.setName(delta.getObject().getUid().getUidValue());
+        result.setOperation(ResourceOperation.NONE);
+        result.setSubjectType(attrUtil.getType());
+        result.setStatus(SyncResult.Status.SUCCESS);
+        ignoreResults.add(result);
+
+        if (!profile.isDryRun()) {
+            audit(matching
+                    ? MatchingRule.toEventName(MatchingRule.IGNORE)
+                    : UnmatchingRule.toEventName(UnmatchingRule.IGNORE), Result.SUCCESS,
null, null, delta);
+        }
+
+        return ignoreResults;
+    }
+
     /**
      * Look into SyncDelta and take necessary profile.getActions() (create / update / delete)
on user(s)/role(s).
      *
@@ -566,6 +595,9 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         case PROVISION:
                             profile.getResults().addAll(create(delta, attrUtil));
                             break;
+                        case IGNORE:
+                            profile.getResults().addAll(ignore(delta, attrUtil, false));
+                            break;
                         default:
                         // do nothing
                     }
@@ -586,6 +618,9 @@ public abstract class AbstractSubjectSyncResultHandler extends AbstractSyncopeRe
                         case UNLINK:
                             profile.getResults().addAll(link(delta, subjectIds, attrUtil,
true));
                             break;
+                        case IGNORE:
+                            profile.getResults().addAll(ignore(delta, attrUtil, true));
+                            break;
                         default:
                         // do nothing
                     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSyncJob.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSyncJob.java b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSyncJob.java
index cabeb4f..0124082 100644
--- a/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSyncJob.java
+++ b/core/src/main/java/org/apache/syncope/core/sync/impl/AbstractSyncJob.java
@@ -116,12 +116,14 @@ public abstract class AbstractSyncJob<T extends AbstractSyncTask,
A extends Abst
         List<SyncResult> uFailUpdate = new ArrayList<SyncResult>();
         List<SyncResult> uSuccDelete = new ArrayList<SyncResult>();
         List<SyncResult> uFailDelete = new ArrayList<SyncResult>();
+        List<SyncResult> uSuccNone = new ArrayList<SyncResult>();
         List<SyncResult> rSuccCreate = new ArrayList<SyncResult>();
         List<SyncResult> rFailCreate = new ArrayList<SyncResult>();
         List<SyncResult> rSuccUpdate = new ArrayList<SyncResult>();
         List<SyncResult> rFailUpdate = new ArrayList<SyncResult>();
         List<SyncResult> rSuccDelete = new ArrayList<SyncResult>();
         List<SyncResult> rFailDelete = new ArrayList<SyncResult>();
+        List<SyncResult> rSuccNone = new ArrayList<SyncResult>();
 
         for (SyncResult syncResult : syncResults) {
             switch (syncResult.getStatus()) {
@@ -169,6 +171,20 @@ public abstract class AbstractSyncJob<T extends AbstractSyncTask,
A extends Abst
                             }
                             break;
 
+                        case NONE:
+                            switch (syncResult.getSubjectType()) {
+                                case USER:
+                                    uSuccNone.add(syncResult);
+                                    break;
+
+                                case ROLE:
+                                    rSuccNone.add(syncResult);
+                                    break;
+
+                                default:
+                            }
+                            break;
+
                         default:
                     }
                     break;
@@ -232,13 +248,16 @@ public abstract class AbstractSyncJob<T extends AbstractSyncTask,
A extends Abst
                 append("[updated/failures]: ").append(uSuccUpdate.size()).append('/').append(uFailUpdate.size()).
                 append(' ').
                 append("[deleted/failures]: ").append(uSuccDelete.size()).append('/').append(uFailDelete.size()).
-                append('\n');
+                append(' ').
+                append("[ignored]: ").append(uSuccNone.size()).append('\n');
         report.append("Roles ").
                 append("[created/failures]: ").append(rSuccCreate.size()).append('/').append(rFailCreate.size()).
                 append(' ').
                 append("[updated/failures]: ").append(rSuccUpdate.size()).append('/').append(rFailUpdate.size()).
                 append(' ').
-                append("[deleted/failures]: ").append(rSuccDelete.size()).append('/').append(rFailDelete.size());
+                append("[deleted/failures]: ").append(rSuccDelete.size()).append('/').append(rFailDelete.size()).
+                append(' ').
+                append("[ignored]: ").append(rSuccNone.size());
 
         // Failures
         if (syncTraceLevel == TraceLevel.FAILURES || syncTraceLevel == TraceLevel.ALL) {
@@ -276,13 +295,17 @@ public abstract class AbstractSyncJob<T extends AbstractSyncTask,
A extends Abst
                     .append("\nUsers updated:\n")
                     .append(SyncResult.produceReport(uSuccUpdate, syncTraceLevel))
                     .append("\nUsers deleted:\n")
-                    .append(SyncResult.produceReport(uSuccDelete, syncTraceLevel));
+                    .append(SyncResult.produceReport(uSuccDelete, syncTraceLevel))
+                    .append("\nUsers ignored:\n")
+                    .append(SyncResult.produceReport(uSuccNone, syncTraceLevel));
             report.append("\n\nRoles created:\n")
                     .append(SyncResult.produceReport(rSuccCreate, syncTraceLevel))
                     .append("\nRoles updated:\n")
                     .append(SyncResult.produceReport(rSuccUpdate, syncTraceLevel))
                     .append("\nRoles deleted:\n")
-                    .append(SyncResult.produceReport(rSuccDelete, syncTraceLevel));
+                    .append(SyncResult.produceReport(rSuccDelete, syncTraceLevel))
+                    .append("\nRoles ignored:\n")
+                    .append(SyncResult.produceReport(rSuccNone, syncTraceLevel));
         }
 
         return report.toString();
@@ -316,7 +339,7 @@ public abstract class AbstractSyncJob<T extends AbstractSyncTask, A
extends Abst
             } catch (Exception e) {
                 final String msg = String.
                         format("Connector instance bean for resource %s and connInstance
%s not found",
-                        syncTask.getResource(), syncTask.getResource().getConnector());
+                                syncTask.getResource(), syncTask.getResource().getConnector());
 
                 throw new JobExecutionException(msg, e);
             }

http://git-wip-us.apache.org/repos/asf/syncope/blob/89d5ad43/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 468b8f9..0cc137a 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
@@ -1385,4 +1385,48 @@ public class TaskTestITCase extends AbstractTest {
             }
         }
     }
+
+    @Test
+    public void issueSYNCOPE648() {
+        //1. Create Push Task
+        final PushTaskTO task = new PushTaskTO();
+        task.setName("Test create Push");
+        task.setResource(RESOURCE_NAME_LDAP);
+        task.setUserFilter(
+                SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("_NO_ONE_").query());
+        task.setRoleFilter(
+                SyncopeClient.getRoleSearchConditionBuilder().is("name").equalTo("citizen").query());
+        task.setMatchingRule(MatchingRule.IGNORE);
+        task.setUnmatchingRule(UnmatchingRule.IGNORE);
+
+        final Response response = taskService.create(task);
+        final PushTaskTO actual = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
+        assertNotNull(actual);
+
+        // 2. Create notification
+        NotificationTO notification = new NotificationTO();
+        notification.setTraceLevel(TraceLevel.FAILURES);
+        notification.getEvents().add("[PushTask]:[role]:[resource-ldap]:[matchingrule_ignore]:[SUCCESS]");
+        notification.getEvents().add("[PushTask]:[role]:[resource-ldap]:[unmatchingrule_ignore]:[SUCCESS]");
+
+        notification.getStaticRecipients().add("issueyncope648@syncope.apache.org");
+        notification.setSelfAsRecipient(false);
+        notification.setRecipientAttrName("email");
+        notification.setRecipientAttrType(IntMappingType.UserSchema);
+
+        notification.setSender("syncope648@syncope.apache.org");
+        String subject = "Test notification";
+        notification.setSubject(subject);
+        notification.setTemplate("optin");
+        notification.setActive(true);
+
+        Response responseNotification = notificationService.create(notification);
+        notification = getObject(responseNotification.getLocation(), NotificationService.class,
NotificationTO.class);
+        assertNotNull(notification);
+
+        execSyncTask(actual.getId(), 50, false);
+        
+        NotificationTaskTO taskTO = findNotificationTaskBySender("syncope648@syncope.apache.org");
+        assertNotNull(taskTO);
+    }
 }


Mime
View raw message