Browse Source

居民端登陆改造 阶段1

dev_shibei_match
jianjun 4 years ago
parent
commit
d176bc76b4
  1. 6
      epmet-auth-client/src/main/java/com/epmet/auth/feign/EpmetAuthOpenFeignClient.java
  2. 4
      epmet-auth-client/src/main/java/com/epmet/auth/feign/fallback/EpmetAuthOpenFeignClientFallback.java
  3. 11
      epmet-auth/src/main/java/com/epmet/controller/GovWebController.java
  4. 4
      epmet-auth/src/main/java/com/epmet/service/GovWebService.java
  5. 61
      epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java
  6. 3
      epmet-gateway/src/main/java/com/epmet/auth/InternalAuthProcessor.java
  7. 4
      epmet-user/epmet-user-server/src/main/resources/mapper/UserDao.xml

6
epmet-auth-client/src/main/java/com/epmet/auth/feign/EpmetAuthOpenFeignClient.java

@ -23,10 +23,12 @@ public interface EpmetAuthOpenFeignClient {
* @param uuid
* @param userId
* @param customerId
* @param app
* @param client
* @return
* @author wangc
* @date 2020.08.13 10:22
**/
@PostMapping("/auth/govweb/generateTokenBySSOKey/{uuid}/{userId}")
Result<String> generateTokenBySSOKey(@PathVariable(value = "uuid")String uuid, @PathVariable String userId, @RequestParam String customerId);
@PostMapping("/auth/govweb/generateTokenBySSOKey/{uuid}/{userId}/{app}")
Result<String> generateTokenBySSOKey(@PathVariable(value = "uuid") String uuid, @PathVariable String userId, @RequestParam String customerId, @RequestParam String app, @RequestParam String client);
}

4
epmet-auth-client/src/main/java/com/epmet/auth/feign/fallback/EpmetAuthOpenFeignClientFallback.java

@ -13,8 +13,8 @@ import com.epmet.commons.tools.utils.Result;
*/
public class EpmetAuthOpenFeignClientFallback implements EpmetAuthOpenFeignClient {
@Override
public Result<String> generateTokenBySSOKey(String uuid, String userId, String customerId) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_AUTH_SERVER, "generateTokenBySSOKey", uuid, userId,customerId);
public Result<String> generateTokenBySSOKey(String uuid, String userId, String customerId, String app, String client) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_AUTH_SERVER, "generateTokenBySSOKey", uuid, userId,customerId,app,client);
}
}

11
epmet-auth/src/main/java/com/epmet/controller/GovWebController.java

@ -28,6 +28,8 @@ public class GovWebController {
@Value("${epmet.login.privateKey}")
private String privateKey;
/**
* @param formDTO
* @return
@ -69,14 +71,17 @@ public class GovWebController {
* @author LiuJanJun
* @date 2021/3/8 5:07 下午
*/
@PostMapping("generateTokenBySSOKey/{uuid}/{userId}")
public Result<String> generateTokenBySSOKey(@PathVariable(value = "uuid")String uuid,@PathVariable String userId,@RequestParam String customerId) {
@PostMapping("generateTokenBySSOKey/{uuid}/{userId}/{app}/{client}")
public Result<String> generateTokenBySSOKey(@PathVariable(value = "uuid")String uuid,@PathVariable String userId,
@RequestParam String customerId,
@RequestParam String client,
@RequestParam String app) {
//判断是否非法登陆
/*if (!redisUtils.hasKey(RedisKeys.getIcLoginAuthKey(customerId,uuid))){
log.error("有人使用userid:{} 非法登陆",userId);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode());
}*/
return new Result().ok(govWebService.generateTokenBySSOKey(customerId,userId));
return new Result().ok(govWebService.generateTokenBySSOKey(customerId,userId,app,client));
}

4
epmet-auth/src/main/java/com/epmet/service/GovWebService.java

@ -22,6 +22,8 @@ public interface GovWebService {
* @return
* @param customerId
* @param userId
* @param app
* @param client
*/
String generateTokenBySSOKey(String customerId, String userId);
String generateTokenBySSOKey(String customerId, String userId, String app, String client);
}

61
epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java

@ -7,15 +7,20 @@ import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.security.dto.GovTokenDto;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.security.password.PasswordUtils;
import com.epmet.commons.tools.utils.CpUserDetailRedis;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.UserDTO;
import com.epmet.dto.UserWechatDTO;
import com.epmet.dto.form.GovWebLoginFormDTO;
import com.epmet.dto.form.GovWebOperLoginFormDTO;
import com.epmet.dto.form.LoginCommonFormDTO;
import com.epmet.dto.result.GovWebOperLoginResultDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.feign.EpmetUserFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.jwt.JwtTokenProperties;
import com.epmet.jwt.JwtTokenUtils;
import com.epmet.service.CaptchaService;
@ -50,6 +55,8 @@ public class GovWebServiceImpl implements GovWebService {
private EpmetUserFeignClient epmetUserFeignClient;
@Autowired
private ThirdLoginServiceImpl thirdLoginService;
@Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
/**
* @param formDTO
@ -98,25 +105,31 @@ public class GovWebServiceImpl implements GovWebService {
}
@Override
public String generateTokenBySSOKey(String customerId, String userId) {
public String generateTokenBySSOKey(String customerId, String userId, String app, String client) {
// 生成token
Map<String, Object> map = new HashMap<>();
map.put(LoginConstant.CLIENT_APP, app);
map.put("client", client);
map.put("userId", userId);
String token = jwtTokenUtils.createToken(map);
if (LoginConstant.APP_RESI.equals(app)){
Result<UserDTO> userDTOResult = epmetUserOpenFeignClient.queryUserClient(userId);
if (!userDTOResult.success()&&userDTOResult.getData() != null){
log.error("居民信息不存在,customerId:{},userId:{}", customerId, userId);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode());
}
LoginCommonFormDTO formDTO = new LoginCommonFormDTO();
formDTO.setApp(app);
formDTO.setClient(client);
this.saveResiTokenDto(formDTO,userId, new UserWechatDTO(),token,customerId);
}else if (LoginConstant.APP_GOV.equals(app)){
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId);
if (staffInfo == null){
log.error("工作人员信息不存在,customerId:{},userId:{}", customerId, userId);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode());
}
// 生成token
Map<String, Object> map = new HashMap<>();
map.put("app", "gov");
map.put("client", "web");
map.put("userId", userId);
String token = jwtTokenUtils.createToken(map);
int expire = jwtTokenProperties.getExpire();
String orgIdPath = thirdLoginService.getOrgIdPath(userId);
String[] orgIdPathParts = orgIdPath.split(":");
GovTokenDto tokenDto = new GovTokenDto();
tokenDto.setCustomerId(customerId);
tokenDto.setApp("gov");
@ -131,7 +144,29 @@ public class GovWebServiceImpl implements GovWebService {
//tokenDto.setGridIdList(thirdLoginService.getGridIdList(userId));
//tokenDto.setRoleList(thirdLoginService.queryGovStaffRoles(userId, orgIdPathParts[orgIdPathParts.length - 1]));
//tokenDto.setOrgIdPath(orgIdPath);
cpUserDetailRedis.set(tokenDto, expire);
}
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss"));
return token;
}
/**
* @Description 将token存入redis
**/
private String saveResiTokenDto(LoginCommonFormDTO formDTO, String userId, UserWechatDTO userWechatDTO, String token, String customerId) {
int expire = jwtTokenProperties.getExpire();
TokenDto tokenDto = new TokenDto();
tokenDto.setCustomerId(customerId);
tokenDto.setApp(formDTO.getApp());
tokenDto.setClient(formDTO.getClient());
tokenDto.setUserId(userId);
//tokenDto.setOpenId(userWechatDTO.getWxOpenId());
//tokenDto.setSessionKey(userWechatDTO.getSessionKey());
//tokenDto.setUnionId(userWechatDTO.getUnionId());
tokenDto.setToken(token);
tokenDto.setUpdateTime(System.currentTimeMillis());
tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime());
cpUserDetailRedis.set(tokenDto, expire);
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss"));
return token;

3
epmet-gateway/src/main/java/com/epmet/auth/InternalAuthProcessor.java

@ -2,6 +2,7 @@ package com.epmet.auth;
import com.alibaba.fastjson.JSON;
import com.epmet.auth.feign.EpmetAuthOpenFeignClient;
import com.epmet.common.token.constant.LoginConstant;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.Constant;
import com.epmet.commons.tools.constant.CustomerIdConstant;
@ -81,7 +82,7 @@ public class InternalAuthProcessor extends AuthProcessor {
if (baseTokenDto == null){
//目前只支持市北客户ID 这样免登陆
if (CustomerIdConstant.SHI_BEI_CUSTOMER_ID.equals(customerId)){
Result<String> stringResult = epmetAuthOpenFeignClient.generateTokenBySSOKey("123", userId, customerId);
Result<String> stringResult = epmetAuthOpenFeignClient.generateTokenBySSOKey(LoginConstant.APP_PUBLIC, userId, customerId, app, client);
if (stringResult != null && stringResult.success() && StringUtils.isNotBlank(stringResult.getData())){
baseTokenDto = new BaseTokenDto();
baseTokenDto.setApp(app);

4
epmet-user/epmet-user-server/src/main/resources/mapper/UserDao.xml

@ -79,8 +79,8 @@
FROM
USER u
WHERE
u.DEL_FLAG = '0'
AND u.id = #{userId}
u.id = #{userId}
AND u.DEL_FLAG = '0'
</select>
<select id="selectIdNum" parameterType="map" resultType="java.lang.String">

Loading…
Cancel
Save