From d272b01ff974eafe5ac7be7800d18cdf1fe32120 Mon Sep 17 00:00:00 2001 From: Art Date: Wed, 8 Sep 2021 13:51:47 +0300 Subject: [PATCH] 60. Authentication failure listener (#6) --- .../AuthenticationFailureListener.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/listener/AuthenticationFailureListener.java diff --git a/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/listener/AuthenticationFailureListener.java b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/listener/AuthenticationFailureListener.java new file mode 100644 index 0000000..beef41e --- /dev/null +++ b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/listener/AuthenticationFailureListener.java @@ -0,0 +1,23 @@ +package net.shyshkin.study.fullstack.supportportal.backend.listener; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.shyshkin.study.fullstack.supportportal.backend.service.LoginAttemptService; +import org.springframework.context.ApplicationListener; +import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class AuthenticationFailureListener implements ApplicationListener { + + private final LoginAttemptService loginAttemptService; + + @Override + public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) { + String username = event.getAuthentication().getPrincipal().toString(); + log.debug("{} failed to login", username); + loginAttemptService.loginFailed(username); + } +}