data = new HashMap<>();
+ data.put("type", event.getAccessDeniedException().getClass().getName());
+ data.put("message", event.getAccessDeniedException().getMessage());
+ data.put("requestUrl", ((FilterInvocation)event.getSource()).getRequestUrl() );
+ if (event.getAuthentication().getDetails() != null) {
+ data.put("details", event.getAuthentication().getDetails());
+ }
+ publish(new AuditEvent(event.getAuthentication().getName(), AUTHORIZATION_FAILURE,
+ data));
+ }
+}
diff --git a/spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java b/spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java
new file mode 100644
index 0000000000..5be8cebfd3
--- /dev/null
+++ b/spring-boot-auditing/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java
@@ -0,0 +1,25 @@
+package org.baeldung.auditing;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.actuate.audit.AuditEvent;
+import org.springframework.boot.actuate.audit.listener.AuditApplicationEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.security.web.authentication.WebAuthenticationDetails;
+import org.springframework.stereotype.Component;
+
+@Component
+public class LoginAttemptsLogger {
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoginAttemptsLogger.class);
+
+ @EventListener
+ public void auditEventHappened(AuditApplicationEvent auditApplicationEvent) {
+ AuditEvent auditEvent = auditApplicationEvent.getAuditEvent();
+ LOGGER.debug("Principal " + auditEvent.getPrincipal() + " - " + auditEvent.getType());
+
+ WebAuthenticationDetails details = (WebAuthenticationDetails) auditEvent.getData().get("details");
+ LOGGER.debug(" Remote IP address: " + details.getRemoteAddress());
+ LOGGER.debug(" Session Id: " + details.getSessionId());
+ LOGGER.debug(" Request URL: " + auditEvent.getData().get("requestUrl"));
+ }
+}
diff --git a/spring-boot-auditing/src/main/resources/application.properties b/spring-boot-auditing/src/main/resources/application.properties
new file mode 100644
index 0000000000..cf09473b60
--- /dev/null
+++ b/spring-boot-auditing/src/main/resources/application.properties
@@ -0,0 +1 @@
+logging.level.org.springframework=INFO
\ No newline at end of file
diff --git a/spring-boot-auditing/src/main/resources/logback.xml b/spring-boot-auditing/src/main/resources/logback.xml
new file mode 100644
index 0000000000..78913ee76f
--- /dev/null
+++ b/spring-boot-auditing/src/main/resources/logback.xml
@@ -0,0 +1,14 @@
+
+
+
+
+ web - %date [%thread] %-5level %logger{36} - %message%n
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-boot-auditing/src/main/resources/templates/hello.html b/spring-boot-auditing/src/main/resources/templates/hello.html
new file mode 100755
index 0000000000..46feef7e2c
--- /dev/null
+++ b/spring-boot-auditing/src/main/resources/templates/hello.html
@@ -0,0 +1,13 @@
+
+
+
+ Hello World!
+
+
+ Hello [[${#httpServletRequest.remoteUser}]]!
+
+
+
\ No newline at end of file
diff --git a/spring-boot-auditing/src/main/resources/templates/home.html b/spring-boot-auditing/src/main/resources/templates/home.html
new file mode 100755
index 0000000000..fe4e8b337e
--- /dev/null
+++ b/spring-boot-auditing/src/main/resources/templates/home.html
@@ -0,0 +1,11 @@
+
+
+
+ Spring Security Example
+
+
+ Welcome!
+
+ Click here to see a greeting.
+
+
\ No newline at end of file
diff --git a/spring-boot-auditing/src/main/resources/templates/login.html b/spring-boot-auditing/src/main/resources/templates/login.html
new file mode 100755
index 0000000000..a1785313f5
--- /dev/null
+++ b/spring-boot-auditing/src/main/resources/templates/login.html
@@ -0,0 +1,20 @@
+
+
+
+ Spring Security Example
+
+
+
+ Invalid username and password.
+
+
+ You have been logged out.
+
+
+
+
\ No newline at end of file