[java-identity-provider] branch maint-4 updated: IDP-2039 - Add audit logging to login flows

Scott Cantor cantor.2 at osu.edu
Wed Nov 30 18:17:52 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch maint-4
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=171acb5b1e7705a4753d33c2724311823010dfa5

The following commit(s) were added to refs/heads/maint-4 by this push:
     new 171acb5b1 IDP-2039 - Add audit logging to login flows
171acb5b1 is described below

commit 171acb5b1e7705a4753d33c2724311823010dfa5
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Nov 30 13:17:48 2022 -0500

    IDP-2039 - Add audit logging to login flows
    
    https://shibboleth.atlassian.net/browse/IDP-2039
    
    Enhance WriteAuditLog action to allow subsetting of formatting map.
---
 .../idp/profile/audit/impl/WriteAuditLog.java      | 37 ++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
index e588bb524..1ae1263b2 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
@@ -22,6 +22,7 @@ import java.time.ZoneId;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -72,6 +73,9 @@ public class WriteAuditLog extends AbstractProfileAction {
     /** Map of log category to formatting tokens and literals to output. */
     @Nonnull @NotEmpty private Map<String,List<String>> formattingMap;
 
+    /** Explicit categories to log from {@link #formattingMap} */
+    @Nonnull @NotEmpty private Collection<String> categoriesToLog;
+    
     /** Formatter for date/time fields. */
     @Nonnull private DateTimeFormatter dateTimeFormatter;
     
@@ -88,6 +92,7 @@ public class WriteAuditLog extends AbstractProfileAction {
     public WriteAuditLog() {
         auditContextLookupStrategy = new ChildContextLookup<>(AuditContext.class);
         formattingMap = Collections.emptyMap();
+        categoriesToLog = Collections.emptyList();
         dateTimeFormatter = DateTimeFormatter.ISO_INSTANT;
     }
 
@@ -122,9 +127,13 @@ public class WriteAuditLog extends AbstractProfileAction {
      * 
      * @param map map of categories to formatting strings
      */
-    public void setFormattingMap(@Nonnull @NonnullElements final Map<String,String> map) {
+    public void setFormattingMap(@Nullable @NonnullElements final Map<String,String> map) {
         ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        Constraint.isNotNull(map, "Audit formatting map cannot be null");
+        
+        if (map == null) {
+            formattingMap = Collections.emptyMap();
+            return;
+        }
         
         formattingMap = new HashMap<>(map.size());
         
@@ -167,6 +176,26 @@ public class WriteAuditLog extends AbstractProfileAction {
     }
 // Checkstyle: CyclomaticComplexity ON
 
+    /**
+     * Set categories to log explicitly.
+     * 
+     * <p>In the absence of any, the original behavior that iterates over the whole formatting map and logs
+     * each key is retained.</p>
+     * 
+     * @param categories categories to log
+     * 
+     * @since 4.3.0
+     */
+    public void setCategoriesToLog(@Nullable @NonnullElements final Collection<String> categories) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        
+        if (categories != null) {
+            categoriesToLog = List.copyOf(categories);
+        } else {
+            categoriesToLog = Collections.emptyList();
+        }
+    }
+    
     /**
      * Set the formatting string to apply when extracting date/time fields.
      * 
@@ -231,6 +260,10 @@ public class WriteAuditLog extends AbstractProfileAction {
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
         for (final Map.Entry<String,List<String>> entry : formattingMap.entrySet()) {
+            
+            if (!categoriesToLog.isEmpty() && !categoriesToLog.contains(entry.getKey())) {
+                continue;
+            }
         
             final StringBuilder record = new StringBuilder();
     

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list