Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: JM Brun
Added: Dec 11, 2019 9:52 AM
Modified: Dec 11, 2019 9:53 AM
Views: 10
  1. package org.talend.dataprep;
  2.  
  3. import org.springframework.boot.actuate.audit.AuditEvent;
  4. import org.springframework.boot.actuate.audit.listener.AuditApplicationEvent;
  5. import org.springframework.context.event.EventListener;
  6. import org.springframework.security.web.authentication.WebAuthenticationDetails;
  7. import org.springframework.stereotype.Component;
  8.  
  9. public class LoginAttemptsLogger {
  10.  
  11.     public void auditEventHappened(
  12.             AuditApplicationEvent auditApplicationEvent) {
  13.  
  14.         AuditEvent auditEvent = auditApplicationEvent.getAuditEvent();
  15.         System.out.println("Principal " + auditEvent.getPrincipal()
  16.                 + " - " + auditEvent.getType());
  17.  
  18.         WebAuthenticationDetails details =
  19.                 (WebAuthenticationDetails) auditEvent.getData().get("details");
  20.         System.out.println("Remote IP address: "
  21.                 + details.getRemoteAddress());
  22.         System.out.println("  Session Id: " + details.getSessionId());
  23.     }
  24. }
  25.