use of com.dappermoose.stsimplefinance.data.LoginEvent in project spring-thymeleaf-simplefinance by heitkergm.
the class AuthenticationListener method onApplicationEvent.
@Override
@Transactional
public void onApplicationEvent(final AbstractAuthenticationEvent e) {
LOG.debug("login event + " + e.toString());
if (!(e instanceof AuthenticationSuccessEvent || e instanceof AbstractAuthenticationFailureEvent)) {
return;
}
Object obj = e.getAuthentication().getPrincipal();
String userName;
if (obj instanceof String) {
userName = (String) obj;
} else if (obj instanceof UserDetails) {
userName = ((UserDetails) obj).getUsername();
} else {
userName = "";
}
List<LoginUser> luser = loginUserRepository.findByUserName(userName);
if (luser.size() <= 0) {
return;
}
LoginUser user = luser.get(0);
LoginEvent loginEvent = new LoginEvent();
loginEvent.setUser(user);
if (e instanceof AbstractAuthenticationFailureEvent) {
loginEvent.setSuccess(YesNoEnum.NO);
} else {
loginEvent.setSuccess(YesNoEnum.YES);
}
loginEventRepository.save(loginEvent);
}
Aggregations