Skip to content

Commit

Permalink
Revert "User created and last login"
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakarFin authored Sep 15, 2023
1 parent 136d62e commit 6f4a2aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 108 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.OffsetDateTime;
import java.util.Date;

public class OskariPreAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
Expand Down Expand Up @@ -64,9 +63,12 @@ public void onAuthenticationSuccess(HttpServletRequest request,

private User getUser(OskariUserDetails oud) throws ServiceException {
User user = userService.getUserByEmail(oud.getUser().getEmail());
// sdf is not threadsafe so create new for each login
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
if(user == null) {
user = oud.getUser();
user.addRole(Role.getDefaultUserRole());
user.setAttribute("created", format.format(new Date()));
} else {
// copy data that we got from headers
user.setFirstname(oud.getUser().getFirstname());
Expand All @@ -75,6 +77,7 @@ private User getUser(OskariUserDetails oud) throws ServiceException {
// merge attributes
JSONHelper.merge(user.getAttributesJSON(), oud.getUser().getAttributesJSON());
}
user.setAttribute("lastLogin", format.format(new Date()));
return user;

}
Expand All @@ -87,17 +90,6 @@ protected void setupSession(User authenticatedUser, HttpServletRequest request)
AuditLog.user(ActionParameters.getClientIp(request), authenticatedUser.getEmail())
.withMsg("Login")
.updated(AuditLog.ResourceType.USER);

// update last login
try {
User userToUpdate = userService.getUser(authenticatedUser.getId());
userToUpdate.setLastLogin(OffsetDateTime.now());
userService.modifyUser(userToUpdate);
} catch (Exception e) {

}


}

protected DatabaseUserService getUserService() {
Expand Down

0 comments on commit 6f4a2aa

Please sign in to comment.