use of com.paascloud.security.core.properties.OAuth2ClientProperties in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method saveUserToken.
@Override
public void saveUserToken(String accessToken, String refreshToken, LoginAuthDto loginAuthDto, HttpServletRequest request) {
// 获取登录时间
Long userId = loginAuthDto.getUserId();
UacUser uacUser = uacUserService.selectByKey(userId);
final UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem().getName();
// 获取客户端浏览器
final String browser = userAgent.getBrowser().getName();
final String remoteAddr = RequestUtil.getRemoteAddr(request);
// 根据IP获取位置信息
final String remoteLocation = opcRpcService.getLocationById(remoteAddr);
// 存入mysql数据库
UacUserToken uacUserToken = new UacUserToken();
OAuth2ClientProperties[] clients = securityProperties.getOauth2().getClients();
int accessTokenValidateSeconds = clients[0].getAccessTokenValidateSeconds();
int refreshTokenValiditySeconds = clients[0].getRefreshTokenValiditySeconds();
uacUserToken.setOs(os);
uacUserToken.setBrowser(browser);
uacUserToken.setAccessToken(accessToken);
uacUserToken.setAccessTokenValidity(accessTokenValidateSeconds);
uacUserToken.setLoginIp(remoteAddr);
uacUserToken.setLoginLocation(remoteLocation);
uacUserToken.setLoginTime(uacUser.getLastLoginTime());
uacUserToken.setLoginName(loginAuthDto.getLoginName());
uacUserToken.setRefreshToken(refreshToken);
uacUserToken.setRefreshTokenValidity(refreshTokenValiditySeconds);
uacUserToken.setStatus(UacUserTokenStatusEnum.ON_LINE.getStatus());
uacUserToken.setUserId(userId);
uacUserToken.setUserName(loginAuthDto.getUserName());
uacUserToken.setUpdateInfo(loginAuthDto);
uacUserToken.setGroupId(loginAuthDto.getGroupId());
uacUserToken.setGroupName(loginAuthDto.getGroupName());
uacUserToken.setId(generateId());
uacUserTokenMapper.insertSelective(uacUserToken);
UserTokenDto userTokenDto = new ModelMapper().map(uacUserToken, UserTokenDto.class);
// 存入redis数据库
updateRedisUserToken(accessToken, accessTokenValidateSeconds, userTokenDto);
}
use of com.paascloud.security.core.properties.OAuth2ClientProperties in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method updateUacUserToken.
@Override
public void updateUacUserToken(UserTokenDto tokenDto, LoginAuthDto loginAuthDto) {
UacUserToken uacUserToken = new ModelMapper().map(tokenDto, UacUserToken.class);
uacUserToken.setUpdateInfo(loginAuthDto);
uacUserTokenMapper.updateByPrimaryKeySelective(uacUserToken);
OAuth2ClientProperties[] clients = securityProperties.getOauth2().getClients();
int accessTokenValidateSeconds = clients[0].getAccessTokenValidateSeconds();
updateRedisUserToken(uacUserToken.getAccessToken(), accessTokenValidateSeconds, tokenDto);
}
Aggregations