Search in sources :

Example 1 with UacUserToken

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;
}
Also used : UserTokenDto(com.paascloud.base.dto.UserTokenDto) UacUserToken(com.paascloud.provider.model.domain.UacUserToken) ModelMapper(org.modelmapper.ModelMapper)

Example 2 with UacUserToken

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);
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) UserAgent(eu.bitwalker.useragentutils.UserAgent) UacUserToken(com.paascloud.provider.model.domain.UacUserToken) UserTokenDto(com.paascloud.base.dto.UserTokenDto) OAuth2ClientProperties(com.paascloud.security.core.properties.OAuth2ClientProperties) ModelMapper(org.modelmapper.ModelMapper)

Example 3 with UacUserToken

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);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) UacUserToken(com.paascloud.provider.model.domain.UacUserToken)

Example 4 with UacUserToken

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);
}
Also used : UacUserToken(com.paascloud.provider.model.domain.UacUserToken) OAuth2ClientProperties(com.paascloud.security.core.properties.OAuth2ClientProperties) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

UacUserToken (com.paascloud.provider.model.domain.UacUserToken)4 ModelMapper (org.modelmapper.ModelMapper)3 UserTokenDto (com.paascloud.base.dto.UserTokenDto)2 OAuth2ClientProperties (com.paascloud.security.core.properties.OAuth2ClientProperties)2 PageInfo (com.github.pagehelper.PageInfo)1 UacUser (com.paascloud.provider.model.domain.UacUser)1 UserAgent (eu.bitwalker.useragentutils.UserAgent)1