syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [syncope] branch master updated: [SYNCOPE-1446] Do not apply transactions to audit table
Date Tue, 12 Mar 2019 11:58:21 GMT
This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 480ea47  [SYNCOPE-1446] Do not apply transactions to audit table
480ea47 is described below

commit 480ea47befd1b651b373658960bd0beee9f6a9d7
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
AuthorDate: Tue Mar 12 11:23:07 2019 +0100

    [SYNCOPE-1446] Do not apply transactions to audit table
---
 .../syncope/core/logic/init/LoggerLoader.java      |  4 +-
 .../provisioning/java/DefaultAuditManager.java     |  3 +
 .../org/apache/syncope/fit/core/LoggerITCase.java  | 80 ++++++++++++++++++++++
 3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
b/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
index 2903a10..77ded77 100644
--- a/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
+++ b/core/idrepo/logic/src/main/java/org/apache/syncope/core/logic/init/LoggerLoader.java
@@ -95,8 +95,8 @@ public class LoggerLoader implements SyncopeCoreLoader {
         Appender appender = ctx.getConfiguration().getAppender("audit_for_" + domain);
         if (appender == null) {
             appender = JdbcAppender.newBuilder().
-                    withName("audit_for_" + domain).
-                    withIgnoreExceptions(false).
+                    setName("audit_for_" + domain).
+                    setIgnoreExceptions(false).
                     setConnectionSource(new DataSourceConnectionSource(domain, datasource)).
                     setBufferSize(0).
                     setTableName("SYNCOPEAUDIT").
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultAuditManager.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultAuditManager.java
index 8a309d0..3d44e35 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultAuditManager.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultAuditManager.java
@@ -30,6 +30,7 @@ import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 @Transactional(readOnly = true)
@@ -72,6 +73,7 @@ public class DefaultAuditManager implements AuditManager {
         return auditRequested;
     }
 
+    @Transactional(propagation = Propagation.NOT_SUPPORTED)
     @Override
     public void audit(final AfterHandlingEvent event) {
         audit(
@@ -86,6 +88,7 @@ public class DefaultAuditManager implements AuditManager {
                 event.getInput());
     }
 
+    @Transactional(propagation = Propagation.NOT_SUPPORTED)
     @Override
     public void audit(
             final String who,
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
index e6f4a14..fe19fef 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
@@ -45,6 +45,7 @@ import org.apache.syncope.common.lib.log.LogStatement;
 import org.apache.syncope.common.lib.log.LoggerTO;
 import org.apache.syncope.common.lib.to.ConnInstanceTO;
 import org.apache.syncope.common.lib.to.ConnPoolConfTO;
+import org.apache.syncope.common.lib.to.PushTaskTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.AuditElements;
@@ -52,7 +53,9 @@ import org.apache.syncope.common.lib.types.AuditElements.EventCategoryType;
 import org.apache.syncope.common.lib.types.AuditLoggerName;
 import org.apache.syncope.common.lib.types.LoggerLevel;
 import org.apache.syncope.common.lib.types.LoggerType;
+import org.apache.syncope.common.lib.types.MatchingRule;
 import org.apache.syncope.common.lib.types.ResourceOperation;
+import org.apache.syncope.common.lib.types.UnmatchingRule;
 import org.apache.syncope.common.rest.api.LoggerWrapper;
 import org.apache.syncope.core.logic.ConnectorLogic;
 import org.apache.syncope.core.logic.ReportLogic;
@@ -370,4 +373,81 @@ public class LoggerITCase extends AbstractITCase {
         assertNotNull(userLogic);
         assertEquals(1, userLogic.getEvents().stream().filter(event -> "create".equals(event)).count());
     }
+
+    @Test
+    public void issueSYNCOPE1446() {
+        AuditLoggerName createSuccess = new AuditLoggerName(
+                AuditElements.EventCategoryType.PROPAGATION,
+                AnyTypeKind.ANY_OBJECT.name().toLowerCase(),
+                RESOURCE_NAME_DBSCRIPTED,
+                "create",
+                AuditElements.Result.SUCCESS);
+        AuditLoggerName createFailure = new AuditLoggerName(
+                AuditElements.EventCategoryType.PROPAGATION,
+                AnyTypeKind.ANY_OBJECT.name().toLowerCase(),
+                RESOURCE_NAME_DBSCRIPTED,
+                "create",
+                AuditElements.Result.FAILURE);
+        AuditLoggerName updateSuccess = new AuditLoggerName(
+                AuditElements.EventCategoryType.PROPAGATION,
+                AnyTypeKind.ANY_OBJECT.name().toLowerCase(),
+                RESOURCE_NAME_DBSCRIPTED,
+                "update",
+                AuditElements.Result.SUCCESS);
+        AuditLoggerName updateFailure = new AuditLoggerName(
+                AuditElements.EventCategoryType.PROPAGATION,
+                AnyTypeKind.ANY_OBJECT.name().toLowerCase(),
+                RESOURCE_NAME_DBSCRIPTED,
+                "update",
+                AuditElements.Result.FAILURE);
+        try {
+            // 1. setup audit for propagation
+            LoggerTO loggerTO = new LoggerTO();
+            loggerTO.setKey(createSuccess.toLoggerName());
+            loggerTO.setLevel(LoggerLevel.DEBUG);
+            loggerService.update(LoggerType.AUDIT, loggerTO);
+
+            loggerTO.setKey(createFailure.toLoggerName());
+            loggerService.update(LoggerType.AUDIT, loggerTO);
+
+            loggerTO.setKey(updateSuccess.toLoggerName());
+            loggerService.update(LoggerType.AUDIT, loggerTO);
+
+            loggerTO.setKey(updateFailure.toLoggerName());
+            loggerService.update(LoggerType.AUDIT, loggerTO);
+
+            // 2. push on resource
+            PushTaskTO pushTask = new PushTaskTO();
+            pushTask.setPerformCreate(true);
+            pushTask.setPerformUpdate(true);
+            pushTask.setUnmatchingRule(UnmatchingRule.PROVISION);
+            pushTask.setMatchingRule(MatchingRule.UPDATE);
+            reconciliationService.push(
+                    AnyTypeKind.ANY_OBJECT, "fc6dbc3a-6c07-4965-8781-921e7401a4a5", RESOURCE_NAME_DBSCRIPTED,
pushTask);
+        } catch (Exception e) {
+            LOG.error("Unexpected exception", e);
+            fail(e.getMessage());
+        } finally {
+            try {
+                loggerService.delete(LoggerType.AUDIT, createSuccess.toLoggerName());
+            } catch (Exception e) {
+                // ignore
+            }
+            try {
+                loggerService.delete(LoggerType.AUDIT, createFailure.toLoggerName());
+            } catch (Exception e) {
+                // ignore
+            }
+            try {
+                loggerService.delete(LoggerType.AUDIT, updateSuccess.toLoggerName());
+            } catch (Exception e) {
+                // ignore
+            }
+            try {
+                loggerService.delete(LoggerType.AUDIT, updateFailure.toLoggerName());
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
 }


Mime
View raw message