use of org.motechproject.mots.domain.security.UserLog in project mots by motech-implementations.
the class UserLogService method createNewUserLog.
/**
* Create new User Log.
* @param user a user that is logging in
* @param expirationDate access token's expiration date
* @return created UserLog
*/
public UserLog createNewUserLog(User user, Date expirationDate) {
UserLog userLog = new UserLog();
userLog.setUser(user);
userLog.setLoginDate(new Date());
userLog.setLogoutDate(expirationDate);
return userLogRepository.save(userLog);
}
use of org.motechproject.mots.domain.security.UserLog in project mots by motech-implementations.
the class CustomTokenServices method refreshAccessToken.
@Override
public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest tokenRequest) throws AuthenticationException {
OAuth2AccessToken accessToken = super.refreshAccessToken(refreshTokenValue, tokenRequest);
OAuth2Authentication authentication = tokenStore.readAuthenticationForRefreshToken(accessToken.getRefreshToken());
User user = getUserFromPrincipal(authentication.getUserAuthentication().getPrincipal());
UserLog existingUserLog = userLogService.getUserLog(user);
if (existingUserLog != null) {
existingUserLog.setLogoutDate(accessToken.getExpiration());
userLogService.updateUserLog(existingUserLog);
} else {
userLogService.createNewUserLog(user, accessToken.getExpiration());
}
return accessToken;
}
Aggregations