Jelajahi Sumber

feat: 修改为新的认证接口

huangzqa 1 tahun lalu
induk
melakukan
55341522e4

+ 15 - 6
approve-api/src/main/java/com/dragonsoft/dcuc/approve/model/resp/bim/ZeroTrustAppItemUserTokenInfoRespVO.java

@@ -1,7 +1,6 @@
 package com.dragonsoft.dcuc.approve.model.resp.bim;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -17,7 +16,7 @@ import java.util.Date;
  * @author huangzqa
  * @date 2022/8/1
  */
-@JsonPropertyOrder({"id", "pid", "orgCode", "ip", "mid", "env"})
+@JsonPropertyOrder({"userTokenId", "pid", "orgCode", "ip", "mid", "env"})
 @Data
 @ApiModel(value = "应用令牌信息中的用户令牌信息")
 public class ZeroTrustAppItemUserTokenInfoRespVO {
@@ -25,14 +24,12 @@ public class ZeroTrustAppItemUserTokenInfoRespVO {
     /**
      * 用户令牌标识
      */
-    @JsonProperty("Id")
     @ApiModelProperty(value = "用户令牌标识")
-    private String id;
+    private String userTokenId;
 
     /**
      * 用户标识
      */
-    @JsonProperty("pId")
     @ApiModelProperty(value = "用户标识")
     private String pid;
 
@@ -42,6 +39,12 @@ public class ZeroTrustAppItemUserTokenInfoRespVO {
     @ApiModelProperty(value = "组织机构编码")
     private String orgCode;
 
+    /**
+     * 用户IP
+     */
+    @ApiModelProperty(value = "用户IP")
+    private String ip;
+
     /**
      * 用户名称
      */
@@ -51,7 +54,6 @@ public class ZeroTrustAppItemUserTokenInfoRespVO {
     /**
      * 终端设备标识
      */
-    @JsonProperty("mId")
     @ApiModelProperty(value = "终端设备标识")
     private String mid;
 
@@ -74,4 +76,11 @@ public class ZeroTrustAppItemUserTokenInfoRespVO {
     @ApiModelProperty(value = "应用令牌到期时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date expireAt;
+
+
+    /**
+     * 用户令牌签名
+     */
+    @ApiModelProperty(value = "用户令牌签名")
+    private String sign;
 }

+ 8 - 4
approve-api/src/main/java/com/dragonsoft/dcuc/approve/model/resp/bim/ZeroTrustAppTokenInfoRespVO.java

@@ -1,7 +1,6 @@
 package com.dragonsoft.dcuc.approve.model.resp.bim;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -17,7 +16,7 @@ import java.util.Date;
  * @author huangzqa
  * @date 2022/8/1
  */
-@JsonPropertyOrder({"id", "createTime", "expireAt", "appId", "userToken", "sign"})
+@JsonPropertyOrder({"appTokenId", "createTime", "expireAt", "appId", "userToken", "sign"})
 @ApiModel(value = "应用令牌信息服务")
 @Data
 public class ZeroTrustAppTokenInfoRespVO {
@@ -26,8 +25,7 @@ public class ZeroTrustAppTokenInfoRespVO {
      * 应用令牌ID
      */
     @ApiModelProperty(value = "应用令牌ID")
-    @JsonProperty("Id")
-    private String id;
+    private String appTokenId;
 
     /**
      * 应用令牌创建时间
@@ -56,4 +54,10 @@ public class ZeroTrustAppTokenInfoRespVO {
     @ApiModelProperty(value = "用户令牌详细信息")
     private ZeroTrustAppItemUserTokenInfoRespVO userToken;
 
+    /**
+     * 应用令牌签名
+     */
+    @ApiModelProperty(value = "应用令牌签名")
+    private String sign;
+
 }

+ 35 - 22
approve-core-service/pom.xml

@@ -63,11 +63,7 @@
 
 
         <!--配置第三方组件开始-->
-        <!--oracle 引入-->
-        <!--<dependency>-->
-        <!--<groupId>com.oracle</groupId>-->
-        <!--<artifactId>ojdbc6</artifactId>-->
-        <!--</dependency>-->
+
         <!--mysql 引入-->
         <dependency>
             <groupId>mysql</groupId>
@@ -88,6 +84,15 @@
             <artifactId>spring-kafka</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.dragonsoft</groupId>
+            <artifactId>sm-tools-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.dragonsoft</groupId>
+            <artifactId>sm-tools-local</artifactId>
+        </dependency>
+
         <!--对接审计-->
         <dependency>
             <groupId>com.dragonsoft</groupId>
@@ -145,22 +150,7 @@
         </dependency>
         <!--工作流-->
         <!--nosql api依赖开始-->
-        <!--<dependency>
-            <groupId>com.dragonsoft.dyy</groupId>
-            <artifactId>nosql-plugins-springconfig</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>com.dragonsoft.dyy</groupId>
-            <artifactId>nosql-kafka-api</artifactId>
-            <version>1.0.1-SNAPSHOT</version>
-            <exclusions>
-                <exclusion>
-                    <artifactId>nosql-api</artifactId>
-                    <groupId>com.dragonsoft.dyy</groupId>
-                </exclusion>
-            </exclusions>
-        </dependency>-->
+
         <dependency>
             <groupId>com.dragonsoft</groupId>
             <artifactId>dcms-mq-client-model</artifactId>
@@ -172,13 +162,36 @@
             <groupId>com.dragoninfo</groupId>
             <artifactId>dcuc-duceap-model</artifactId>
             <version>2.1.2-SNAPSHOT</version>
-            <scope>compile</scope>
         </dependency>
 
         <dependency>
             <groupId>com.github.rholder</groupId>
             <artifactId>guava-retrying</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.github.dreamhead</groupId>
+            <artifactId>moco-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.github.dreamhead</groupId>
+            <artifactId>moco-junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>it.ozimov</groupId>
+            <artifactId>embedded-redis</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <artifactId>slf4j-simple</artifactId>
+                    <groupId>org.slf4j</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 55 - 2
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/impl/BimBusinessImpl.java

@@ -8,11 +8,13 @@ import com.dragonsoft.dcuc.approve.model.resp.bim.ZeroTrustAppTokenInfoRespVO;
 import com.dragonsoft.dcuc.approve.model.resp.v3.ZeroTrustResultRespVO;
 import com.dragonsoft.dcuc.approve.properties.BimProperties;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
+import com.dragonsoft.smtools.loader.SMFactory;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.RequestEntity;
 import org.springframework.http.ResponseEntity;
@@ -20,6 +22,8 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
 import java.net.URI;
+import java.util.Locale;
+import java.util.Map;
 
 /**
  * <p>
@@ -37,6 +41,21 @@ public class BimBusinessImpl implements IBimBusiness {
 
     private RestTemplate restTemplate;
 
+    private ObjectMapper objectMapper;
+
+    private SMFactory smFactory;
+
+    @Autowired
+    public void setSmFactory(SMFactory smFactory) {
+        this.smFactory = smFactory;
+    }
+
+    @Qualifier("dragonObjectMapper")
+    @Autowired
+    public void setObjectMapper(ObjectMapper objectMapper) {
+        this.objectMapper = objectMapper;
+    }
+
     @Autowired
     public void setBimProperties(BimProperties bimProperties) {
         this.bimProperties = bimProperties;
@@ -57,7 +76,7 @@ public class BimBusinessImpl implements IBimBusiness {
         ZeroTrustAppTokenInfoReqVO zeroTrustAppTokenInfoReqVO = new ZeroTrustAppTokenInfoReqVO();
         zeroTrustAppTokenInfoReqVO.setAppTokenId(appTokenId);
 
-        log.info("zeroTrustAppTokenInfoReqVO :{}", JsonUtils.toJSONString(zeroTrustAppTokenInfoReqVO));
+        log.info("获取应用令牌信息请求 :{}", JsonUtils.toJSONString(zeroTrustAppTokenInfoReqVO));
         RequestEntity<ZeroTrustAppTokenInfoReqVO> httpEntity = new RequestEntity<>(zeroTrustAppTokenInfoReqVO, HttpMethod.POST, URI.create(reqUrl));
 
         TypeReference<ZeroTrustResultRespVO<ZeroTrustAppTokenInfoRespVO>> parameterizedTypeReference =
@@ -65,9 +84,11 @@ public class BimBusinessImpl implements IBimBusiness {
                 };
 
         ResponseEntity<String> responseEntity = restTemplate.exchange(httpEntity, String.class);
+        log.info("获取应用令牌信息返回参数 :{}", JsonUtils.toJSONString(responseEntity));
+
         if (responseEntity.getStatusCode().is2xxSuccessful()) {
-            ObjectMapper objectMapper = new ObjectMapper();
             String responseEntityJsonBody = responseEntity.getBody();
+
             ZeroTrustResultRespVO<ZeroTrustAppTokenInfoRespVO> responseEntityBody = null;
             try {
                 responseEntityBody = objectMapper.readValue(responseEntityJsonBody, parameterizedTypeReference);
@@ -89,4 +110,36 @@ public class BimBusinessImpl implements IBimBusiness {
         }
         return null;
     }
+
+    /**
+     * 校验用户令牌签名
+     *
+     * @param useTokenInfoMap 用户令牌信息
+     * @return 签名结果
+     */
+    protected boolean checkUserTokenSign(Map<String, Object> useTokenInfoMap) {
+        String userTokenId = useTokenInfoMap.getOrDefault("userTokenId", "").toString();
+        String createTime = useTokenInfoMap.getOrDefault("createTime", "").toString();
+        String expireAt = useTokenInfoMap.getOrDefault("expireAt", "").toString();
+        String pid = useTokenInfoMap.getOrDefault("pid", "").toString();
+        String orgCode = useTokenInfoMap.getOrDefault("orgCode", "").toString();
+        String ip = useTokenInfoMap.getOrDefault("ip", "").toString();
+        String mid = useTokenInfoMap.getOrDefault("mid", "").toString();
+        String env = useTokenInfoMap.getOrDefault("env", "").toString();
+        String sign = useTokenInfoMap.getOrDefault("sign", "").toString();
+
+        String origin = "userTokenId=" + userTokenId +
+                "&createTime=" + createTime + "&expireAt=" + expireAt + "&pid=" + pid + "&orgCode=" + orgCode
+                + "&ip=" + ip + "&mid=" + mid + "&env=" + env;
+        log.info("用户令牌校验签名签名原文:{}", origin);
+
+        String generalSign = smFactory.getSM3().summary(origin).toString().toLowerCase(Locale.ROOT);
+        log.info("用户令牌校验签名签名后的值:{}", generalSign);
+        log.info("用户令牌校验签名令牌信息中的签名值:{}", sign);
+
+        boolean ignoreCase = generalSign.equalsIgnoreCase(sign);
+        log.info("用户令牌:{} 校验签名签名结果:{}", userTokenId, ignoreCase);
+
+        return ignoreCase;
+    }
 }

+ 39 - 2
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/config/ApproveConfig.java

@@ -4,11 +4,20 @@ import com.dragoninfo.dcuc.common.http.SkipSslVerificationHttpRequestFactory;
 import com.dragonsoft.auditlog.collection.qmtj.provider.IRestTemplateProvider;
 import com.dragonsoft.dcuc.approve.componet.SkipSslRestTemplateProvider;
 import com.dragonsoft.dcuc.approve.filter.ProofsFilter;
+import com.dragonsoft.dcuc.approve.properties.ApproveProperties;
+import com.dragonsoft.smtools.loader.SMFactory;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.client.RestTemplate;
 
+import java.lang.reflect.InvocationTargetException;
+
 /**
  * <p>
  *
@@ -17,9 +26,17 @@ import org.springframework.web.client.RestTemplate;
  * @author huangzqa
  * @date 2021/6/30
  */
+@Slf4j
 @Configuration
 public class ApproveConfig {
 
+    private ApproveProperties approveProperties;
+
+    @Autowired
+    public void setApproveProperties(ApproveProperties approveProperties) {
+        this.approveProperties = approveProperties;
+    }
+
     @Bean
     public IRestTemplateProvider restTemplateProvider() {
         return new SkipSslRestTemplateProvider();
@@ -29,11 +46,31 @@ public class ApproveConfig {
     public RestTemplate restTemplate() {
         SkipSslVerificationHttpRequestFactory skipSslVerificationHttpRequestFactory
                 = new SkipSslVerificationHttpRequestFactory();
-        skipSslVerificationHttpRequestFactory.setReadTimeout(5000);
-        skipSslVerificationHttpRequestFactory.setConnectTimeout(5000);
+        skipSslVerificationHttpRequestFactory.setReadTimeout(approveProperties.getRequestTimeout());
+        skipSslVerificationHttpRequestFactory.setConnectTimeout(approveProperties.getRequestTimeout());
         return new RestTemplate(skipSslVerificationHttpRequestFactory);
     }
 
+    @Qualifier("dragonObjectMapper")
+    @Bean()
+    public ObjectMapper dragonObjectMapper() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        // 忽略不对应的字段
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        return objectMapper;
+    }
+
+    @Bean
+    public SMFactory smFactory() {
+        try {
+            return SMFactory.init(approveProperties.getSmTypeEnum());
+        } catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
+            log.error("国密初始化错误", e);
+        }
+        return null;
+    }
+
+
     @Bean
     public ProofsFilter proofsFilter() {
         return new ProofsFilter();

+ 12 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/properties/ApproveProperties.java

@@ -1,5 +1,6 @@
 package com.dragonsoft.dcuc.approve.properties;
 
+import com.dragonsoft.smtools.enums.SmTypeEunm;
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
@@ -38,5 +39,16 @@ public class ApproveProperties {
      * 权限中心地址
      */
     private String authServiceUrl;
+    /**
+     * 国密类型
+     */
+    private SmTypeEunm smTypeEnum = SmTypeEunm.Local;
+
+    /**
+     * 单位毫秒
+     * 10000
+     */
+    private Integer requestTimeout = 10000;
+
 
 }

+ 6 - 0
approve-core-service/src/main/resources/conf/local.properties

@@ -0,0 +1,6 @@
+local.sm2.prik=e1fd3231e230c7f20bda06d0e652650a924a66642ce2313c0abd5f3ee84c411d
+local.sm2.pubk=04265e9b4c487992cbd0ef4b2d26d31f9a09cbdca788224fe324b03484fa6271d90e21f77feb8c25300cf6b785c2f24d5cba2ccf5e2a58c23d6beea296bf607cea
+local.sm4.secretKey=JeF8U9wHFOMfs2Y8
+local.sm4.iv=UISwD9fW6cFh9SNS
+local.sm4.hexString=false
+local.sm2.mode=C1C3C2

+ 76 - 57
approve-core-service/src/test/java/com/dragonsoft/dcuc/approve/business/impl/BimBusinessImplTest.java

@@ -4,19 +4,21 @@ import com.dragoninfo.dcuc.common.http.SkipSslVerificationHttpRequestFactory;
 import com.dragonsoft.dcuc.approve.model.resp.bim.ZeroTrustAppItemUserTokenInfoRespVO;
 import com.dragonsoft.dcuc.approve.model.resp.bim.ZeroTrustAppTokenInfoRespVO;
 import com.dragonsoft.dcuc.approve.properties.BimProperties;
+import com.dragonsoft.smtools.enums.SmTypeEunm;
+import com.dragonsoft.smtools.loader.SMFactory;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.dreamhead.moco.HttpServer;
+import com.github.dreamhead.moco.Runner;
+import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.test.web.client.ExpectedCount;
-import org.springframework.test.web.client.MockRestServiceServer;
-import org.springframework.test.web.client.match.MockRestRequestMatchers;
-import org.springframework.test.web.client.response.MockRestResponseCreators;
 import org.springframework.web.client.RestTemplate;
 
-import java.net.URI;
+import java.util.HashMap;
+
+import static com.github.dreamhead.moco.Moco.*;
 
 /**
  * <p>
@@ -28,72 +30,89 @@ import java.net.URI;
  */
 public class BimBusinessImplTest {
 
-    private RestTemplate restTemplate;
+    public static Runner runner;
+
 
-    private MockRestServiceServer mockRestServiceServer;
+    String identityUrl = "http://127.0.0.1:8080";
+    String appInfoUrl = "/idp/rest/getAppTokenInfo";
+
+    BimBusinessImpl bimBusiness;
 
     @Before
-    public void before() {
+    public void before() throws Exception {
+        HttpServer httpServer = httpServer(8080, log());
+
+        httpServer.request(by(uri(appInfoUrl)))
+                .response(pathResource("bim/getAppTokenInfo.json"));
+
+        runner = Runner.runner(httpServer);
+
+        runner.start();
+
         SkipSslVerificationHttpRequestFactory skipSslVerificationHttpRequestFactory
                 = new SkipSslVerificationHttpRequestFactory();
         skipSslVerificationHttpRequestFactory.setReadTimeout(5000);
         skipSslVerificationHttpRequestFactory.setConnectTimeout(5000);
-        restTemplate = new RestTemplate(skipSslVerificationHttpRequestFactory);
-
-        mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);
-    }
-
-    @Test
-    public void getAppTokenInfo() {
-        String identityUrl = "http://1.1.1.10:8080";
-        String appInfoUrl = "/idp/rest/getAppTokenInfo";
-
-        String reqUr = identityUrl + appInfoUrl;
-        String respBody = "{\n" +
-                "    \"result\": {\n" +
-                "        \"appId\": \"OA\",\n" +
-                "        \"createTime\": \"2022-07-27 14:05:04\",\n" +
-                "        \"expireAt\": \"2022-07-27 14:35:04\",\n" +
-                "        \"Id\": \"eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InRlc3QxMCIsImlhdCI6MTY1ODkwMTkwNCwiZXhwIjoyNzU3ODkwMTkwNCwidHlwZSI6ImFwcCIsIklEIjoiMWIzZjZmNjMtODgyNy00ZjRjLWE1YWEtNDUzMzRmMmRiOGE4IiwiYXBwSWQiOiJPQSIsInVpZCI6Ijk5YjBjZGRlZjdkNTExZWNhNjQ5MDAwYzI5YzQ5YmY1IiwidXNlclRva2VuSWQiOiIxODhiOGMwOS0xODdiLTRiMjAtOTUwYi03ZmY5ZWYwZTY5ZWEiLCJzZXNzaW9uSWQiOiI5NDQ0NjNkZjhkMWVhMzc5OTQ4MmMyZGEwMDg0YzZhYyJ9.zCy21HdojCtmSh_aoxj_gIhbVNlPYbpI9H4ilb1c-HvyxoBdRAoPnEckBjILBUgAXIHfz9W7fsDiQ0Cygb9DWw\",\n" +
-                "        \"userToken\": {\n" +
-                "            \"pId\": \"test10\",\n" +
-                "            \"name\": \"测试10\",\n" +
-                "            \"orgCode\": \"bamboocloud\",\n" +
-                "            \"mId\": \"1\",\n" +
-                "            \"env\": \"1\",\n" +
-                "            \"createTime\": \"2022-07-27 14:04:45\",\n" +
-                "            \"expireAt\": \"2022-07-27 14:35:04\",\n" +
-                "            \"Id\": \"eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InRlc3QxMCIsImlhdCI6MTY1ODkwMTg4NSwiZXhwIjoxNjg0ODIxODg1LCJ0eXBlIjoidXNlciIsIklEIjoiMTg4YjhjMDktMTg3Yi00YjIwLTk1MGItN2ZmOWVmMGU2OWVhIiwicmVtb3RlSXAiOiIxMS4xMS4xMS4xMSIsInNlc3Npb25JZCI6Ijk0NDQ2M2RmOGQxZWEzNzk5NDgyYzJkYTAwODRjNmFjIiwidWlkIjoiOTliMGNkZGVmN2Q1MTFlY2E2NDkwMDBjMjljNDliZjUiLCJvcmdhbml6YXRpb25Db2RlIjoiYmFtYm9vY2xvdWQiLCJkZXZPbmx5SWQiOiIiLCJlcXVpcG1lbnRUeXBlIjoiIn0.5pGkVDtz4KwFytwjQVkmapOV2QI0EO_1x0HifCKfkdWibGjMb4t8ev5oNx59FhM-NO0v2-BH0s3WyQ-XA19Elg\"\n" +
-                "        }\n" +
-                "    },\n" +
-                "    \"status_code\": \"0000\",\n" +
-                "    \"message\": \"success\"\n" +
-                "}  \n";
-
-        mockRestServiceServer.expect(ExpectedCount.once(),
-                        MockRestRequestMatchers.requestTo(URI.create(reqUr))
-                ).andExpect(MockRestRequestMatchers.method(HttpMethod.POST))
-                .andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK)
-                        .contentType(MediaType.APPLICATION_JSON)
-                        .body(respBody));
-
+        RestTemplate restTemplate = new RestTemplate(skipSslVerificationHttpRequestFactory);
         BimProperties bimProperties = new BimProperties();
         bimProperties.setIdentityUrl(identityUrl);
 
-        BimBusinessImpl bimBusiness = new BimBusinessImpl();
+        ObjectMapper objectMapper = new ObjectMapper();
+        // 忽略不对应的字段
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+        SMFactory smFactory = SMFactory.init(SmTypeEunm.Local);
+
+        bimBusiness = new BimBusinessImpl();
         bimBusiness.setRestTemplate(restTemplate);
         bimBusiness.setBimProperties(bimProperties);
+        bimBusiness.setObjectMapper(objectMapper);
+        bimBusiness.setSmFactory(smFactory);
+    }
+
+    @AfterClass
+    public static void stop() {
+        runner.stop();
+    }
 
-        String appTokenId = "22222";
+    @Test
+    public void getAppTokenInfo() {
+
+        String appTokenId = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InpoYW5wZW5nIiwiaWF0IjoxNjg2ODEwOTYzLCJleHAiOjE2ODk0MDI5NjMsInR5cGUiOiJhcHAiLCJJRCI6IjY0ZDBmY2RjLTAyMWMtNGM0My05ZWQxLThkYTgyYzJmYmY5ZiIsImFwcElkIjoiZGVtbzEiLCJ1aWQiOiIyMDIyMTEyOTE2MTEyNDI3NS01NTBCLUNDQTdBRDRBNCIsInVzZXJUb2tlbklkIjoiYjNlYjMzZDItYjI0My00YWQ4LTg5ZjEtOTJkNzljMWNjNTE3Iiwic2Vzc2lvbklkIjoiNjAwMzdiN2JkYjhiNTQ2MWFiYmFmOTNhOWM1ZDZiNTMifQ.C4QagXSAT5k4H9tDoZOS_4DypXIBNi4gZqB_AZQ40eEWhSQAHBTWEik86mxIuu4qCTBMBPJ28kjdXJEDCfgTMQ";
         ZeroTrustAppTokenInfoRespVO appTokenInfo = bimBusiness.getAppTokenInfo(appTokenId);
 
         Assert.assertNotNull(appTokenInfo);
-        Assert.assertEquals("OA", appTokenInfo.getAppId());
-        Assert.assertEquals("eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InRlc3QxMCIsImlhdCI6MTY1ODkwMTkwNCwiZXhwIjoyNzU3ODkwMTkwNCwidHlwZSI6ImFwcCIsIklEIjoiMWIzZjZmNjMtODgyNy00ZjRjLWE1YWEtNDUzMzRmMmRiOGE4IiwiYXBwSWQiOiJPQSIsInVpZCI6Ijk5YjBjZGRlZjdkNTExZWNhNjQ5MDAwYzI5YzQ5YmY1IiwidXNlclRva2VuSWQiOiIxODhiOGMwOS0xODdiLTRiMjAtOTUwYi03ZmY5ZWYwZTY5ZWEiLCJzZXNzaW9uSWQiOiI5NDQ0NjNkZjhkMWVhMzc5OTQ4MmMyZGEwMDg0YzZhYyJ9.zCy21HdojCtmSh_aoxj_gIhbVNlPYbpI9H4ilb1c-HvyxoBdRAoPnEckBjILBUgAXIHfz9W7fsDiQ0Cygb9DWw", appTokenInfo.getId());
+        Assert.assertEquals("demo1", appTokenInfo.getAppId());
+
+        Assert.assertEquals(appTokenId, appTokenInfo.getAppTokenId());
         ZeroTrustAppItemUserTokenInfoRespVO userToken = appTokenInfo.getUserToken();
-        Assert.assertEquals("eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InRlc3QxMCIsImlhdCI6MTY1ODkwMTg4NSwiZXhwIjoxNjg0ODIxODg1LCJ0eXBlIjoidXNlciIsIklEIjoiMTg4YjhjMDktMTg3Yi00YjIwLTk1MGItN2ZmOWVmMGU2OWVhIiwicmVtb3RlSXAiOiIxMS4xMS4xMS4xMSIsInNlc3Npb25JZCI6Ijk0NDQ2M2RmOGQxZWEzNzk5NDgyYzJkYTAwODRjNmFjIiwidWlkIjoiOTliMGNkZGVmN2Q1MTFlY2E2NDkwMDBjMjljNDliZjUiLCJvcmdhbml6YXRpb25Db2RlIjoiYmFtYm9vY2xvdWQiLCJkZXZPbmx5SWQiOiIiLCJlcXVpcG1lbnRUeXBlIjoiIn0.5pGkVDtz4KwFytwjQVkmapOV2QI0EO_1x0HifCKfkdWibGjMb4t8ev5oNx59FhM-NO0v2-BH0s3WyQ-XA19Elg", userToken.getId());
-        Assert.assertEquals("1", userToken.getMid());
-        Assert.assertEquals("test10", userToken.getPid());
+        String userTokenId = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InpoYW5wZW5nIiwiaWF0IjoxNjg2ODEwODU4LCJleHAiOjE2ODk0MDI4NTgsInR5cGUiOiJ1c2VyIiwiSUQiOiJiM2ViMzNkMi1iMjQzLTRhZDgtODlmMS05MmQ3OWMxY2M1MTciLCJyZW1vdGVJcCI6IjEyNy4wLjAuMSIsInNlc3Npb25JZCI6IjYwMDM3YjdiZGI4YjU0NjFhYmJhZjkzYTljNWQ2YjUzIiwidWlkIjoiMjAyMjExMjkxNjExMjQyNzUtNTUwQi1DQ0E3QUQ0QTQiLCJvcmdhbml6YXRpb25Db2RlIjoiYmFtYm9vY2xvdWQiLCJkZXZPbmx5SWQiOiIiLCJlcXVpcG1lbnRUeXBlIjoicGMifQ.opQczo6NVMuafO2ruKCCpT1YdrsKLP2vlUnETyPR8Al-CijmIgqE0oW_BkOJaCP_UX-BYLLhoPBDFriI5IrLMg";
+
+        Assert.assertEquals(userTokenId, userToken.getUserTokenId());
+        Assert.assertEquals("", userToken.getMid());
+        Assert.assertEquals("zhanpeng", userToken.getPid());
+
+    }
+
+    @Test
+    public void checkUserTokenSign() {
+        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
+        stringObjectHashMap.put("userTokenId", "1111111111111111");
+        stringObjectHashMap.put("createTime", "2023-05-30 17:32:45");
+        stringObjectHashMap.put("expireAt", "2023-05-30 19:32:45");
+        stringObjectHashMap.put("pid", "test");
+        stringObjectHashMap.put("orgCode", "1111");
+        stringObjectHashMap.put("ip", "127.0.0.1");
+        stringObjectHashMap.put("mid", "2222");
+        stringObjectHashMap.put("env", "pc");
+        stringObjectHashMap.put("sign", "4023c48d904bb2f908d5be02c867d5bbc1fe8ec590f583c76f970d3feff309a7");
+
+        boolean checkUserTokenSign = bimBusiness.checkUserTokenSign(stringObjectHashMap);
+        Assert.assertTrue(checkUserTokenSign);
+
+        stringObjectHashMap.put("env", "1222");
+        boolean checkUserTokenSign1 = bimBusiness.checkUserTokenSign(stringObjectHashMap);
+        Assert.assertFalse(checkUserTokenSign1);
 
     }
 }

+ 23 - 0
approve-core-service/src/test/resources/bim/getAppTokenInfo.json

@@ -0,0 +1,23 @@
+{
+  "result": {
+    "userToken": {
+      "createTime": "2023-06-15 14:34:18",
+      "orgCode": "bamboocloud",
+      "ip": "127.0.0.1",
+      "name": "zhanpeng",
+      "sign": "83522b44abfd628093490c969fc7df1741f410e940c18c21e0f0b1594bf2a761",
+      "mid": "",
+      "pid": "zhanpeng",
+      "userTokenId": "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InpoYW5wZW5nIiwiaWF0IjoxNjg2ODEwODU4LCJleHAiOjE2ODk0MDI4NTgsInR5cGUiOiJ1c2VyIiwiSUQiOiJiM2ViMzNkMi1iMjQzLTRhZDgtODlmMS05MmQ3OWMxY2M1MTciLCJyZW1vdGVJcCI6IjEyNy4wLjAuMSIsInNlc3Npb25JZCI6IjYwMDM3YjdiZGI4YjU0NjFhYmJhZjkzYTljNWQ2YjUzIiwidWlkIjoiMjAyMjExMjkxNjExMjQyNzUtNTUwQi1DQ0E3QUQ0QTQiLCJvcmdhbml6YXRpb25Db2RlIjoiYmFtYm9vY2xvdWQiLCJkZXZPbmx5SWQiOiIiLCJlcXVpcG1lbnRUeXBlIjoicGMifQ.opQczo6NVMuafO2ruKCCpT1YdrsKLP2vlUnETyPR8Al-CijmIgqE0oW_BkOJaCP_UX-BYLLhoPBDFriI5IrLMg",
+      "expireAt": "2023-06-15 16:36:41",
+      "env": "pc"
+    },
+    "appTokenId": "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJCQyIsInN1YiI6InpoYW5wZW5nIiwiaWF0IjoxNjg2ODEwOTYzLCJleHAiOjE2ODk0MDI5NjMsInR5cGUiOiJhcHAiLCJJRCI6IjY0ZDBmY2RjLTAyMWMtNGM0My05ZWQxLThkYTgyYzJmYmY5ZiIsImFwcElkIjoiZGVtbzEiLCJ1aWQiOiIyMDIyMTEyOTE2MTEyNDI3NS01NTBCLUNDQTdBRDRBNCIsInVzZXJUb2tlbklkIjoiYjNlYjMzZDItYjI0My00YWQ4LTg5ZjEtOTJkNzljMWNjNTE3Iiwic2Vzc2lvbklkIjoiNjAwMzdiN2JkYjhiNTQ2MWFiYmFmOTNhOWM1ZDZiNTMifQ.C4QagXSAT5k4H9tDoZOS_4DypXIBNi4gZqB_AZQ40eEWhSQAHBTWEik86mxIuu4qCTBMBPJ28kjdXJEDCfgTMQ",
+    "createTime": "2023-06-15 14:36:03",
+    "appId": "demo1",
+    "sign": "7bdc8e55f31e618192c51b52f81ad011cd45eaff0d22c78a5c2d81205d1b9389",
+    "expireAt": "2023-06-15 16:36:41"
+  },
+  "status_code": "0000",
+  "message": "操作成功"
+}

+ 35 - 2
pom.xml

@@ -15,11 +15,13 @@
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <duceap.version>2.1.0-SNAPSHOT</duceap.version>
-        <oracle.version>11.2.0.1.0</oracle.version>
         <mysql.version>5.1.49</mysql.version>
-        <lombok.version>1.18.8</lombok.version>
+        <lombok.version>1.18.24</lombok.version>
         <guava.retry.version>2.0.0</guava.retry.version>
         <junit.version>4.13.2</junit.version>
+        <moco.version>0.12.0</moco.version>
+        <embedded.redis.version>0.7.3</embedded.redis.version>
+        <sm.tools.version>1.2.1-SNAPSHOT</sm.tools.version>
     </properties>
     <artifactId>approve-core</artifactId>
     <packaging>pom</packaging>
@@ -35,13 +37,44 @@
                 <artifactId>guava-retrying</artifactId>
                 <version>${guava.retry.version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>com.dragonsoft</groupId>
+                <artifactId>sm-tools-api</artifactId>
+                <version>${sm.tools.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.dragonsoft</groupId>
+                <artifactId>sm-tools-local</artifactId>
+                <version>${sm.tools.version}</version>
+            </dependency>
+
             <dependency>
                 <groupId>junit</groupId>
                 <artifactId>junit</artifactId>
                 <version>${junit.version}</version>
                 <scope>test</scope>
             </dependency>
+            <dependency>
+                <groupId>it.ozimov</groupId>
+                <artifactId>embedded-redis</artifactId>
+                <version>${embedded.redis.version}</version>
+                <scope>test</scope>
+            </dependency>
 
+            <dependency>
+                <groupId>com.github.dreamhead</groupId>
+                <artifactId>moco-core</artifactId>
+                <version>${moco.version}</version>
+                <scope>test</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>com.github.dreamhead</groupId>
+                <artifactId>moco-junit</artifactId>
+                <version>${moco.version}</version>
+                <scope>test</scope>
+            </dependency>
             <!-- 导入duceap-cloud 2.1 POM定义-->
             <dependency>
                 <groupId>com.dragonsoft</groupId>