@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
// Find the current user
User user = userService.getUserByLoginOrEmail(authentication.getName());
// Persit only the new UserConnectionLog
UserConnectionLog userConnectionLog = new UserConnectionLog();
userConnectionLog.setUserId(user.getId());
userConnectionLog.setLoginDate(new Date());
userConnectionLog.setApp(Constants.APP_NAME_BO_BUSINESS_CODE);
userConnectionLog.setHost(request.getRemoteHost());
userConnectionLog.setPublicAddress(request.getRemoteAddr());
userConnectionLog.setPrivateAddress(request.getHeader(Constants.X_FORWARDED_FOR));
userConnectionLogService.saveOrUpdateUserConnectionLog(userConnectionLog);
try {
// Update the User in Session
user.getConnectionLogs().add(userConnectionLog);
requestUtil.updateCurrentUser(request, user);
setUseReferer(false);
String targetUrl = null;
String lastUrl = requestUtil.getCurrentRequestUrlNotSecurity(request);