Search in sources :

Example 1 with OAuth2ClientProperties

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);
}
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 2 with OAuth2ClientProperties

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