60. Authentication failure listener (#6)
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user