Browse Source

市北登陆

dev_shibei_match
jianjun 4 years ago
parent
commit
84ec95c237
  1. 8
      epmet-auth-client/pom.xml
  2. 32
      epmet-auth-client/src/main/java/com/epmet/auth/feign/EpmetAuthOpenFeignClient.java
  3. 20
      epmet-auth-client/src/main/java/com/epmet/auth/feign/fallback/EpmetAuthOpenFeignClientFallback.java
  4. 20
      epmet-auth-client/src/main/java/com/epmet/auth/feign/fallback/EpmetAuthOpenFeignClientFallbackFactory.java
  5. 24
      epmet-auth/src/main/java/com/epmet/controller/GovWebController.java
  6. 8
      epmet-auth/src/main/java/com/epmet/service/GovWebService.java
  7. 43
      epmet-auth/src/main/java/com/epmet/service/impl/GovWebServiceImpl.java
  8. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  9. 14
      epmet-gateway/pom.xml
  10. 22
      epmet-gateway/src/main/java/com/epmet/auth/InternalAuthProcessor.java

8
epmet-auth-client/pom.xml

@ -10,5 +10,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>epmet-auth-client</artifactId>
<dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-tools</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

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

@ -0,0 +1,32 @@
package com.epmet.auth.feign;
import com.epmet.auth.feign.fallback.EpmetAuthOpenFeignClientFallbackFactory;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 本服务对外开放的API,其他服务通过引用此client调用该服务
*
* @author yinzuomei@elink-cn.com
* @date 2020/6/4 13:25
*/
//@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallbackFactory = EpmetAuthOpenFeignClientFallbackFactory.class)
@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallbackFactory = EpmetAuthOpenFeignClientFallbackFactory.class, url = "http://localhost:8081")
public interface EpmetAuthOpenFeignClient {
/**
* @Description 根据客户Id查询志愿者用户Id集合
* @param uuid
* @param userId
* @param customerId
* @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);
}

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

@ -0,0 +1,20 @@
package com.epmet.auth.feign.fallback;
import com.epmet.auth.feign.EpmetAuthOpenFeignClient;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
/**
* 本服务对外开放的API,其他服务通过引用此client调用该服务
*
* @author yinzuomei@elink-cn.com
* @date 2020/6/4 13:26
*/
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);
}
}

20
epmet-auth-client/src/main/java/com/epmet/auth/feign/fallback/EpmetAuthOpenFeignClientFallbackFactory.java

@ -0,0 +1,20 @@
package com.epmet.auth.feign.fallback;
import com.epmet.auth.feign.EpmetAuthOpenFeignClient;
import com.epmet.commons.tools.exception.ExceptionUtils;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class EpmetAuthOpenFeignClientFallbackFactory implements FallbackFactory<EpmetAuthOpenFeignClient> {
private EpmetAuthOpenFeignClientFallback fallback = new EpmetAuthOpenFeignClientFallback();
@Override
public EpmetAuthOpenFeignClient create(Throwable cause) {
log.error(String.format("FeignClient调用发生异常,异常信息:%s", ExceptionUtils.getThrowableErrorStackTrace(cause)));
return fallback;
}
}

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

@ -6,18 +6,17 @@ import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.GovWebLoginFormDTO;
import com.epmet.dto.result.UserTokenResultDTO;
import com.epmet.service.GovWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @author sun
* @Description PC工作端-登陆服务
*/
@Slf4j
@RestController
@RequestMapping("govweb")
public class GovWebController {
@ -63,5 +62,22 @@ public class GovWebController {
return new Result().ok(publicKey);
}
/**
* desc: 根据用户id
*
* @return com.epmet.commons.tools.utils.Result
* @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) {
//判断是否非法登陆
/*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));
}
}

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

@ -16,4 +16,12 @@ public interface GovWebService {
* @Description PC工作端-工作人员登录
**/
UserTokenResultDTO login(GovWebLoginFormDTO formDTO);
/**
* desc:根据用户Id 生成token
* @return
* @param customerId
* @param userId
*/
String generateTokenBySSOKey(String customerId, String userId);
}

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

@ -1,8 +1,11 @@
package com.epmet.service.impl;
import com.epmet.common.token.constant.LoginConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode;
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.password.PasswordUtils;
import com.epmet.commons.tools.utils.CpUserDetailRedis;
@ -94,6 +97,46 @@ public class GovWebServiceImpl implements GovWebService {
}
@Override
public String generateTokenBySSOKey(String customerId, String userId) {
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");
tokenDto.setClient("web");
tokenDto.setUserId(userId);
tokenDto.setToken(token);
tokenDto.setUpdateTime(System.currentTimeMillis());
tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime());
tokenDto.setAgencyId(staffInfo.getAgencyId());
tokenDto.setRootAgencyId(staffInfo.getAgencyId());
//tokenDto.setDeptIdList(thirdLoginService.getDeptartmentIdList(userId));
//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;
}
/**
* 生成PC工作端token
* @author sun

11
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -636,4 +636,15 @@ public class RedisKeys {
public static String getOrgTreeCacheKey(String agencyId) {
return rootPrefix.concat("org:temp:orgtree").concat(agencyId);
}
/**
* desc:获取第三方登陆跳转 授权key
*
* @param customerId
* @param uuid
* @return
*/
public static String getIcLoginAuthKey(String customerId, String uuid) {
return rootPrefix.concat("sys:iclogin:authkey:").concat(customerId).concat(StrConstant.COLON).concat(uuid);
}
}

14
epmet-gateway/pom.xml

@ -77,6 +77,12 @@
<artifactId>epmet-admin-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-auth-client</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@ -129,8 +135,8 @@
<!-- gateway routes -->
<!-- 1、认证服务 -->
<!-- <gateway.routes.epmet-auth-server.uri>http://localhost:8081</gateway.routes.epmet-auth-server.uri>-->
<gateway.routes.epmet-auth-server.uri>lb://epmet-auth-server</gateway.routes.epmet-auth-server.uri>
<gateway.routes.epmet-auth-server.uri>http://localhost:8081</gateway.routes.epmet-auth-server.uri>
<!--<gateway.routes.epmet-auth-server.uri>lb://epmet-auth-server</gateway.routes.epmet-auth-server.uri>-->
<!-- 2、Admin服务 -->
<gateway.routes.epmet-admin-server.uri>lb://epmet-admin-server</gateway.routes.epmet-admin-server.uri>
<!-- 4、OSS服务 -->
@ -266,8 +272,8 @@
<nacos.service-list-changed-listening.enable>false</nacos.service-list-changed-listening.enable>
<!-- gateway routes -->
<!-- 1、认证服务 -->
<!-- <gateway.routes.epmet-auth-server.uri>http://localhost:8081</gateway.routes.epmet-auth-server.uri>-->
<gateway.routes.epmet-auth-server.uri>lb://epmet-auth-server</gateway.routes.epmet-auth-server.uri>
<gateway.routes.epmet-auth-server.uri>http://localhost:8081</gateway.routes.epmet-auth-server.uri>
<!--<gateway.routes.epmet-auth-server.uri>lb://epmet-auth-server</gateway.routes.epmet-auth-server.uri>-->
<!-- 2、Admin服务 -->
<!--<gateway.routes.epmet-admin-server.uri>http://localhost:8082</gateway.routes.epmet-admin-server.uri>-->
<gateway.routes.epmet-admin-server.uri>lb://epmet-admin-server</gateway.routes.epmet-admin-server.uri>

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

@ -1,11 +1,15 @@
package com.epmet.auth;
import com.alibaba.fastjson.JSON;
import com.epmet.auth.feign.EpmetAuthOpenFeignClient;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.Constant;
import com.epmet.commons.tools.constant.CustomerIdConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.BaseTokenDto;
import com.epmet.commons.tools.utils.CpUserDetailRedis;
import com.epmet.commons.tools.utils.Result;
import com.epmet.filter.CpProperty;
import com.epmet.jwt.JwtTokenUtils;
import io.jsonwebtoken.Claims;
@ -40,6 +44,8 @@ public class InternalAuthProcessor extends AuthProcessor {
@Autowired
private CpProperty cpProperty;
@Autowired
private EpmetAuthOpenFeignClient epmetAuthOpenFeignClient;
@Override
public ServerWebExchange auth(ServerWebExchange exchange, GatewayFilterChain chain) {
@ -70,6 +76,22 @@ public class InternalAuthProcessor extends AuthProcessor {
userId = (String) claims.get(AppClientConstant.USER_ID);
expiration = claims.getExpiration();
baseTokenDto = cpUserDetailRedis.get(app, client, userId, BaseTokenDto.class);
//市北数字社区 如果redis里不存在 则自动登陆 生成token放入redis
if (baseTokenDto == null){
Result<String> stringResult = epmetAuthOpenFeignClient.generateTokenBySSOKey("123", userId, CustomerIdConstant.SHI_BEI_CUSTOMER_ID);
if (stringResult != null && stringResult.success() && StringUtils.isNotBlank(stringResult.getData())){
baseTokenDto = new BaseTokenDto();
baseTokenDto.setApp(app);
baseTokenDto.setClient(client);
baseTokenDto.setUserId(userId);
String tokenNew = stringResult.getData();
//把传过来的token用新的token 替换
token = tokenNew;
baseTokenDto.setToken(tokenNew);
baseTokenDto.setCustomerId(CustomerIdConstant.SHI_BEI_CUSTOMER_ID);
}
logger.info("stringResult"+ JSON.toJSONString(stringResult));
}
}
}

Loading…
Cancel
Save