use of com.paascloud.provider.model.domain.UacUserToken in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method getByAccessToken.
@Override
public UserTokenDto getByAccessToken(String accessToken) {
UserTokenDto userTokenDto = (UserTokenDto) redisTemplate.opsForValue().get(RedisKeyUtil.getAccessTokenKey(accessToken));
if (userTokenDto == null) {
UacUserToken uacUserToken = new UacUserToken();
uacUserToken.setAccessToken(accessToken);
uacUserToken = uacUserTokenMapper.selectOne(uacUserToken);
userTokenDto = new ModelMapper().map(uacUserToken, UserTokenDto.class);
}
return userTokenDto;
}
use of com.paascloud.provider.model.domain.UacUserToken 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.provider.model.domain.UacUserToken in project paascloud-master by paascloud.
the class UacUserTokenServiceImpl method listTokenWithPage.
@Override
public PageInfo listTokenWithPage(TokenMainQueryDto token) {
PageHelper.startPage(token.getPageNum(), token.getPageSize());
UacUserToken userToken = new UacUserToken();
userToken.setStatus(token.getStatus());
if (token.getStatus() != null) {
userToken.setStatus(token.getStatus());
}
if (StringUtils.isNotBlank(token.getLoginName())) {
userToken.setLoginName(token.getLoginName());
}
if (StringUtils.isNotBlank(token.getUserName())) {
userToken.setUserName(token.getUserName());
}
List<UacUserToken> userTokenList = uacUserTokenMapper.selectTokenList(userToken);
return new PageInfo<>(userTokenList);
}
use of com.paascloud.provider.model.domain.UacUserToken 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