Kaynağa Gözat

Merge remote-tracking branch 'origin/dev/20211117_2.1.4' into dev/20211117_2.1.4

chengyao 3 yıl önce
ebeveyn
işleme
547d762fbe

+ 28 - 5
src/main/java/com/diagbot/config/AuthExceptionEntryPoint.java

@@ -1,9 +1,13 @@
 package com.diagbot.config;
 
+import com.diagbot.facade.SysUserFacade;
 import com.diagbot.util.StringUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.AuthenticationException;
 import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+import org.springframework.stereotype.Component;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -16,22 +20,32 @@ import java.util.Map;
  * @Author songxl
  * @Date 2021/11/30
  */
+@Component
 public class AuthExceptionEntryPoint implements AuthenticationEntryPoint {
-
+    @Autowired
+    private SysUserFacade userFacade;
 
     @Override
     public void commence(HttpServletRequest request, HttpServletResponse response,
                          AuthenticationException authException)
             throws ServletException {
         Map map = new HashMap();
-        if (StringUtil.isNotEmpty(authException.getMessage())&&authException.getMessage().contains("Access token expired")) {
+        if (StringUtil.isNotEmpty(authException.getMessage()) && authException.getMessage().contains("Access token expired")) {
             map.put("code", "10020011");
             map.put("msg", "登录超时。为确保您的账户安全,系统已自动退出,请重新登录。");
             response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-        }else {
+        } else {
+            //登录前的获取登录页面的请求接口不知道什么原因会抛出未认证(Full authentication is required to access this resource)
+            //如果抛出未认证在这个调用这个服务接口返回消息
             response.setStatus(HttpServletResponse.SC_OK);
-            map.put("code", "00000001");
-            map.put("msg", authException.getMessage());
+            if (matchers("/sys/user/getHospitalMark", request)) {
+                map.put("code", "0");
+                map.put("msg", "");
+                map.put("data", userFacade.getHospitalMark());
+            } else {
+                map.put("code", "00000001");
+                map.put("msg", authException.getMessage());
+            }
         }
         response.setContentType("application/json");
         try {
@@ -41,4 +55,13 @@ public class AuthExceptionEntryPoint implements AuthenticationEntryPoint {
             throw new ServletException();
         }
     }
+
+
+    private boolean matchers(String url, HttpServletRequest request) {
+        AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
+        if (matcher.matches(request)) {
+            return true;
+        }
+        return false;
+    }
 }

+ 6 - 2
src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -30,12 +30,14 @@ import java.io.IOException;
 @ComponentScan({"com.diagbot.config"})
 public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
     Logger log = LoggerFactory.getLogger(ResourceServerConfigurer.class);
+    @Autowired
+    private AuthExceptionEntryPoint authExceptionEntryPoint;
 
     @Override
     public void configure(HttpSecurity http) throws Exception {
         http.cors()
                 .and()
-                .exceptionHandling().authenticationEntryPoint(new AuthExceptionEntryPoint())
+                .exceptionHandling().authenticationEntryPoint(authExceptionEntryPoint)
                 .and()
                 .csrf().disable()
                 .authorizeRequests()
@@ -283,12 +285,14 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
                 .antMatchers("/**").authenticated();
         //                .antMatchers("/**").permitAll();
     }
+
     @Override
     public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
         log.info("Configuring ResourceServerSecurityConfigurer");
         resources.resourceId("user-service").tokenStore(new JwtTokenStore(jwtTokenEnhancerClient()));
-        resources.authenticationEntryPoint(new AuthExceptionEntryPoint());
+        resources.authenticationEntryPoint(authExceptionEntryPoint);
     }
+
     @Autowired
     private CustomAccessTokenConverter customAccessTokenConverter;
 

+ 4 - 4
src/main/resources/application-dev.yml

@@ -59,7 +59,7 @@ spring:
     druid:
       driver-class-name: com.mysql.cj.jdbc.Driver
       platform: mysql
-      url: jdbc:mysql://192.168.2.236:3306/qc?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true
+      url: jdbc:mysql://192.168.2.237:3306/qc?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true
       username: root
       password: lantone
       # 连接池的配置信息
@@ -111,9 +111,9 @@ spring:
     database:
       cache: 8 # cache索引
       token: 8 # Token索引
-    host: 192.168.2.236  #Redis服务器地址
-    port: 6379 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
-    password: lantone # Redis服务器连接密码(默认为空)
+    host: 192.168.2.237  #Redis服务器地址
+    port: 63791 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
+    password: emrais # Redis服务器连接密码(默认为空)
     lettuce:
       pool:
         max-active: 8 # 连接池最大连接数(使用负值表示没有限制)

+ 4 - 4
src/main/resources/application-local.yml

@@ -111,9 +111,9 @@ spring:
     database:
       cache: 8 # cache索引
       token: 8 # Token索引
-    host: 192.168.2.236  #Redis服务器地址
-    port: 6378 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
-    password: lantone # Redis服务器连接密码(默认为空)
+    host: 192.168.2.237  #Redis服务器地址
+    port: 63791 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
+    password: emrais # Redis服务器连接密码(默认为空)
     lettuce:
       pool:
         max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
@@ -164,7 +164,7 @@ oath.self.address: http://${myhost}:${server.port}
 
 # 加解密开关
 encrypt:
-  enable: false
+  enable: true
 
 swagger:
   enable: true

+ 1 - 1
src/main/resources/application-pre.yml

@@ -111,7 +111,7 @@ spring:
     database:
       cache: 8 # cache索引
       token: 8 # Token索引
-    host: 192.168.2.121  #Redis服务器地址
+    host: 192.168.2.125  #Redis服务器地址
     port: 6379 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
     password: lantone # Redis服务器连接密码(默认为空)
     lettuce:

+ 4 - 4
src/main/resources/application-pro.yml

@@ -59,9 +59,9 @@ spring:
     druid:
       driver-class-name: com.mysql.cj.jdbc.Driver
       platform: mysql
-      url: jdbc:mysql://192.168.2.122:3306/qc?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true
+      url: jdbc:mysql://192.168.2.125:3308/qc?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true
       username: root
-      password: lantone
+      password: LangT0ng@122lt
       # 连接池的配置信息
       # 初始化大小,最小,最大
       initialSize: 5
@@ -111,8 +111,8 @@ spring:
     database:
       cache: 8 # cache索引
       token: 8 # Token索引
-    host: 192.168.2.122  #Redis服务器地址
-    port: 6379 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
+    host: 192.168.2.125  #Redis服务器地址
+    port: 63791 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
     password: lantone # Redis服务器连接密码(默认为空)
     lettuce:
       pool:

+ 1 - 1
src/main/resources/application-test.yml

@@ -111,7 +111,7 @@ spring:
     database:
       cache: 8 # cache索引
       token: 8 # Token索引
-    host: 192.168.2.241  #Redis服务器地址
+    host: 192.168.2.126  #Redis服务器地址
     port: 6379 # Redis服务器连接端口(本地环境端口6378,其他环境端口是6379)
     password: lantone # Redis服务器连接密码(默认为空)
     lettuce: