Search in sources :

Example 1 with UacUser

use of com.paascloud.provider.model.domain.UacUser 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 UacUser

use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.

the class UacUserTokenServiceImpl method refreshToken.

@Override
public String refreshToken(String accessToken, String refreshToken, HttpServletRequest request) throws HttpProcessException {
    String token;
    Map<String, Object> map = new HashMap<>(2);
    map.put("grant_type", "refresh_token");
    map.put("refresh_token", refreshToken);
    // 插件式配置请求参数(网址、请求参数、编码、client)
    Header[] headers = HttpHeader.custom().contentType(HttpHeader.Headers.APP_FORM_URLENCODED).authorization(request.getHeader(HttpHeaders.AUTHORIZATION)).build();
    HttpConfig config = HttpConfig.custom().headers(headers).url(refreshTokenUrl).map(map);
    token = HttpClientUtil.post(config);
    JSONObject jsonObj = JSON.parseObject(token);
    String accessTokenNew = (String) jsonObj.get("access_token");
    String refreshTokenNew = (String) jsonObj.get("refresh_token");
    String loginName = (String) jsonObj.get("loginName");
    // 更新本次token数据
    UserTokenDto tokenDto = this.getByAccessToken(accessToken);
    tokenDto.setStatus(UacUserTokenStatusEnum.ON_REFRESH.getStatus());
    UacUser uacUser = uacUserService.findUserInfoByLoginName(loginName);
    LoginAuthDto loginAuthDto = new LoginAuthDto(uacUser.getId(), uacUser.getLoginName(), uacUser.getUserName(), uacUser.getGroupId(), uacUser.getGroupName());
    this.updateUacUserToken(tokenDto, loginAuthDto);
    // 创建刷新token
    this.saveUserToken(accessTokenNew, refreshTokenNew, loginAuthDto, request);
    return token;
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) Header(org.apache.http.Header) HttpHeader(com.arronlong.httpclientutil.common.HttpHeader) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) HttpConfig(com.arronlong.httpclientutil.common.HttpConfig) LoginAuthDto(com.paascloud.base.dto.LoginAuthDto) UserTokenDto(com.paascloud.base.dto.UserTokenDto)

Example 3 with UacUser

use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.

the class AuthRestController method checkEmailActive.

/**
 * 校验邮箱.
 *
 * @param email the email
 *
 * @return the wrapper
 */
@PostMapping(value = "/checkEmailActive/{email:.+}")
@ApiOperation(httpMethod = "POST", value = "校验邮箱")
public Wrapper<Boolean> checkEmailActive(@PathVariable("email") String email) {
    UacUser uacUser = new UacUser();
    uacUser.setStatus(UacUserStatusEnum.ENABLE.getKey());
    uacUser.setEmail(email);
    int count = uacUserService.selectCount(uacUser);
    return WrapMapper.ok(count > 0);
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with UacUser

use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.

the class AuthRestController method checkPhoneActive.

/**
 * 校验手机号码.
 *
 * @param mobileNo the mobile no
 *
 * @return the wrapper
 */
@PostMapping(value = "/checkPhoneActive/{mobileNo}")
@ApiOperation(httpMethod = "POST", value = "校验手机号码")
public Wrapper<Boolean> checkPhoneActive(@PathVariable String mobileNo) {
    UacUser uacUser = new UacUser();
    uacUser.setStatus(UacUserStatusEnum.ENABLE.getKey());
    uacUser.setMobileNo(mobileNo);
    int count = uacUserService.selectCount(uacUser);
    return WrapMapper.ok(count > 0);
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with UacUser

use of com.paascloud.provider.model.domain.UacUser in project paascloud-master by paascloud.

the class UacUserCommonController method queryUserInfo.

/**
 * 根据userId查询用户详细信息(连表查询).
 *
 * @return the wrapper
 */
@PostMapping(value = "/queryUserInfo/{loginName}")
@ApiOperation(httpMethod = "POST", value = "根据userId查询用户详细信息")
public Wrapper<UserVo> queryUserInfo(@PathVariable String loginName) {
    logger.info("根据userId查询用户详细信息");
    UserVo userVo = new UserVo();
    UacUser uacUser = uacUserService.findByLoginName(loginName);
    uacUser = uacUserService.findUserInfoByUserId(uacUser.getId());
    List<UacRole> roleList = uacRoleService.findAllRoleInfoByUserId(uacUser.getId());
    List<MenuVo> authTree = uacRoleService.getOwnAuthTree(uacUser.getId());
    BeanUtils.copyProperties(uacUser, userVo);
    if (PublicUtil.isNotEmpty(roleList)) {
        userVo.setRoles(new HashSet<>(roleList));
    }
    userVo.setAuthTree(authTree);
    return WrapMapper.ok(userVo);
}
Also used : MenuVo(com.paascloud.provider.model.vo.MenuVo) UacUser(com.paascloud.provider.model.domain.UacUser) UserVo(com.paascloud.provider.model.vo.UserVo) UacRole(com.paascloud.provider.model.domain.UacRole) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

UacUser (com.paascloud.provider.model.domain.UacUser)17 ApiOperation (io.swagger.annotations.ApiOperation)8 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)4 UacBizException (com.paascloud.provider.model.exceptions.UacBizException)3 UserTokenDto (com.paascloud.base.dto.UserTokenDto)2 MenuVo (com.paascloud.provider.model.vo.MenuVo)2 SecurityUser (com.paascloud.security.core.SecurityUser)2 ModelMapper (org.modelmapper.ModelMapper)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 JSONObject (com.alibaba.fastjson.JSONObject)1 HttpConfig (com.arronlong.httpclientutil.common.HttpConfig)1 HttpHeader (com.arronlong.httpclientutil.common.HttpHeader)1 PageInfo (com.github.pagehelper.PageInfo)1 LogAnnotation (com.paascloud.core.annotation.LogAnnotation)1 MqMessageData (com.paascloud.provider.model.domain.MqMessageData)1 UacGroup (com.paascloud.provider.model.domain.UacGroup)1 UacGroupUser (com.paascloud.provider.model.domain.UacGroupUser)1 UacRole (com.paascloud.provider.model.domain.UacRole)1 UacUserToken (com.paascloud.provider.model.domain.UacUserToken)1 LoginRespDto (com.paascloud.provider.model.dto.user.LoginRespDto)1