61. Authentication success listener (#6)
This commit is contained in:
@ -0,0 +1,27 @@
|
|||||||
|
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.AuthenticationSuccessEvent;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> {
|
||||||
|
|
||||||
|
private final LoginAttemptService loginAttemptService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(AuthenticationSuccessEvent event) {
|
||||||
|
Object principal = event.getAuthentication().getPrincipal();
|
||||||
|
if (principal instanceof UserDetails) {
|
||||||
|
String username = ((UserDetails) principal).getUsername();
|
||||||
|
log.debug("{} successfully logged in", username);
|
||||||
|
loginAttemptService.loginSucceeded(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user