60. Authentication failure listener (#6)

This commit is contained in:
Art
2021-09-08 13:51:47 +03:00
parent 213ff93e55
commit d272b01ff9

View File

@ -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<AuthenticationFailureBadCredentialsEvent> {
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);
}
}