Search in sources :

Example 1 with UserLog

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);
}
Also used : UserLog(org.motechproject.mots.domain.security.UserLog) Date(java.util.Date)

Example 2 with 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;
}
Also used : User(org.motechproject.mots.domain.security.User) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) UserLog(org.motechproject.mots.domain.security.UserLog)

Aggregations

UserLog (org.motechproject.mots.domain.security.UserLog)2 Date (java.util.Date)1 User (org.motechproject.mots.domain.security.User)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1