You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/09/23 17:19:52 UTC

[4/6] logging-log4j-audit git commit: Merge branch 'master' of https://github.com/apache/logging-log4j-audit into LOG4J2-2421

Merge branch 'master' of https://github.com/apache/logging-log4j-audit into LOG4J2-2421


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/45884e0a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/45884e0a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/45884e0a

Branch: refs/heads/master
Commit: 45884e0aa192954068d57b36e5539fdf66ceb052
Parents: 0c3a58a 07e5419
Author: Andrei Ivanov <an...@gmail.com>
Authored: Sat Sep 22 10:10:14 2018 +0300
Committer: Andrei Ivanov <an...@gmail.com>
Committed: Sat Sep 22 10:10:14 2018 +0300

----------------------------------------------------------------------
 .../log4j/audit/AbstractEventLogger.java        | 32 +++++++-------
 .../logging/log4j/audit/LogEventFactory.java    | 27 ++++++++----
 .../log4j/audit/catalog/CatalogManagerImpl.java | 33 ++++++++------
 .../log4j/audit/rest/RequestContextFilter.java  | 21 +++++----
 .../rest/RequestContextHandlerInterceptor.java  | 22 ++++++----
 .../logging/log4j/audit/AuditLoggerTest.java    | 45 ++++++++++++++------
 .../logging/log4j/audit/BaseEventTest.java      | 39 +++++++++++++++++
 .../apache/logging/log4j/audit/LoginTest.java   | 34 +++++++++++++++
 .../logging/log4j/audit/TransferTest.java       | 24 +----------
 .../apache/logging/log4j/audit/event/Login.java |  6 +++
 .../src/test/resources/basicCatalog.json        |  5 +++
 src/changes/changes.xml                         | 14 ++++++
 12 files changed, 214 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/45884e0a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
----------------------------------------------------------------------
diff --cc log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
index e9af187,ee203d6..5de2844
--- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
+++ b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/AbstractEventLogger.java
@@@ -28,9 -29,11 +29,9 @@@ import org.apache.logging.log4j.catalog
  import org.apache.logging.log4j.catalog.api.plugins.ConstraintPlugins;
  import org.apache.logging.log4j.message.StructuredDataMessage;
  
 -import java.util.List;
 -import java.util.Map;
 -import java.util.Set;
 +import java.util.*;
  
- import static org.apache.logging.log4j.catalog.api.constant.Constants.*;
+ import static java.util.Collections.*;
  
  /**
   * This class is used to log events generated remotely.

http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/45884e0a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
----------------------------------------------------------------------
diff --cc log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
index eab5dd1,3cfca75..5d925d5
--- a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
+++ b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/AuditLoggerTest.java
@@@ -74,10 -80,10 +81,12 @@@ public class AuditLoggerTest 
      }
  
      @Test
-     public void testAuditLogger() {
+     public void testAuditLogger() throws Exception {
+         auditLogger = buildAuditLogger(catalogReader);
+ 
 +        ThreadContext.put("accountNumber", "12345");
          ThreadContext.put("companyId", "12345");
 +        ThreadContext.put("userId", "JohnDoe");
          ThreadContext.put("ipAddress", "127.0.0.1");
          ThreadContext.put("environment", "dev");
          ThreadContext.put("product", "TestProduct");
@@@ -103,16 -110,9 +113,20 @@@
      }
  
      @Test(expected = AuditException.class)
-     public void testMissingRequestContextAttribute() {
 -    public void testBadAttribute() throws Exception {
++    public void testMissingRequestContextAttribute() throws Exception {
++        auditLogger = buildAuditLogger(catalogReader);
++
 +        Map<String, String> properties = new HashMap<String, String>();
 +        properties.put("toAccount", "123456");
 +        properties.put("fromAccount", "111111");
 +        properties.put("amount", "111.55");
 +        auditLogger.logEvent("transfer", properties);
 +    }
 +
 +    @Test(expected = AuditException.class)
-     public void testMissingEventAttribute() {
++    public void testMissingEventAttribute() throws Exception {
+         auditLogger = buildAuditLogger(catalogReader);
+ 
          ThreadContext.put("companyId", "12345");
          ThreadContext.put("ipAddress", "127.0.0.1");
          ThreadContext.put("environment", "dev");

http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/45884e0a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/TransferTest.java
----------------------------------------------------------------------
diff --cc log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/TransferTest.java
index ebc46ba,716bb58..7b1cd47
--- a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/TransferTest.java
+++ b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/TransferTest.java
@@@ -40,32 -40,10 +40,10 @@@ import static org.junit.Assert.fail
  /**
   *
   */
- public class TransferTest {
- 
-     private static LoggerContext ctx;
-     private static ListAppender app;
- 
-     @BeforeClass
-     public static void setupClass() throws Exception {
-         ctx = (LoggerContext) LogManager.getContext(false);
-         Configuration config = ctx.getConfiguration();
-         for (Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
-             if (entry.getKey().equals("List")) {
-                 app = (ListAppender) entry.getValue();
-                 break;
-             }
-         }
-         assertNotNull("No Appender", app);
-     }
- 
-     @Before
-     public void before() {
-         app.clear();
-         ThreadContext.clearMap();
-     }
+ public class TransferTest extends BaseEventTest {
  
      @Test(expected = ConstraintValidationException.class)
 -    public void testValidationFailure() {
 +    public void testValidationFailureForMissingRequestContextAttribute() {
          Transfer transfer = LogEventFactory.getEvent(Transfer.class);
          ThreadContext.put("companyId", "12345");
          ThreadContext.put("ipAddress", "127.0.0.1");