Commit 69da33d2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Update last login date on successful login

parent d1bdd379
......@@ -82,7 +82,7 @@ public class AccountLockoutManager {
}
/**
* Reset failed attempt statistics on successful login.
* Reset failed attempt statistics on successful login and update the last login date.
*
* @param userName the user name
*/
......@@ -93,6 +93,12 @@ public class AccountLockoutManager {
loginAttempts.remove(userName);
LOG.info("Successful login. Removed failed login statistics for " + userName + " " + stats);
}
try {
userService.updateLastLogin(userName);
} catch (final NoUserFoundException e) {
LOG.warn(e.getMessage());
}
}
/**
......
......@@ -39,7 +39,7 @@ public class AuthenticationSuccessListener implements ApplicationListener<Authen
/** The lockout manager. */
@Autowired
private AccountLockoutManager lockoutManager;
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.
......
/*
* Copyright 2017 Global Crop Diversity Trust
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -74,7 +74,9 @@ public abstract class BasicUser<R extends GrantedAuthority> extends AclSid imple
/** The google. */
GOOGLE,
/** The system. */
SYSTEM
SYSTEM,
/** Deleted user accounts */
DELETED
}
/** The uuid. */
......@@ -130,6 +132,12 @@ public abstract class BasicUser<R extends GrantedAuthority> extends AclSid imple
@Column(length = 20)
private AccountType accountType = AccountType.LOCAL;
/** The date of last successful login. */
@JsonView(JsonViews.Internal.class)
@Temporal(TemporalType.TIMESTAMP)
private Date lastLogin;
public BasicUser() {
setPrincipal(true);
}
......@@ -414,4 +422,21 @@ public abstract class BasicUser<R extends GrantedAuthority> extends AclSid imple
this.accountType = accountType;
}
/**
* Gets the last login.
*
* @return the last login
*/
public Date getLastLogin() {
return lastLogin;
}
/**
* Sets the last login.
*
* @param lastLogin the new last login
*/
public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;
}
}
......@@ -157,4 +157,12 @@ public interface BasicUserService<R extends GrantedAuthority, T extends BasicUse
*/
T setAccountType(T user, AccountType accountType);
/**
* Update user's last login date
*
* @param userName
* @throws NoUserFoundException if username not found in the system
*/
void updateLastLogin(String userName) throws NoUserFoundException;
}
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.security.service.impl;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
......@@ -325,4 +326,18 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
return _repository.save(u);
}
@Override
@Transactional
public void updateLastLogin(String userName) throws NoUserFoundException {
T u = getUserByEmail(userName);
u.setLastLogin(new Date());
// Set account to expire 1 year after last login
Calendar accountExpires = Calendar.getInstance();
accountExpires.add(Calendar.YEAR, 1);
u.setAccountExpires(accountExpires.getTime());
_repository.save(u);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment