Forráskód Böngészése

springSecurity 替换位sa-token

ligang134 3 éve
szülő
commit
0ac983535b
55 módosított fájl, 1752 hozzáadás és 1482 törlés
  1. 27 12
      pom.xml
  2. 16 9
      src/main/java/com/ydtech/aop/GlobalExceptionHandler.java
  3. 2 2
      src/main/java/com/ydtech/aop/HttpAspect_CBIT.java
  4. 2 2
      src/main/java/com/ydtech/aop/LogAspect.java
  5. 30 0
      src/main/java/com/ydtech/components/CorsInterceptor.java
  6. 57 0
      src/main/java/com/ydtech/components/TokenInterceptor.java
  7. 61 11
      src/main/java/com/ydtech/config/MvcConfig.java
  8. 85 210
      src/main/java/com/ydtech/config/SwaggerConfig.java
  9. 120 120
      src/main/java/com/ydtech/config/WebSecurityConfig.java
  10. 36 30
      src/main/java/com/ydtech/core/page/BaseController.java
  11. 2 0
      src/main/java/com/ydtech/core/page/HttpResult.java
  12. 1 2
      src/main/java/com/ydtech/modules/admin/controller/DemoController.java
  13. 0 1
      src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java
  14. 3 3
      src/main/java/com/ydtech/modules/admin/controller/SysDictController.java
  15. 1 2
      src/main/java/com/ydtech/modules/admin/controller/SysLogController.java
  16. 31 11
      src/main/java/com/ydtech/modules/admin/controller/SysLoginController.java
  17. 2 3
      src/main/java/com/ydtech/modules/admin/controller/SysMenuController.java
  18. 6 7
      src/main/java/com/ydtech/modules/admin/controller/SysRoleController.java
  19. 1 0
      src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java
  20. 13 7
      src/main/java/com/ydtech/modules/admin/service/impl/WechatServiceImpl.java
  21. 6 5
      src/main/java/com/ydtech/modules/esm/controller/EsmTrainController.java
  22. 1 2
      src/main/java/com/ydtech/modules/esm/controller/EsmUserInternalController.java
  23. 2 2
      src/main/java/com/ydtech/modules/esm/service/impl/TrainServiceImpl.java
  24. 0 1
      src/main/java/com/ydtech/modules/fnc/controller/SubjectController.java
  25. 6 4
      src/main/java/com/ydtech/modules/fnc/controller/VoucherController.java
  26. 2 2
      src/main/java/com/ydtech/modules/ins/controller/InsCBITAPIController.java
  27. 3 3
      src/main/java/com/ydtech/modules/ins/controller/InsCBITController.java
  28. 2 4
      src/main/java/com/ydtech/modules/ins/model/yc/audit/Audit.java
  29. 222 25
      src/main/java/com/ydtech/modules/ins/model/yc/modelsQuery/ModelsQueryResponse.java
  30. 10 10
      src/main/java/com/ydtech/modules/ins/service/impl/InsAlltrustApiServiceImpl.java
  31. 2 2
      src/main/java/com/ydtech/modules/ins/service/impl/InsCBITServiceImpl.java
  32. 2 2
      src/main/java/com/ydtech/modules/ins/service/impl/InsPmainServiceImpl.java
  33. 10 11
      src/main/java/com/ydtech/modules/ins/service/impl/YongAnServiceImpl.java
  34. 19 28
      src/main/java/com/ydtech/modules/inv/controller/InvChannelsExternalBillsDetailsController.java
  35. 0 3
      src/main/java/com/ydtech/modules/inv/controller/InvCompanyController.java
  36. 3 3
      src/main/java/com/ydtech/modules/inv/controller/InvInvoiceInfoController.java
  37. 4 3
      src/main/java/com/ydtech/modules/inv/service/impl/InvoiceServiceImpl.java
  38. 10 10
      src/main/java/com/ydtech/modules/nai/controller/ChinaCoalInterface.java
  39. 4 2
      src/main/java/com/ydtech/modules/order/entity/vo/AccidentalDrivingQueryVo.java
  40. 5 3
      src/main/java/com/ydtech/modules/report/service/impl/PropertyInsuranceServiceImpl.java
  41. 29 29
      src/main/java/com/ydtech/security/GrantedAuthorityImpl.java
  42. 44 46
      src/main/java/com/ydtech/security/JwtAuthenticatioToken.java
  43. 35 35
      src/main/java/com/ydtech/security/JwtAuthenticationFilter.java
  44. 59 59
      src/main/java/com/ydtech/security/JwtAuthenticationProvider.java
  45. 133 133
      src/main/java/com/ydtech/security/JwtLoginFilter.java
  46. 103 103
      src/main/java/com/ydtech/security/JwtUserDetails.java
  47. 41 41
      src/main/java/com/ydtech/security/UserDetailsServiceImpl.java
  48. 316 316
      src/main/java/com/ydtech/security/utils/JwtTokenUtils.java
  49. 153 153
      src/main/java/com/ydtech/security/utils/SecurityUtils.java
  50. 1 5
      src/main/resources/application-prod.yml
  51. 0 5
      src/main/resources/application-test.yml
  52. 29 0
      src/main/resources/application.yml
  53. BIN
      src/main/resources/template/social_model.xls
  54. BIN
      src/main/resources/template/wage_model_A.xls
  55. BIN
      src/main/resources/template/wage_model_B.xls

+ 27 - 12
pom.xml

@@ -20,9 +20,7 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <java.version>1.8</java.version>
         <druid.version>1.1.10</druid.version>
-        <jwt.version>0.9.1</jwt.version>
         <fastjson.version>1.2.58</fastjson.version>
-<!--        <log4j.version>1.2.17</log4j.version>-->
         <kaptcha.version>0.0.9</kaptcha.version>
         <mapstruct.version>1.5.4.Final</mapstruct.version>
     </properties>
@@ -160,17 +158,7 @@
         <!--        </dependency>-->
 
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-security</artifactId>
-        </dependency>
 
-        <!-- jwt -->
-        <dependency>
-            <groupId>io.jsonwebtoken</groupId>
-            <artifactId>jjwt</artifactId>
-            <version>${jwt.version}</version>
-        </dependency>
         <!-- fastjson -->
         <dependency>
             <groupId>com.alibaba</groupId>
@@ -490,6 +478,33 @@
             <version>5.3</version>
         </dependency>
 
+        <!-- 解决@NotEmpty注解不生效 spring-boot 2.3.0 版本以后需要加入 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+
+
+        <!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-spring-boot-starter</artifactId>
+            <version>1.35.0.RC</version>
+        </dependency>
+
+        <!-- Sa-Token 整合 Redis (使用 jdk 默认序列化方式) -->
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-redis</artifactId>
+            <version>1.35.0.RC</version>
+        </dependency>
+
+
+
+
+
+
+
         <!-- rabbitmq依赖 -->
         <!--        <dependency>-->
         <!--            <groupId>org.springframework.boot</groupId>-->

+ 16 - 9
src/main/java/com/ydtech/aop/GlobalExceptionHandler.java

@@ -1,19 +1,23 @@
 package com.ydtech.aop;
 
+import cn.dev33.satoken.exception.NotLoginException;
+import cn.dev33.satoken.util.SaResult;
+import com.sun.xml.internal.ws.handler.HandlerException;
 import com.ydtech.aop.exception.DescribeException;
 import com.ydtech.aop.exception.ErrorInfo;
 import com.ydtech.core.page.HttpResult;
+import com.ydtech.core.page.HttpStatus;
 import com.ydtech.exception.SystemException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.dao.DuplicateKeyException;
-import org.springframework.security.access.AccessDeniedException;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.ObjectError;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
 
 import java.sql.SQLIntegrityConstraintViolationException;
 import java.util.List;
@@ -50,19 +54,19 @@ public class GlobalExceptionHandler {
 
     @ExceptionHandler(value = DescribeException.class)
     @ResponseBody
-    public HttpResult describeExceptionHandle(DescribeException describeException){
+    public HttpResult describeExceptionHandle(DescribeException describeException) {
         return HttpResult.error(describeException.getCode(), describeException.getMessage());
     }
 
     @ExceptionHandler(value = SystemException.class)
     @ResponseBody
-    public HttpResult systemExceptionHandle(SystemException systemException){
+    public HttpResult systemExceptionHandle(SystemException systemException) {
         return HttpResult.error(Integer.parseInt(systemException.getCode()), systemException.getMessage());
     }
 
     @ExceptionHandler(value = MethodArgumentNotValidException.class)
     @ResponseBody
-    public HttpResult methodArgumentNotValidExceptionHandle(MethodArgumentNotValidException methodArgumentNotValidException){
+    public HttpResult methodArgumentNotValidExceptionHandle(MethodArgumentNotValidException methodArgumentNotValidException) {
         BindingResult bindingResult = methodArgumentNotValidException.getBindingResult();
         List<ObjectError> objectErrors = bindingResult.getAllErrors();
         String message = objectErrors.get(0).getDefaultMessage();
@@ -72,15 +76,18 @@ public class GlobalExceptionHandler {
 
     @ExceptionHandler(value = DuplicateKeyException.class)
     @ResponseBody
-    public HttpResult sqlExceptionHandle(SQLIntegrityConstraintViolationException sqlException){
-        return HttpResult.error("违反唯一约束:" + sqlException.getMessage().substring(0,sqlException.getMessage().indexOf("for key")));
+    public HttpResult sqlExceptionHandle(SQLIntegrityConstraintViolationException sqlException) {
+        return HttpResult.error("违反唯一约束:" + sqlException.getMessage().substring(0, sqlException.getMessage().indexOf("for key")));
     }
 
-    @ExceptionHandler(value = AccessDeniedException.class)
+
+    @ExceptionHandler(value = NotLoginException.class)
     @ResponseBody
-    public HttpResult accessDeniedException(AccessDeniedException accessDeniedException){
-        return HttpResult.error(accessDeniedException.getMessage());
+    public HttpResult notLoginException(NotLoginException e) {
+//        e.printStackTrace();
+        return HttpResult.error(HttpStatus.SC_UNAUTHORIZED,"未登录状态,无法访问。");
     }
 
+
 }
 

+ 2 - 2
src/main/java/com/ydtech/aop/HttpAspect_CBIT.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.admin.model.SysLog;
 import com.ydtech.modules.admin.service.SysLogService;
-import com.ydtech.security.utils.JwtTokenUtils;
 import io.swagger.annotations.ApiOperation;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
@@ -52,7 +51,8 @@ public class HttpAspect_CBIT {
         HttpServletRequest request = attributes.getRequest();
 
         //请求人 url method ip class_method
-        SysLog sysLog = new SysLog(JwtTokenUtils.getUsernameFromRequest(request), request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
+        SysLog sysLog = new SysLog("", request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
+//        SysLog sysLog = new SysLog(JwtTokenUtils.getUsernameFromRequest(request), request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
 
         try {
             //获取注解注释

+ 2 - 2
src/main/java/com/ydtech/aop/LogAspect.java

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.admin.model.SysLog;
 import com.ydtech.modules.admin.service.SysLogService;
-import com.ydtech.security.utils.JwtTokenUtils;
 import io.swagger.annotations.ApiOperation;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
@@ -47,7 +46,8 @@ public class LogAspect {
         HttpServletRequest request = attributes.getRequest();
 
         //请求人 url method ip class_method
-        SysLog sysLog = new SysLog(JwtTokenUtils.getUsernameFromRequest(request), request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
+        SysLog sysLog = new SysLog("", request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
+//        SysLog sysLog = new SysLog(JwtTokenUtils.getUsernameFromRequest(request), request.getRequestURL().toString(), request.getMethod(), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), request.getRemoteAddr(), new Date());
 
         try {
             //获取注解注释

+ 30 - 0
src/main/java/com/ydtech/components/CorsInterceptor.java

@@ -0,0 +1,30 @@
+package com.ydtech.components;
+
+
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Component
+public class CorsInterceptor implements HandlerInterceptor {
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Methods", "*");
+        response.setHeader("Access-Control-Max-Age", "3600");
+        response.setHeader("Access-Control-Allow-Headers", "*");
+
+        // 如果是OPTIONS则结束请求
+        if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
+            response.setStatus(HttpStatus.NO_CONTENT.value());
+            return false;
+        }
+
+        return true;
+    }
+}

+ 57 - 0
src/main/java/com/ydtech/components/TokenInterceptor.java

@@ -0,0 +1,57 @@
+package com.ydtech.components;
+
+
+import cn.dev33.satoken.fun.SaParamFunction;
+import cn.dev33.satoken.interceptor.SaInterceptor;
+import cn.dev33.satoken.router.SaRouter;
+import cn.dev33.satoken.stp.StpUtil;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class TokenInterceptor {
+
+
+    public static SaInterceptor tokenInterceptor(){
+        List<String> notMatchList = new ArrayList<>();
+        notMatchList.add("/favicon.ico");//@TODO 静态资源应该不请求后台  需要确认
+        notMatchList.add("/captcha.jpg**"); // 验证码
+        notMatchList.add("/login");
+        notMatchList.add("/sendMsg");
+        notMatchList.add("/loginByPhone");
+        notMatchList.add("/esmUserInternalcheck/userRegist");
+        notMatchList.add("/dict/**");   //字典
+
+        //中煤
+        notMatchList.add("/zm/Underwriting");   //自动核保回调
+        notMatchList.add("/zm/ArtificialUnderwriting");   //人工核保回调
+        notMatchList.add("/order/zhongMeiApi/underwritingCallback");
+        notMatchList.add("/order/zhongMeiApi/auditCallback");
+
+
+        // swagger
+        notMatchList.add("/doc.html");
+        notMatchList.add("/webjars/**");
+        notMatchList.add("/swagger-resources");
+        notMatchList.add("/v2/**");
+
+        return new SaInterceptor(handler -> {
+            // 指定一条 match 规则
+            SaRouter
+                    .match("/**")    // 拦截的 path 列表,可以写多个 */
+                    .notMatch(notMatchList)        // 排除掉的 path 列表,可以写多个
+                    .check(r -> StpUtil.checkLogin());
+        });
+    }
+
+
+
+}

+ 61 - 11
src/main/java/com/ydtech/config/MvcConfig.java

@@ -1,9 +1,15 @@
 package com.ydtech.config;
 
+import cn.dev33.satoken.interceptor.SaInterceptor;
+import cn.dev33.satoken.router.SaHttpMethod;
+import cn.dev33.satoken.router.SaRouter;
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.ydtech.aop.RequestStringParamHandlerMethodArgumentResolver;
+import com.ydtech.components.CorsInterceptor;
+import com.ydtech.components.TokenInterceptor;
 import com.ydtech.config.properties.WechatOpenProperties;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
@@ -12,21 +18,25 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.http.converter.StringHttpMessageConverter;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.method.support.HandlerMethodArgumentResolver;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
+import javax.annotation.Resource;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.List;
 
 @Configuration
 public class MvcConfig implements WebMvcConfigurer {
 
-    @Autowired
+    @Resource
     private WechatOpenProperties wechatOpenProperties;
 
     @Value("${apk.path}")
@@ -38,6 +48,12 @@ public class MvcConfig implements WebMvcConfigurer {
     @Value("${upload.file.url}")
     private String uploadFileUrl;
 
+    @Resource
+    private CorsInterceptor corsInterceptor;
+    @Resource
+    private TokenInterceptor tokenInterceptor;
+
+
     @Bean
     public HttpMessageConverter<String> responseBody() {
         return new StringHttpMessageConverter(StandardCharsets.UTF_8);
@@ -48,16 +64,33 @@ public class MvcConfig implements WebMvcConfigurer {
         converters.add(responseBody());
     }
 
-    @Override
-    public void addCorsMappings(CorsRegistry registry) {
-        registry.addMapping("/**")    // 允许跨域访问的路径
-                .allowedOriginPatterns("*")
-//                .allowedOrigins("*")    // 允许跨域访问的源
-                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")    // 允许请求方法
-                .maxAge(168000)    // 预检间隔时间
-                .allowedHeaders("*")  // 允许头部设置
-                .allowCredentials(true);    // 是否发送cookie
-    }
+//    @Override
+//    public void addCorsMappings(CorsRegistry registry) {
+//        registry.addMapping("/**")    // 允许跨域访问的路径
+//                .allowedOriginPatterns("*")
+////                .allowedOrigins("*")    // 允许跨域访问的源
+//                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")    // 允许请求方法
+//                .maxAge(168000)    // 预检间隔时间
+//                .allowedHeaders("*")  // 允许头部设置
+//                .allowCredentials(false);    // 是否发送cookie
+//    }
+
+
+//    @Override
+//    public void addCorsMappings(CorsRegistry registry) {
+//        registry.addMapping("/**")
+//                .allowedOriginPatterns("*")
+////                .allowedOrigins("*")
+////                .allowedMethods("*")
+//                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
+//                .allowCredentials(true)
+//                .maxAge(3600)
+//                .allowedHeaders("*")
+//                //暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
+//                .exposedHeaders("Authorization", "content-type");
+//
+//        ;
+//    }
 
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
@@ -118,4 +151,21 @@ public class MvcConfig implements WebMvcConfigurer {
         WebMvcConfigurer.super.addArgumentResolvers(argumentResolvers);
     }
 
+
+
+    // 注册拦截器
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+
+        // 跨域拦截器需放在最上面
+        registry.addInterceptor(corsInterceptor).addPathPatterns("/**");
+
+        //token拦截器
+        registry.addInterceptor(tokenInterceptor.tokenInterceptor()).addPathPatterns("/**");
+
+
+    }
+
+
+
 }

+ 85 - 210
src/main/java/com/ydtech/config/SwaggerConfig.java

@@ -1,5 +1,6 @@
 package com.ydtech.config;
 
+import com.ydtech.utils.StringUtils;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.Order;
@@ -26,271 +27,145 @@ public class SwaggerConfig {
     @Bean(value = "adminApi")
     @Order(value = 1)
     public Docket adminApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .defaultValue("Authorization")
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.admin"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("admin")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("admin");
     }
 
+
     @Bean(value = "esmApi")
     @Order(value = 2)
     public Docket esmApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<Parameter>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.esm"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("esm")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("esm");
     }
 
     @Bean(value = "fncApi")
     @Order(value = 3)
     public Docket fncApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.fnc"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("fnc")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("fnc");
     }
 
     @Bean(value = "insApi")
     @Order(value = 4)
     public Docket insApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.ins"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("ins")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("ins");
     }
 
     @Bean(value = "invApi")
     @Order(value = 4)
     public Docket invApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.inv"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("inv(发票)")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("inv","inv财务");
     }
 
     @Bean(value = "reportApi")
     @Order(value = 5)
     public Docket reportApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<Parameter>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.report"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("report")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("report");
     }
 
     @Bean(value = "orderApi")
     @Order(value = 6)
     public Docket orderApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.order"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("order")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("order");
     }
 
 
     @Bean(value = "naiApi")
     @Order(value = 7)
     public Docket naiApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<Parameter>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.nai"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("nai")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("nai");
     }
 
     @Bean(value = "protocolApi")
-    @Order(value = 7)
+    @Order(value = 8)
     public Docket protocolApi() {
-        // 添加请求参数,我们这里把token作为请求头部参数传入后端
-        ParameterBuilder parameterBuilder = new ParameterBuilder();
-        List<Parameter> parameters = new ArrayList<Parameter>();
-        parameterBuilder.name("Authorization")
-                .description("令牌")
-                .modelRef(new ModelRef("string"))
-                .parameterType("header")
-                .required(false)
-                .build();
-        parameters.add(parameterBuilder.build());
-        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
-                .select()
-                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules.protocol"))
-                .paths(PathSelectors.any())
-                .build()
-                .groupName("protocol")
-//                .globalOperationParameters(parameters)
-                //  安全上下文
-                .securitySchemes(securitySchemes())
-                .securityContexts(securityContexts());
-
+        return buildDocket("protocol");
     }
 
 
     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
-                .title("一个伟大项目的 API 文档")
-                .description("This is a restful api document of Spring Boot.")
+                .title("晋掌柜 API 文档")
+                .description("在线文档")
                 .version("1.0")
                 .build();
     }
 
 
-    private List<ApiKey> securitySchemes() {
-        List<ApiKey> apiKeys = new ArrayList<>();
-        apiKeys.add(new ApiKey("Authorization", "Authorization", "header"));
-        return apiKeys;
+//    private List<ApiKey> securitySchemes() {
+//        List<ApiKey> apiKeys = new ArrayList<>();
+//
+//        apiKeys.add(new ApiKey("Authorization", "Authorization", "header"));
+//        return apiKeys;
+//    }
+
+//    private List<SecurityContext> securityContexts() {
+//        List<SecurityContext> securityContexts = new ArrayList<>();
+//        securityContexts.add(SecurityContext.builder()
+//                .securityReferences(defaultAuth())
+//                .forPaths(PathSelectors.regex("^(?!auth).*$")).build());
+//        return securityContexts;
+//    }
+//
+//    private List<SecurityReference> defaultAuth() {
+//        AuthorizationScope authorizationScope = new AuthorizationScope("global", "描述信息");
+//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
+//        authorizationScopes[0] = authorizationScope;
+//        List<SecurityReference> securityReferences = new ArrayList<>();
+//        securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
+//        return securityReferences;
+//    }
+
+
+    /**
+     * 全局参数
+     *
+     * @return List<Parameter>
+     */
+    private List<Parameter> parameters() {
+        List<Parameter> params = new ArrayList<>();
+        params.add(new ParameterBuilder()
+                .name("Authorization")
+                .description("认证令牌")
+                .modelRef(new ModelRef("string"))
+                .parameterType("header")
+                .defaultValue("Bearer ")
+                .required(false)
+                .build());
+
+        return params;
     }
 
-    private List<SecurityContext> securityContexts() {
-        List<SecurityContext> securityContexts = new ArrayList<>();
-        securityContexts.add(SecurityContext.builder()
-                .securityReferences(defaultAuth())
-                .forPaths(PathSelectors.regex("^(?!auth).*$")).build());
-        return securityContexts;
+
+
+    public Docket buildDocket(String basePackage){
+        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules." + basePackage))
+                .paths(PathSelectors.any())
+                .build()
+                .groupName(basePackage)
+                .globalOperationParameters(parameters())
+//                //  安全上下文
+//                .securitySchemes(securitySchemes())
+//                .securityContexts(securityContexts());
+                ;
+
     }
+    public Docket buildDocket(String basePackage,String groupName){
+        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.ydtech.modules." + basePackage))
+                .paths(PathSelectors.any())
+                .build()
+                .groupName(groupName)
+                .globalOperationParameters(parameters())
+//                //  安全上下文
+//                .securitySchemes(securitySchemes())
+//                .securityContexts(securityContexts());
+                ;
 
-    private List<SecurityReference> defaultAuth() {
-        AuthorizationScope authorizationScope = new AuthorizationScope("global", "描述信息");
-        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
-        authorizationScopes[0] = authorizationScope;
-        List<SecurityReference> securityReferences = new ArrayList<>();
-        securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
-        return securityReferences;
     }
 
 
+
+
 }

+ 120 - 120
src/main/java/com/ydtech/config/WebSecurityConfig.java

@@ -1,120 +1,120 @@
-package com.ydtech.config;
-
-import com.ydtech.security.JwtAuthenticationFilter;
-import com.ydtech.security.JwtAuthenticationProvider;
-import com.ydtech.security.UserDetailsServiceImpl;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
-import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler;
-
-@Configuration
-@EnableWebSecurity
-@EnableGlobalMethodSecurity(prePostEnabled = true)
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-
-    @Autowired
-    private UserDetailsServiceImpl userDetailsService;
-
-    @Autowired
-    private MasterPasswordConfig masterPasswordConfig;
-
-    @Value("${upload.file.url}")
-    private String uploadFileUrl;
-
-    @Override
-    public void configure(AuthenticationManagerBuilder auth) throws Exception {
-        // 使用自定义登录身份认证组件
-        auth.authenticationProvider(new JwtAuthenticationProvider(userDetailsService, masterPasswordConfig));
-    }
-
-    @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        // 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf
-        http.cors().and().csrf().disable()
-                .authorizeRequests()
-                // 跨域预检请求
-//                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
-                // web jars
-                .antMatchers("/webjars/**").permitAll()
-                // 查看SQL监控(druid)
-                .antMatchers("/druid/**").permitAll()
-                // 首页和登录页面
-                .antMatchers("/").permitAll()
-                .antMatchers("/login").permitAll()
-                .antMatchers("/sendMsg").permitAll()
-                .antMatchers("/loginByPhone").permitAll()
-                .antMatchers("/user/findById").permitAll()
-                .antMatchers("/esmUserInternalcheck/userRegist").permitAll()
-                .antMatchers("/insOrder/queryOrder").permitAll()
-                .antMatchers("/insOrder/getPayCode").permitAll()
-                .antMatchers("/zm/Underwriting").permitAll()//自动核保回调
-                .antMatchers("/zm/ArtificialUnderwriting").permitAll()//人工核保回调
-                .antMatchers("/esmUserInternalcheck/updateName").permitAll()
-                // swagger
-                .antMatchers("/doc.html").permitAll()
-                .antMatchers("/swagger**/**").permitAll()
-                .antMatchers("/webjars/**").permitAll()
-                .antMatchers("/v2/**").permitAll()
-//                .antMatchers("/swagger-ui.html").permitAll()
-//                .antMatchers("/swagger-resources").permitAll()
-//                .antMatchers("/v2/api-docs").permitAll()
-//                .antMatchers("/webjars/springfox-swagger-ui/**").permitAll()
-                // 字典
-                .antMatchers("/dict/**").permitAll()
-                //静态资源
-                .antMatchers("/static/**").permitAll()
-                //api
-                .antMatchers("/api/**").permitAll()
-                //app
-                .antMatchers("/app/android/**").permitAll()
-                // 文件上传访问路径
-                .antMatchers(uploadFileUrl + "**").permitAll()
-                // 验证码
-                .antMatchers("/captcha.jpg**").permitAll()
-                // 服务监控
-                .antMatchers("/actuator/**").permitAll()
-                .antMatchers("/API/insCBIT/**").permitAll()
-                .antMatchers("/CBIT/API/insCBIT/**").permitAll()
-                .antMatchers("/CBITAPI/insCBIT/**").permitAll()
-                .antMatchers("/api/yongan/**").permitAll()
-                .antMatchers("/order/yongAn/**").permitAll()
-                .antMatchers("/api/insRenbao/**").permitAll()
-                .antMatchers("/ins/**").permitAll()
-                .antMatchers("/wechat/**").permitAll()
-                .antMatchers("/esm/policy/**").permitAll()
-                // 中煤回调
-                .antMatchers("/order/zhongMeiApi/underwritingCallback").permitAll()
-                .antMatchers("/order/zhongMeiApi/auditCallback").permitAll()
-
-                //审核退回
-                .antMatchers("/api/inv/invoiceInfo/approvalBack").hasAuthority("inv:invoice:info:approval:back")
-                //审核通过
-                .antMatchers("/api/inv/invoiceInfo/approvalPass").hasAuthority("inv:invoice:info:approval:pass")
-                // 其他所有请求需要身份认证
-                .anyRequest().authenticated();
-        // 退出登录处理器
-        http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
-        // 开启登录认证流程过滤器
-//        http.addFilterBefore(new JwtLoginFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
-        // 访问控制时登录状态检查过滤器
-        http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
-    }
-
-
-
-    @Bean
-    @Override
-    public AuthenticationManager authenticationManager() throws Exception {
-        return super.authenticationManager();
-    }
-
-}
+//package com.ydtech.config;
+//
+//import com.ydtech.security.JwtAuthenticationFilter;
+//import com.ydtech.security.JwtAuthenticationProvider;
+//import com.ydtech.security.UserDetailsServiceImpl;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.security.authentication.AuthenticationManager;
+//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+//import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler;
+//
+//@Configuration
+//@EnableWebSecurity
+//@EnableGlobalMethodSecurity(prePostEnabled = true)
+//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+//
+//    @Autowired
+//    private UserDetailsServiceImpl userDetailsService;
+//
+//    @Autowired
+//    private MasterPasswordConfig masterPasswordConfig;
+//
+//    @Value("${upload.file.url}")
+//    private String uploadFileUrl;
+//
+//    @Override
+//    public void configure(AuthenticationManagerBuilder auth) throws Exception {
+//        // 使用自定义登录身份认证组件
+//        auth.authenticationProvider(new JwtAuthenticationProvider(userDetailsService, masterPasswordConfig));
+//    }
+//
+//    @Override
+//    protected void configure(HttpSecurity http) throws Exception {
+//        // 禁用 csrf, 由于使用的是JWT,我们这里不需要csrf
+//        http.cors().and().csrf().disable()
+//                .authorizeRequests()
+//                // 跨域预检请求
+////                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
+//                // web jars
+//                .antMatchers("/webjars/**").permitAll()
+//                // 查看SQL监控(druid)
+//                .antMatchers("/druid/**").permitAll()
+//                // 首页和登录页面
+//                .antMatchers("/").permitAll()
+//                .antMatchers("/login").permitAll()
+//                .antMatchers("/sendMsg").permitAll()
+//                .antMatchers("/loginByPhone").permitAll()
+//                .antMatchers("/user/findById").permitAll()
+//                .antMatchers("/esmUserInternalcheck/userRegist").permitAll()
+//                .antMatchers("/insOrder/queryOrder").permitAll()
+//                .antMatchers("/insOrder/getPayCode").permitAll()
+//                .antMatchers("/zm/Underwriting").permitAll()//自动核保回调
+//                .antMatchers("/zm/ArtificialUnderwriting").permitAll()//人工核保回调
+//                .antMatchers("/esmUserInternalcheck/updateName").permitAll()
+//                // swagger
+//                .antMatchers("/doc.html").permitAll()
+//                .antMatchers("/swagger**/**").permitAll()
+//                .antMatchers("/webjars/**").permitAll()
+//                .antMatchers("/v2/**").permitAll()
+////                .antMatchers("/swagger-ui.html").permitAll()
+////                .antMatchers("/swagger-resources").permitAll()
+////                .antMatchers("/v2/api-docs").permitAll()
+////                .antMatchers("/webjars/springfox-swagger-ui/**").permitAll()
+//                // 字典
+//                .antMatchers("/dict/**").permitAll()
+//                //静态资源
+//                .antMatchers("/static/**").permitAll()
+//                //api
+//                .antMatchers("/api/**").permitAll()
+//                //app
+//                .antMatchers("/app/android/**").permitAll()
+//                // 文件上传访问路径
+//                .antMatchers(uploadFileUrl + "**").permitAll()
+//                // 验证码
+//                .antMatchers("/captcha.jpg**").permitAll()
+//                // 服务监控
+//                .antMatchers("/actuator/**").permitAll()
+//                .antMatchers("/API/insCBIT/**").permitAll()
+//                .antMatchers("/CBIT/API/insCBIT/**").permitAll()
+//                .antMatchers("/CBITAPI/insCBIT/**").permitAll()
+//                .antMatchers("/api/yongan/**").permitAll()
+//                .antMatchers("/order/yongAn/**").permitAll()
+//                .antMatchers("/api/insRenbao/**").permitAll()
+//                .antMatchers("/ins/**").permitAll()
+//                .antMatchers("/wechat/**").permitAll()
+//                .antMatchers("/esm/policy/**").permitAll()
+//                // 中煤回调
+//                .antMatchers("/order/zhongMeiApi/underwritingCallback").permitAll()
+//                .antMatchers("/order/zhongMeiApi/auditCallback").permitAll()
+//
+//                //审核退回
+//                .antMatchers("/api/inv/invoiceInfo/approvalBack").hasAuthority("inv:invoice:info:approval:back")
+//                //审核通过
+//                .antMatchers("/api/inv/invoiceInfo/approvalPass").hasAuthority("inv:invoice:info:approval:pass")
+//                // 其他所有请求需要身份认证
+//                .anyRequest().authenticated();
+//        // 退出登录处理器
+//        http.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
+//        // 开启登录认证流程过滤器
+////        http.addFilterBefore(new JwtLoginFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
+//        // 访问控制时登录状态检查过滤器
+//        http.addFilterBefore(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
+//    }
+//
+//
+//
+//    @Bean
+//    @Override
+//    public AuthenticationManager authenticationManager() throws Exception {
+//        return super.authenticationManager();
+//    }
+//
+//}

+ 36 - 30
src/main/java/com/ydtech/core/page/BaseController.java

@@ -1,34 +1,33 @@
 package com.ydtech.core.page;
 
 
+import cn.dev33.satoken.session.SaSession;
+import cn.dev33.satoken.stp.StpUtil;
 import com.ydtech.modules.admin.model.SysUser;
-import com.ydtech.security.JwtAuthenticatioToken;
-import com.ydtech.security.utils.JwtTokenUtils;
-import com.ydtech.security.utils.SecurityUtils;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
 
 import javax.servlet.http.HttpServletRequest;
 
 public class BaseController {
 
     public SysUser getUser() {
-        return (SysUser) SecurityContextHolder.getContext()
-                .getAuthentication()
-                .getPrincipal();
+//        return (SysUser) SecurityContextHolder.getContext()
+//                .getAuthentication()
+//                .getPrincipal();
+        SaSession saSession = StpUtil.getSessionByLoginId(StpUtil.getLoginId());
+        SysUser sysUser = (SysUser) saSession.get(SaSession.USER);
+        return sysUser;
     }
 
     public String getUserName() {
-        String userName = null;
-        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-
-        if (principal instanceof UserDetails) {
-            userName = ((UserDetails) principal).getUsername();
-        } else {
-            userName = principal.toString();
-        }
-        return userName;
+//        String userName = null;
+//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//
+//        if (principal instanceof UserDetails) {
+//            userName = ((UserDetails) principal).getUsername();
+//        } else {
+//            userName = principal.toString();
+//        }
+        return StpUtil.getLoginId().toString();
     }
 
 
@@ -54,7 +53,10 @@ public class BaseController {
      * @return
      */
     public String getdeptId(HttpServletRequest request) {
-        return JwtTokenUtils.getDeptIdFromRequest(request);
+        SaSession saSession = StpUtil.getSessionByLoginId(StpUtil.getLoginId());
+        SysUser sysUser = (SysUser) saSession.get(SaSession.USER);
+        return sysUser.getDeptId();
+//        return JwtTokenUtils.getDeptIdFromRequest(request);
     }
 
 
@@ -65,7 +67,8 @@ public class BaseController {
      * @return
      */
     public String getUserId(HttpServletRequest request) {
-        return JwtTokenUtils.getUserIdFromRequest(request);
+        return StpUtil.getLoginId().toString();
+//        return JwtTokenUtils.getUserIdFromRequest(request);
     }
 
 
@@ -76,10 +79,11 @@ public class BaseController {
      * @date: 2023年05月18日 0018
      */
     public String getUserId2() {
-        Authentication authentication = SecurityUtils.getAuthentication();
-
-        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
-        return JwtTokenUtils.getUserIdFromToken(j.getToken());
+        return StpUtil.getLoginId().toString();
+//        Authentication authentication = SecurityUtils.getAuthentication();
+//
+//        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
+//        return JwtTokenUtils.getUserIdFromToken(j.getToken());
     }
     /**
      * 新加 可用
@@ -88,11 +92,12 @@ public class BaseController {
      * @date: 2023年05月18日 0018
      */
     public String getUserId() {
-        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-//        Authentication authentication = SecurityUtils.getAuthentication();
-
-        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
-        return JwtTokenUtils.getUserIdFromToken(j.getToken());
+        return StpUtil.getLoginId().toString();
+//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+////        Authentication authentication = SecurityUtils.getAuthentication();
+//
+//        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
+//        return JwtTokenUtils.getUserIdFromToken(j.getToken());
     }
 
     /**
@@ -102,7 +107,8 @@ public class BaseController {
      * @return
      */
     public String getJwtUserName(HttpServletRequest request) {
-        return JwtTokenUtils.getUsernameFromRequest(request);
+        return StpUtil.getLoginId().toString();
+//        return JwtTokenUtils.getUsernameFromRequest(request);
     }
 
 }

+ 2 - 0
src/main/java/com/ydtech/core/page/HttpResult.java

@@ -42,6 +42,7 @@ public class HttpResult<T> {
         return r;
     }
 
+
     public static <T> HttpResult<T> ok(String msg) {
         HttpResult<T> r = new HttpResult<>();
         r.setMsg(msg);
@@ -61,6 +62,7 @@ public class HttpResult<T> {
         return r;
     }
 
+
     public static <T> HttpResult<T> ok() {
         return new HttpResult<>();
     }

+ 1 - 2
src/main/java/com/ydtech/modules/admin/controller/DemoController.java

@@ -1,7 +1,6 @@
 package com.ydtech.modules.admin.controller;
 
 import com.ydtech.modules.admin.model.SysUser;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -11,7 +10,7 @@ import java.util.List;
 @RestController
 public class DemoController {
 
-    @PreAuthorize("hasAuthority('sys:demo:view')")
+//    @PreAuthorize("hasAuthority('sys:demo:view')")
     @GetMapping("/hello")
     public String hello() {
         return "Hello SpringSecurity!";

+ 0 - 1
src/main/java/com/ydtech/modules/admin/controller/SysDeptController.java

@@ -8,7 +8,6 @@ import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;

+ 3 - 3
src/main/java/com/ydtech/modules/admin/controller/SysDictController.java

@@ -19,7 +19,6 @@ import com.ydtech.modules.esm.model.EsmInsCompany;
 import com.ydtech.modules.esm.model.EsmProduct;
 import com.ydtech.modules.esm.service.EsmInsCompanyService;
 import com.ydtech.modules.esm.service.EsmProductService;
-import com.ydtech.security.utils.JwtTokenUtils;
 import com.ydtech.utils.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -110,8 +109,9 @@ public class SysDictController extends BaseController {
     public HttpResult findByLable(@RequestParam String lable, HttpServletRequest request) {
         List<SysDict> byLable = sysDictService.findByLable(lable);
         if (byLable == null || byLable.size() == 0) {
-            // 获取用户名
-            String deptId = JwtTokenUtils.getDeptIdFromRequest(request);
+            // 获取部门ID
+            String deptId = "";
+//            String deptId = JwtTokenUtils.getDeptIdFromRequest(request);
             lable = lable.toLowerCase();
             switch (lable) {
                 case "inscompanycmain":

+ 1 - 2
src/main/java/com/ydtech/modules/admin/controller/SysLogController.java

@@ -4,7 +4,6 @@ import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.admin.service.SysLogService;
 import com.ydtech.modules.admin.model.vo.SysLogQueryVO;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,7 +23,7 @@ public class SysLogController {
     @Autowired
     private SysLogService sysLogService;
 
-    @PreAuthorize("hasAuthority('sys:log:view')")
+//    @PreAuthorize("hasAuthority('sys:log:view')")
     @PostMapping(value = "/findPage")
     public HttpResult findPage(@RequestBody SysLogQueryVO sysLogQueryVO) {
         return HttpResult.ok(sysLogService.selectPaging(sysLogQueryVO));

+ 31 - 11
src/main/java/com/ydtech/modules/admin/controller/SysLoginController.java

@@ -1,25 +1,25 @@
 package com.ydtech.modules.admin.controller;
 
+import cn.dev33.satoken.session.SaSession;
+import cn.dev33.satoken.stp.StpUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.google.code.kaptcha.Producer;
 import com.ydtech.config.MasterPasswordConfig;
 import com.ydtech.modules.admin.model.SysUser;
 import com.ydtech.modules.admin.service.SysMsgLogService;
 import com.ydtech.modules.esm.service.EsmUserInternalService;
-import com.ydtech.security.JwtAuthenticatioToken;
 import com.ydtech.security.utils.PasswordUtils;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.modules.admin.service.SysUserService;
 import com.ydtech.modules.admin.model.vo.LoginBean;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.utils.IPUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.Authorization;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.tomcat.util.http.fileupload.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
@@ -57,8 +57,8 @@ public class SysLoginController {
     private Producer producer;
     @Autowired
     private SysUserService sysUserService;
-    @Autowired
-    private AuthenticationManager authenticationManager;
+//    @Autowired
+//    private AuthenticationManager authenticationManager;
     @Autowired
     private SysMsgLogService sysMsgLogService;
 
@@ -72,7 +72,7 @@ public class SysLoginController {
     private MasterPasswordConfig masterPasswordConfig;
 
     @GetMapping("captcha.jpg")
-    @ApiOperation(value = "获取验证码", produces = "application/octet-stream")
+    @ApiOperation(value = "获取验证码", produces = "application/octet-stream" )
     public void captcha(HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
         response.setHeader("Cache-Control", "no-store, no-cache");
         response.setContentType("image/jpeg");
@@ -126,10 +126,19 @@ public class SysLoginController {
             return HttpResult.error("账号已被锁定,请联系管理员");
         }
 
-        // 系统登录认证
-        JwtAuthenticatioToken token = SecurityUtils.login(request, username, password, authenticationManager);
+        // 获取这个人的token
+        String token = StpUtil.createLoginSession(user.getId());
+        StpUtil.getSessionByLoginId(user.getId()).set(SaSession.USER ,user);
 
-        return HttpResult.ok(token);
+//        StpUtil.login(token);
+
+
+//        String token = "";
+//        // 系统登录认证
+//        JwtAuthenticatioToken token = SecurityUtils.login(request, username, password, authenticationManager);
+
+
+        return HttpResult.ok("登录成功",token);
     }
 
     /**
@@ -181,8 +190,9 @@ public class SysLoginController {
             return HttpResult.error("账号已被锁定,请联系管理员");
         }
 
-        // 系统登录认证
-        JwtAuthenticatioToken token = SecurityUtils.login(request, user.getId(), "", authenticationManager);
+        String token = "";
+//        // 系统登录认证
+//        JwtAuthenticatioToken token = SecurityUtils.login(request, user.getId(), "", authenticationManager);
 
         return HttpResult.ok(token);
     }
@@ -325,4 +335,14 @@ public class SysLoginController {
     }
 
 
+
+
+    @PostMapping(value = "/loginOut")
+    @ApiOperation(value = "登出")
+    public HttpResult loginOut() {
+        StpUtil.logout();
+        return HttpResult.ok("退出登录成功");
+    }
+
+
 }

+ 2 - 3
src/main/java/com/ydtech/modules/admin/controller/SysMenuController.java

@@ -6,7 +6,6 @@ import com.ydtech.modules.admin.service.SysMenuService;
 import com.ydtech.utils.StringUtils;
 import com.ydtech.core.page.HttpResult;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -25,7 +24,7 @@ public class SysMenuController {
     @Autowired
     private SysMenuService sysMenuService;
 
-    @PreAuthorize("hasAuthority('sys:menu:add') AND hasAuthority('sys:menu:edit')")
+//    @PreAuthorize("hasAuthority('sys:menu:add') AND hasAuthority('sys:menu:edit')")
     @PostMapping(value = "/save")
     public HttpResult save(@RequestBody SysMenu record) {
         if (StringUtils.isNullOrEmpty(record.getId()) || record.getId().equalsIgnoreCase("0")) {
@@ -37,7 +36,7 @@ public class SysMenuController {
         }
     }
 
-    @PreAuthorize("hasAuthority('sys:menu:delete')")
+//    @PreAuthorize("hasAuthority('sys:menu:delete')")
     @PostMapping(value = "/delete")
     public HttpResult delete(@RequestBody List<SysMenu> records) {
         List<String> ids = records.stream().map(SysMenu::getId).collect(Collectors.toList());

+ 6 - 7
src/main/java/com/ydtech/modules/admin/controller/SysRoleController.java

@@ -8,7 +8,6 @@ import com.ydtech.modules.admin.model.SysRoleMenu;
 import com.ydtech.modules.admin.service.SysRoleMenuService;
 import com.ydtech.modules.admin.service.SysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
@@ -32,7 +31,7 @@ public class SysRoleController {
     @Autowired
     private SysRoleMenuService sysRoleMenuService;
 
-    @PreAuthorize("hasAuthority('sys:role:add') AND hasAuthority('sys:role:edit')")
+//    @PreAuthorize("hasAuthority('sys:role:add') AND hasAuthority('sys:role:edit')")
     @PostMapping(value = "/save")
     public HttpResult save(@RequestBody SysRole record) {
         SysRole role = sysRoleService.getById(record.getId());
@@ -49,7 +48,7 @@ public class SysRoleController {
         return HttpResult.ok(sysRoleService.saveOrUpdate(record));
     }
 
-    @PreAuthorize("hasAuthority('sys:role:delete')")
+//    @PreAuthorize("hasAuthority('sys:role:delete')")
     @PostMapping(value = "/delete")
     @Transactional
     public HttpResult delete(@RequestBody List<SysRole> records) {
@@ -60,26 +59,26 @@ public class SysRoleController {
 //        return HttpResult.ok(sysRoleService.delete(records));
     }
 
-    @PreAuthorize("hasAuthority('sys:role:view')")
+//    @PreAuthorize("hasAuthority('sys:role:view')")
     @PostMapping(value = "/findPage")
     public HttpResult findPage(@RequestBody PageRequest pageRequest) {
         return HttpResult.ok(sysRoleService.findPage(pageRequest));
     }
 
-    @PreAuthorize("hasAuthority('sys:role:view')")
+//    @PreAuthorize("hasAuthority('sys:role:view')")
     @GetMapping(value = "/findAll")
     public HttpResult findAll() {
         return HttpResult.ok(sysRoleService.list());
 //        return HttpResult.ok(sysRoleService.selectAll());
     }
 
-    @PreAuthorize("hasAuthority('sys:role:view')")
+//    @PreAuthorize("hasAuthority('sys:role:view')")
     @GetMapping(value = "/findRoleMenus")
     public HttpResult findRoleMenus(@RequestParam Long roleId) {
         return HttpResult.ok(sysRoleService.findRoleMenus(roleId));
     }
 
-    @PreAuthorize("hasAuthority('sys:role:view')")
+//    @PreAuthorize("hasAuthority('sys:role:view')")
     @PostMapping(value = "/saveRoleMenus")
     public HttpResult saveRoleMenus(@RequestBody List<SysRoleMenu> records) {
         for (SysRoleMenu record : records) {

+ 1 - 0
src/main/java/com/ydtech/modules/admin/service/impl/SysDeptServiceImpl.java

@@ -62,6 +62,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
 //        return updateSelective(record);
 //    }
 //
+    @Override
     public PageResult findSubDepts(PageRequest pageRequest) {
 
 

+ 13 - 7
src/main/java/com/ydtech/modules/admin/service/impl/WechatServiceImpl.java

@@ -16,8 +16,6 @@ import com.ydtech.modules.admin.model.vo.WechatLoginVo;
 import com.ydtech.modules.esm.model.SysUserCheck;
 import com.ydtech.modules.esm.service.EsmUserInternalService;
 import com.ydtech.modules.esm.service.SysUserCheckService;
-import com.ydtech.security.JwtAuthenticatioToken;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.idgen.IdGenerate;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
@@ -26,7 +24,6 @@ import me.chanjar.weixin.mp.api.WxMpService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -49,7 +46,6 @@ public class WechatServiceImpl implements WechatService {
     private SysUserService sysUserService;
 
     private final WxMpService wxMpService;
-    private final AuthenticationManager authenticationManager;
 
     private final EsmUserInternalService esmUserInternalService;
 
@@ -59,15 +55,24 @@ public class WechatServiceImpl implements WechatService {
 
     private final SysUserCheckService sysUserCheckService;
 
-    public WechatServiceImpl(SysUserMapper sysUserMapper, WxMpService wxMpService, AuthenticationManager authenticationManager, SysUserRoleMapper sysUserRoleMapper, StringRedisTemplate stringRedisTemplate, EsmUserInternalService esmUserInternalService, SysUserCheckService sysUserCheckService) {
+    public WechatServiceImpl(SysUserMapper sysUserMapper, WxMpService wxMpService,  SysUserRoleMapper sysUserRoleMapper, StringRedisTemplate stringRedisTemplate, EsmUserInternalService esmUserInternalService, SysUserCheckService sysUserCheckService) {
         this.sysUserMapper = sysUserMapper;
         this.wxMpService = wxMpService;
-        this.authenticationManager = authenticationManager;
+//        this.authenticationManager = authenticationManager;
         this.sysUserRoleMapper = sysUserRoleMapper;
         this.stringRedisTemplate = stringRedisTemplate;
         this.esmUserInternalService = esmUserInternalService;
         this.sysUserCheckService = sysUserCheckService;
     }
+//    public WechatServiceImpl(SysUserMapper sysUserMapper, WxMpService wxMpService, AuthenticationManager authenticationManager, SysUserRoleMapper sysUserRoleMapper, StringRedisTemplate stringRedisTemplate, EsmUserInternalService esmUserInternalService, SysUserCheckService sysUserCheckService) {
+//        this.sysUserMapper = sysUserMapper;
+//        this.wxMpService = wxMpService;
+////        this.authenticationManager = authenticationManager;
+//        this.sysUserRoleMapper = sysUserRoleMapper;
+//        this.stringRedisTemplate = stringRedisTemplate;
+//        this.esmUserInternalService = esmUserInternalService;
+//        this.sysUserCheckService = sysUserCheckService;
+//    }
 
     @Override
     @Transactional
@@ -116,7 +121,8 @@ public class WechatServiceImpl implements WechatService {
         } else {
             number = sysUser.getId();
         }
-        JwtAuthenticatioToken token = SecurityUtils.login(request, number, "", authenticationManager);
+//        JwtAuthenticatioToken token = SecurityUtils.login(request, number, "", authenticationManager);
+        String token = "";
         return HttpResult.ok(token);
     }
 

+ 6 - 5
src/main/java/com/ydtech/modules/esm/controller/EsmTrainController.java

@@ -8,7 +8,6 @@ import com.ydtech.modules.esm.model.EsmTrain;
 import com.ydtech.modules.esm.model.EsmTrainQueryReq;
 import com.ydtech.modules.esm.service.TrainService;
 import com.ydtech.modules.esm.model.vo.req.EsmTrainCountReq;
-import com.ydtech.security.utils.JwtTokenUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
@@ -43,7 +42,8 @@ public class EsmTrainController {
     @ApiOperation(value = "保存培训信息")
     public HttpResult insertTrain(HttpServletRequest request, @RequestBody EsmTrain trainReqParm) {
 
-        String userid = JwtTokenUtils.getUsernameFromRequest(request);
+//        String userid = JwtTokenUtils.getUsernameFromRequest(request);
+        String userid = "";
         HttpResult httpResult = trainService.insertTrain(trainReqParm, userid);
 
         return httpResult;
@@ -66,8 +66,9 @@ public class EsmTrainController {
     public HttpResult queryTrainByCodition_app(HttpServletRequest request, @RequestBody EsmTrainQueryReq codition) {
         HttpResult httpResult = null;
         try {
-            String userid = JwtTokenUtils.getUsernameFromRequest(request);
-            SysUser sysUser = sysUserService.findByUserId(userid);
+            String userId = "";
+//            String userid = JwtTokenUtils.getUsernameFromRequest(request);
+            SysUser sysUser = sysUserService.findByUserId(userId);
             String userscope = "";
             if (sysUser == null) {
                 throw new Exception("token传值有误");
@@ -85,7 +86,7 @@ public class EsmTrainController {
             codition.setStatus("1");
             codition.setUserscope(userscope);
             codition.setByzd1(StringUtil.isEmpty(codition.getByzd1()) ? "1" : codition.getByzd1());
-            codition.setUserId(userid);
+            codition.setUserId(userId);
             httpResult = trainService.queryTrainByCodition(codition);
 
         } catch (Exception e) {

+ 1 - 2
src/main/java/com/ydtech/modules/esm/controller/EsmUserInternalController.java

@@ -19,7 +19,6 @@ import com.ydtech.modules.ins.model.InsOrder;
 import com.ydtech.modules.ins.service.InsOrderService;
 import com.ydtech.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
@@ -75,7 +74,7 @@ public class EsmUserInternalController extends BaseController {
         return HttpResult.ok("保存成功");
     }
 
-    @PreAuthorize("hasAuthority('sys:user:delete')")
+//    @PreAuthorize("hasAuthority('sys:user:delete')")
     @PostMapping(value = "/delete")
     public HttpResult delete(@RequestBody List<SysUser> records) {
 

+ 2 - 2
src/main/java/com/ydtech/modules/esm/service/impl/TrainServiceImpl.java

@@ -17,7 +17,6 @@ import com.ydtech.modules.esm.model.vo.req.EsmTrainCountReq;
 import com.ydtech.modules.esm.model.vo.res.EsmTrainCountVO;
 import com.ydtech.modules.ins.dao.InsFileMapper;
 import com.ydtech.modules.ins.model.InsFileDto;
-import com.ydtech.security.utils.JwtTokenUtils;
 import com.ydtech.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -150,7 +149,8 @@ public class TrainServiceImpl implements TrainService {
             return HttpResult.error("培训ID不可为空!");
         }
         EsmTrainCount esmTrainCount = new EsmTrainCount();
-        String userId = JwtTokenUtils.getUsernameFromRequest(request);
+        String userId = "";
+//        String userId = JwtTokenUtils.getUsernameFromRequest(request);
         esmTrainCount.setTrainid(req.getTrainid());
         esmTrainCount.setUserId(userId);
         esmTrainCount.setSpeakTime(new Date());

+ 0 - 1
src/main/java/com/ydtech/modules/fnc/controller/SubjectController.java

@@ -6,7 +6,6 @@ import com.ydtech.modules.fnc.service.SubjectService;
 import com.ydtech.modules.fnc.vo.FncSubjectReq;
 import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;

+ 6 - 4
src/main/java/com/ydtech/modules/fnc/controller/VoucherController.java

@@ -4,7 +4,6 @@ import com.ydtech.constants.SysConstants;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.fnc.service.VoucherService;
 import com.ydtech.modules.fnc.vo.FncVoucherReq;
-import com.ydtech.security.utils.JwtTokenUtils;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
@@ -44,7 +43,8 @@ public class VoucherController {
     @PostMapping(value = "/query")
     public HttpResult query(@RequestBody FncVoucherReq codition, HttpServletRequest request) {
         HttpResult httpResult = null;
-        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
+//        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
+        String deptid = "";
         deptid = SysConstants.DEPT.equals(deptid) ? deptid : (deptid.contains("D") ? deptid.substring(0, deptid.indexOf("D")) : deptid);
         codition.setCdeptName(deptid);
 
@@ -68,7 +68,8 @@ public class VoucherController {
     @PostMapping(value = "/queryDetail")
     public HttpResult queryDetail(@RequestBody FncVoucherReq fncVoucherReq, HttpServletRequest request) {
         HttpResult httpResult = null;
-        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
+//        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
+        String deptid = "";
         deptid = SysConstants.DEPT.equals(deptid) ? deptid : (deptid.contains("D") ? deptid.substring(0, deptid.indexOf("D")) : deptid);
         fncVoucherReq.setCdeptName(deptid);
 
@@ -92,7 +93,8 @@ public class VoucherController {
     @PostMapping(value = "/exportDetail")
     public void exportDetail(@RequestBody FncVoucherReq fncVoucherReq, HttpServletRequest request, HttpServletResponse response) {
         HttpResult httpResult = null;
-        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
+        String deptid = "";
+//        String deptid = JwtTokenUtils.getDeptIdFromRequest(request);
         deptid = SysConstants.DEPT.equals(deptid) ? deptid : (deptid.contains("D") ? deptid.substring(0, deptid.indexOf("D")) : deptid);
         fncVoucherReq.setCdeptName(deptid);
         voucherService.exportVoucherByCodition(fncVoucherReq, request, response);

+ 2 - 2
src/main/java/com/ydtech/modules/ins/controller/InsCBITAPIController.java

@@ -26,7 +26,6 @@ import com.ydtech.modules.ins.model.vo.CarModelQryVo;
 import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
 import com.ydtech.modules.ins.model.vo.KindInfoVo;
 import com.ydtech.modules.ins.service.*;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.HttpsPostUtil;
 import com.ydtech.utils.RSA.RSAUtils;
 import org.slf4j.Logger;
@@ -1407,7 +1406,8 @@ public class InsCBITAPIController extends BaseController {
     private void insertCbitLog(String url, String req_desc, String reqno, String req_json, String resp_json) {
         SysCbitLog cbitLog = new SysCbitLog();
         cbitLog.setReqNo(reqno);
-        cbitLog.setUsercode(SecurityUtils.getUsername());
+        cbitLog.setUsercode("");
+//        cbitLog.setUsercode(SecurityUtils.getUsername());
         cbitLog.setReqUrl(url);
         cbitLog.setDescription(req_desc);
         cbitLog.setReqParam(req_json);

+ 3 - 3
src/main/java/com/ydtech/modules/ins/controller/InsCBITController.java

@@ -14,7 +14,6 @@ import com.ydtech.modules.ins.model.cbit.*;
 import com.ydtech.modules.ins.service.*;
 import com.ydtech.modules.ins.model.vo.CarModelQryVo;
 import com.ydtech.modules.ins.model.vo.QuoteInfoVo;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.HttpsPostUtil;
 import com.ydtech.utils.RSA.RSAUtils;
 import org.slf4j.Logger;
@@ -677,7 +676,8 @@ public class InsCBITController extends BaseController {
     private void insertCbitLog(String url, String req_desc, String reqno, String req_json, String resp_json) {
         SysCbitLog cbitLog = new SysCbitLog();
         cbitLog.setReqNo(reqno);
-        cbitLog.setUsercode(SecurityUtils.getUsername());
+        cbitLog.setUsercode("");
+//        cbitLog.setUsercode(SecurityUtils.getUsername());
         cbitLog.setReqUrl(url);
         cbitLog.setDescription(req_desc);
         cbitLog.setReqParam(req_json);
@@ -735,4 +735,4 @@ public class InsCBITController extends BaseController {
         sysCbitError.setErrorinfo(errorinfo);
         sysCbitErrorService.insert(sysCbitError);
     }
-}
+}

+ 2 - 4
src/main/java/com/ydtech/modules/ins/model/yc/audit/Audit.java

@@ -272,10 +272,8 @@ public class Audit {
         taxATion.setMobile(applyInfo.getMobile());
 
         //@TODO 无法获取,输入无效内容
-        taxATion.setBankName(" ");
-        taxATion.setAcctNo(" ");
-//        taxATion.setBankName("山西省太原市");
-//        taxATion.setAcctNo("999999");
+        taxATion.setBankName("山西省太原市");
+        taxATion.setAcctNo("999999");
 
         condition.setCustomer(customer);
         condition.setTaxATion(taxATion);

+ 222 - 25
src/main/java/com/ydtech/modules/ins/model/yc/modelsQuery/ModelsQueryResponse.java

@@ -36,42 +36,239 @@ public class ModelsQueryResponse {
 
     @Data
     public static class VehicleInfo {
-//        @JacksonXmlProperty(localName = "absFlag")
-//        private String aafff;
-//        @JacksonXmlProperty(localName = "airbagCount")
-//        private String airbagCount;
+        /**
+         * 车型唯一编码
+         */
+        @JacksonXmlProperty(localName = "vehicleId")
+        private String vehicleId;
 
-        @JacksonXmlProperty(localName = "ycVehicleClass")
-        private String modelCode;//车型编码 autoModelCode
+        /**
+         * 车型正式名称
+         */
         @JacksonXmlProperty(localName = "vehicleName")
-        private String modelName;//车型库名称 比亚迪QCJ7153A5轿车
+        private String vehicleName;
+
+        /**
+         * 车型种类编码
+         */
+        @JacksonXmlProperty(localName = "vehicleClass")
+        private String vehicleClass;
+
+        /**
+         * 永诚车型种类编码
+         */
+        @JacksonXmlProperty(localName = "ycVehicleClass")
+        private String ycVehicleClass;
+
+        /**
+         * 进口车/国产车
+         */
+        @JacksonXmlProperty(localName = "vehicleType")
+        private String vehicleType;
+
+        /**
+         * 厂商ID
+         */
+        @JacksonXmlProperty(localName = "factoryId")
+        private String factoryId;
+
+        /**
+         * 生产厂家
+         */
+        @JacksonXmlProperty(localName = "VehicleMaker")
+        private String VehicleMaker;
+
+        /**
+         * 品牌
+         */
         @JacksonXmlProperty(localName = "vehicleBrand")
-        private String brandCN;//品牌名称 brandName
+        private String vehicleBrand;
+
+        /**
+         * 品牌ID
+         */
+        @JacksonXmlProperty(localName = "brandID")
+        private String brandID;
+
+        /**
+         * 车型系列
+         */
         @JacksonXmlProperty(localName = "vehicleSeries")
-        private String series;//车系名称
-        @JacksonXmlProperty(localName = "vehicleType")
-        private String importFlag;//车型种类
+        private String vehicleSeries;
+
+        /**
+         * 车型ID
+         */
+        @JacksonXmlProperty(localName = "familiyId")
+        private String familiyId;
+
+        /**
+         * 查询简码
+         */
+        @JacksonXmlProperty(localName = "searchCode")
+        private String searchCode;
+
+        /**
+         * 型号编码
+         */
+        @JacksonXmlProperty(localName = "modelCode")
+        private String modelCode;
+
+        /**
+         * 核定载客(人)
+         */
         @JacksonXmlProperty(localName = "vehicleSeat")
-        private String ratedPassengerCapacity;//核定载客人数
+        private String vehicleSeat;
+
+        /**
+         * 排气量
+         */
         @JacksonXmlProperty(localName = "vehicleDisplacement")
-        private String displacement;//排量
+        private String vehicleDisplacement;
+
+        /**
+         * 上市年份
+         */
         @JacksonXmlProperty(localName = "vehicleYear")
-        private String marketYear;//上市年份
+        private String vehicleYear;
+
+        /**
+         * 精友新车购置价
+         */
         @JacksonXmlProperty(localName = "vehiclePrice")
-        private String replacementValue;//默认购置价
-        //        @JacksonXmlProperty(localName = "vehicleSeries")
-//        private String vehicleDescription;//车型描述
+        private String vehiclePrice;
+
+        /**
+         * 备注
+         */
+        @JacksonXmlProperty(localName = "vehicleRemark")
+        private String vehicleRemark;
+
+        /**
+         * 变速器类型
+         */
         @JacksonXmlProperty(localName = "transmissionType")
-        private String gearboxType;//变速箱类型
+        private String transmissionType;
+
+        /**
+         * 生产状态
+         */
+        @JacksonXmlProperty(localName = "productStatus")
+        private String productStatus;
+
+        /**
+         * 风险类型
+         */
+        @JacksonXmlProperty(localName = "riskType")
+        private String riskType;
+
+        /**
+         * ABS装置
+         */
+        @JacksonXmlProperty(localName = "absFlag")
+        private String absFlag;
+
+        /**
+         * 防盗装置
+         */
+        @JacksonXmlProperty(localName = "thefiProof")
+        private String thefiProof;
+
+        /**
+         * 安全气囊数量
+         */
+        @JacksonXmlProperty(localName = "airbagCount")
+        private String airbagCount;
+
+        /**
+         * 最小整备质量
+         */
+        @JacksonXmlProperty(localName = "curbWeightMin")
+        private String curbWeightMin;
+
+        /**
+         * 最大整备质量
+         */
+        @JacksonXmlProperty(localName = "curbWeightMax")
+        private String curbWeightMax;
+
+        /**
+         * 类比车型价格(含税)
+         */
+        @JacksonXmlProperty(localName = "xhKindPrice")
+        private String xhKindPrice;
+
+        /**
+         * 浙江协会类比税前价格
+         */
+        @JacksonXmlProperty(localName = "nXhKindpriceWithouttax")
+        private String nXhKindpriceWithouttax;
+
+        /**
+         * 发动机功率
+         */
+        @JacksonXmlProperty(localName = "vehiclePower")
+        private String vehiclePower;
+
+        /**
+         * 精友新车购置价(含税)
+         */
+        @JacksonXmlProperty(localName = "szxhTaxedPrice")
+        private String szxhTaxedPrice;
+
+        /**
+         * 商业险车型分类
+         */
+        @JacksonXmlProperty(localName = "syxClassid")
+        private String syxClassid;
+
+        /**
+         * 商业险车型名称
+         */
+        @JacksonXmlProperty(localName = "syxClassname")
+        private String syxClassname;
+
+        /**
+         * 交强险车型分类
+         */
+        @JacksonXmlProperty(localName = "jqxClassid")
+        private String jqxClassid;
+
+        /**
+         * 交强险车型名称
+         */
+        @JacksonXmlProperty(localName = "jqxClassname")
+        private String jqxClassname;
+
+        /**
+         * VIN码
+         */
+        @JacksonXmlProperty(localName = "vinCode")
+        private String vinCode;
+
+        /**
+         * 创建日期
+         */
+        @JacksonXmlProperty(localName = "dateCreated")
+        private String dateCreated;
+
+        /**
+         * 更新日期
+         */
+        @JacksonXmlProperty(localName = "dateUpdated")
+        private String dateUpdated;
 
+        /**
+         * 精友车型分类
+         */
+        @JacksonXmlProperty(localName = "jyClassid")
+        private String jyClassid;
 
-//        private String refCode1;//参考代码1
-//        private String refCode2;//参考代码2
-//        private String remark;//
-//        private String fuelType;//能源种类
-//        private String wholeWeight;//
-//        private String powerScale;//
-//        private VehicleJingyou vehicleJingyo;
+        /**
+         * 吨位
+         */
+        @JacksonXmlProperty(localName = "vehicleTonnage")
+        private String vehicleTonnage;
 
 
     }

+ 10 - 10
src/main/java/com/ydtech/modules/ins/service/impl/InsAlltrustApiServiceImpl.java

@@ -58,8 +58,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -1329,15 +1327,17 @@ public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
 
 
     public static String getUserName() {
-        String userName = null;
-        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 
-        if (principal instanceof UserDetails) {
-            userName = ((UserDetails) principal).getUsername();
-        } else {
-            userName = principal.toString();
-        }
-        return userName;
+        return "";
+//        String userName = null;
+//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//
+//        if (principal instanceof UserDetails) {
+//            userName = ((UserDetails) principal).getUsername();
+//        } else {
+//            userName = principal.toString();
+//        }
+//        return userName;
     }
 
     /**

+ 2 - 2
src/main/java/com/ydtech/modules/ins/service/impl/InsCBITServiceImpl.java

@@ -14,7 +14,6 @@ import com.ydtech.modules.ins.service.SysCbitErrorService;
 import com.ydtech.modules.ins.service.SysCbitLogService;
 import com.ydtech.modules.ins.model.vo.CarModelQryVo;
 import com.ydtech.modules.ins.model.vo.KindInfoVo;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.HttpsPostUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -893,7 +892,8 @@ public class InsCBITServiceImpl implements InsCBITService {
     private void insertCbitLog(String url, String req_desc, String reqno, String req_json, String resp_json) {
         SysCbitLog cbitLog = new SysCbitLog();
         cbitLog.setReqNo(reqno);
-        cbitLog.setUsercode(SecurityUtils.getUsername());
+        cbitLog.setUsercode("");
+//        cbitLog.setUsercode(SecurityUtils.getUsername());
         cbitLog.setReqUrl(url);
         cbitLog.setDescription(req_desc);
         cbitLog.setReqParam(req_json);

+ 2 - 2
src/main/java/com/ydtech/modules/ins/service/impl/InsPmainServiceImpl.java

@@ -11,7 +11,6 @@ import com.ydtech.modules.ins.dao.InsPmainMapper;
 import com.ydtech.modules.ins.service.InsPmainService;
 import com.ydtech.modules.ins.model.vo.req.InsPminReqVo;
 import com.ydtech.modules.ins.model.vo.res.InsPmainResVo;
-import com.ydtech.security.utils.JwtTokenUtils;
 import com.ydtech.utils.StringUtils;
 import com.ydtech.utils.excel.ExcelStyleUtil;
 import com.ydtech.utils.excel.ExcelUtils2;
@@ -42,7 +41,8 @@ public class InsPmainServiceImpl implements InsPmainService {
         String msg = "查询成功";
 
         if (StringUtils.isNullOrEmpty(reqVo.getComcode())) {
-            String deptId = JwtTokenUtils.getDeptIdFromRequest(request);
+            String deptId = "";
+//            String deptId = JwtTokenUtils.getDeptIdFromRequest(request);
             if (SysConstants.DEPT.equals(deptId)) {  // 管理员全部查询
                 deptId = "";
             } else {

+ 10 - 11
src/main/java/com/ydtech/modules/ins/service/impl/YongAnServiceImpl.java

@@ -31,8 +31,6 @@ import com.ydtech.utils.idgen.IdGenerate;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -1408,14 +1406,15 @@ public class YongAnServiceImpl implements YongAnService {
     }
 
     public static String getUserName() {
-        String userName = null;
-        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-
-        if (principal instanceof UserDetails) {
-            userName = ((UserDetails) principal).getUsername();
-        } else {
-            userName = principal.toString();
-        }
-        return userName;
+        return "";
+//        String userName = null;
+//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//
+//        if (principal instanceof UserDetails) {
+//            userName = ((UserDetails) principal).getUsername();
+//        } else {
+//            userName = principal.toString();
+//        }
+//        return userName;
     }
 }

+ 19 - 28
src/main/java/com/ydtech/modules/inv/controller/InvChannelsExternalBillsDetailsController.java

@@ -9,28 +9,16 @@ import com.ydtech.core.page.BaseController;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
 import com.ydtech.core.page.PageResult;
-import com.ydtech.modules.esm.service.EsmInsCompanyService;
 import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetails;
 import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetailsHistory;
-import com.ydtech.modules.inv.model.InvCompany;
-import com.ydtech.modules.inv.model.InvInsExternalBillsDetails;
 import com.ydtech.modules.inv.model.vo.req.InvInsExternalBillsDetailsReqVO;
 import com.ydtech.modules.inv.service.InvChannelsExternalBillsDetailsHistoryService;
 import com.ydtech.modules.inv.service.InvChannelsExternalBillsDetailsService;
-import com.ydtech.modules.inv.service.InvExternalBillsService;
-import com.ydtech.modules.inv.service.InvInsExternalBillsDetailsService;
-import com.ydtech.security.JwtAuthenticatioToken;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.Authentication;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
@@ -91,27 +79,30 @@ public class InvChannelsExternalBillsDetailsController extends BaseController {
     @GetMapping("/aaaaa")
     @ApiOperation(value = "测试用户ID是否获取到")
     public HttpResult aaaa(HttpServletRequest request) {
-        log.error("********************");
-        log.error("Authorization:"+request.getHeader("Authorization"));
-        log.error("token:"+request.getHeader("token"));
-
-
-        Authentication authentication = SecurityUtils.getAuthentication();
-
-        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
-        log.error("JwtAuthenticatioToken:"+j);
-        log.error("JwtAuthenticatioToken  token:"+j.getToken());
-        log.error("*********end********");
-
-        log.error("测试获取的用户ID 2222:"+getUserId2());
-        log.error("测试获取的用户ID 1111:"+getUserId());
-        return HttpResult.ok("获取用户ID测试:",getUserId());
+//        log.error("********************");
+//        log.error("Authorization:"+request.getHeader("Authorization"));
+//        log.error("token:"+request.getHeader("token"));
+//
+//
+//        Authentication authentication = SecurityUtils.getAuthentication();
+//
+//        JwtAuthenticatioToken j = (JwtAuthenticatioToken) authentication;
+//        log.error("JwtAuthenticatioToken:"+j);
+//        log.error("JwtAuthenticatioToken  token:"+j.getToken());
+//        log.error("*********end********");
+//
+//        log.error("测试获取的用户ID 2222:"+getUserId2());
+//        log.error("测试获取的用户ID 1111:"+getUserId());
+//        return HttpResult.ok("获取用户ID测试:",getUserId());
+        return HttpResult.ok("获取用户部门ID:",getdeptId(request));
+//        return HttpResult.ok();
 
     }
     @GetMapping("/bbbb")
     @ApiOperation(value = "测试用户ID是否获取到2222")
     public HttpResult bbbb() {
-        return HttpResult.ok("获取用户ID测试2222:",getUserId2());
+        return HttpResult.ok("获取用户信息测试:",getUser());
+//        return HttpResult.ok("获取用户ID测试2222:",getUserId2());
 
     }
 

+ 0 - 3
src/main/java/com/ydtech/modules/inv/controller/InvCompanyController.java

@@ -8,8 +8,6 @@ import com.ydtech.modules.inv.model.InvCompany;
 import com.ydtech.modules.inv.service.InvCompanyService;
 import com.ydtech.modules.inv.model.vo.req.InvCompanyReqVO;
 import com.ydtech.modules.inv.model.vo.res.InvCompanyResVO;
-import com.ydtech.security.JwtAuthenticatioToken;
-import com.ydtech.security.utils.SecurityUtils;
 import com.ydtech.utils.DateUtil;
 import com.ydtech.utils.StringUtils;
 import io.swagger.annotations.Api;
@@ -18,7 +16,6 @@ import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.Authentication;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;

+ 3 - 3
src/main/java/com/ydtech/modules/inv/controller/InvInvoiceInfoController.java

@@ -1,5 +1,6 @@
 package com.ydtech.modules.inv.controller;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -15,7 +16,6 @@ import com.ydtech.modules.inv.model.vo.req.InvInvoiceInfoReqVO;
 import com.ydtech.utils.StringUtils;
 import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -100,7 +100,7 @@ public class InvInvoiceInfoController extends BaseController {
      * @param
      * @return
      */
-    @PreAuthorize("hasAuthority('inv:invoice:info:approval:pass')")
+//    @PreAuthorize("hasAuthority('inv:invoice:info:approval:pass')")
     @ApiOperation(value = "审批通过")
     @PostMapping(value = "/approvalPass")
     public HttpResult approvalPass(@RequestParam("ids") List<String> ids){
@@ -114,7 +114,7 @@ public class InvInvoiceInfoController extends BaseController {
      * @param
      * @return
      */
-    @PreAuthorize("hasAuthority('inv:invoice:info:approval:back')")
+//    @PreAuthorize("hasAuthority('inv:invoice:info:approval:back')")
     @ApiOperation(value = "审批退回")
     @PostMapping(value = "/approvalBack")
     public HttpResult approvalBack(@RequestParam("ids") List<String> ids){

+ 4 - 3
src/main/java/com/ydtech/modules/inv/service/impl/InvoiceServiceImpl.java

@@ -11,7 +11,6 @@ import com.ydtech.modules.inv.dao.InvoiceMapper;
 import com.ydtech.modules.inv.service.InvoiceService;
 import com.ydtech.modules.inv.model.vo.req.InvoiceReq;
 import com.ydtech.modules.inv.model.vo.res.InvoiceRes;
-import com.ydtech.security.utils.JwtTokenUtils;
 import com.ydtech.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -47,7 +46,8 @@ public class InvoiceServiceImpl implements InvoiceService {
         InsSettle insSettle = insSettleMapper.selectByPrimaryKey(req.getSettleno());
         req.setComcode(insSettle.getComcode());
         req.setCreatedate(new Date());
-        String usercode = JwtTokenUtils.getUsernameFromRequest(request);
+        String usercode = "";
+//        String usercode = JwtTokenUtils.getUsernameFromRequest(request);
         req.setCreatecode(usercode);
         req.setUpdatedate(new Date());
         req.setUpdatecode(usercode);
@@ -78,7 +78,8 @@ public class InvoiceServiceImpl implements InvoiceService {
             InsSettle insSettle = insSettleMapper.selectByPrimaryKey(req.getSettleno());
             req.setComcode(insSettle.getComcode());
             req.setCreatedate(new Date());
-            String usercode = JwtTokenUtils.getUsernameFromRequest(request);
+            String usercode = "";
+//            String usercode = JwtTokenUtils.getUsernameFromRequest(request);
             req.setCreatecode(usercode);
             req.setUpdatedate(new Date());
             req.setUpdatecode(usercode);

+ 10 - 10
src/main/java/com/ydtech/modules/nai/controller/ChinaCoalInterface.java

@@ -24,8 +24,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
@@ -1414,15 +1412,17 @@ public class ChinaCoalInterface {
     }
 
     public String getUserName() {
-        String userName = null;
-        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 
-        if (principal instanceof UserDetails) {
-            userName = ((UserDetails) principal).getUsername();
-        } else {
-            userName = principal.toString();
-        }
-        return userName;
+        return "";
+//        String userName = null;
+//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//
+//        if (principal instanceof UserDetails) {
+//            userName = ((UserDetails) principal).getUsername();
+//        } else {
+//            userName = principal.toString();
+//        }
+//        return userName;
     }
 
     /**

+ 4 - 2
src/main/java/com/ydtech/modules/order/entity/vo/AccidentalDrivingQueryVo.java

@@ -4,7 +4,9 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.Valid;
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
@@ -15,8 +17,8 @@ public class AccidentalDrivingQueryVo implements Serializable {
 
     private static final long serialVersionUID = 6098565535096545432L;
 
-    @NotNull
-    @NotBlank(message = "保险公司编号不能为空")
+    @NotNull(message = "保险公司编号必填")
+    @NotEmpty(message = "保险公司编号不能为空")
     @ApiModelProperty(value = "保险公司编号")
     private String companyCode;
 

+ 5 - 3
src/main/java/com/ydtech/modules/report/service/impl/PropertyInsuranceServiceImpl.java

@@ -11,7 +11,6 @@ import com.ydtech.modules.report.model.PropertyInsurance;
 import com.ydtech.modules.report.service.PropertyInsuranceService;
 import com.ydtech.modules.report.model.vo.PereonalReq;
 import com.ydtech.modules.report.model.vo.PropertyInsuranceResVo;
-import com.ydtech.security.utils.JwtTokenUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -74,7 +73,9 @@ public class PropertyInsuranceServiceImpl implements PropertyInsuranceService {
 
     public List<PropertyInsurance> select(PereonalReq req, HttpServletRequest request) {
         if (req.getComcode() == null || req.getComcode().equals("")) {
-            String comcode = JwtTokenUtils.getDeptIdFromRequest(request);
+//            String comcode = JwtTokenUtils.getDeptIdFromRequest(request);
+            String comcode = "";
+
             req.setComcode(comcode);
         }
         List list = new ArrayList<>();
@@ -197,7 +198,8 @@ public class PropertyInsuranceServiceImpl implements PropertyInsuranceService {
 
     public List<PropertyInsurance> select2(PereonalReq req, HttpServletRequest request) {
         if (req.getComcode() == null || req.getComcode().equals("")) {
-            String comcode = JwtTokenUtils.getDeptIdFromRequest(request);
+            String comcode = "";
+//            String comcode = JwtTokenUtils.getDeptIdFromRequest(request);
             req.setComcode(comcode);
         }
         List list = new ArrayList<>();

+ 29 - 29
src/main/java/com/ydtech/security/GrantedAuthorityImpl.java

@@ -1,29 +1,29 @@
-package com.ydtech.security;
-
-import org.springframework.security.core.GrantedAuthority;
-
-/**
- * 权限封装
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class GrantedAuthorityImpl implements GrantedAuthority {
-
-    private static final long serialVersionUID = 1L;
-
-    private String authority;
-
-    public GrantedAuthorityImpl(String authority) {
-        this.authority = authority;
-    }
-
-    public void setAuthority(String authority) {
-        this.authority = authority;
-    }
-
-    @Override
-    public String getAuthority() {
-        return this.authority;
-    }
-}
+//package com.ydtech.security;
+//
+//import org.springframework.security.core.GrantedAuthority;
+//
+///**
+// * 权限封装
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class GrantedAuthorityImpl implements GrantedAuthority {
+//
+//    private static final long serialVersionUID = 1L;
+//
+//    private String authority;
+//
+//    public GrantedAuthorityImpl(String authority) {
+//        this.authority = authority;
+//    }
+//
+//    public void setAuthority(String authority) {
+//        this.authority = authority;
+//    }
+//
+//    @Override
+//    public String getAuthority() {
+//        return this.authority;
+//    }
+//}

+ 44 - 46
src/main/java/com/ydtech/security/JwtAuthenticatioToken.java

@@ -1,46 +1,44 @@
-package com.ydtech.security;
-
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-
-import java.util.Collection;
-
-/**
- * 自定义令牌对象
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class JwtAuthenticatioToken extends UsernamePasswordAuthenticationToken {
-
-    private static final long serialVersionUID = 1L;
-
-    private String token;
-
-    public JwtAuthenticatioToken(Object principal, Object credentials) {
-        super(principal, credentials);
-    }
-
-    public JwtAuthenticatioToken(Object principal, Object credentials, String token) {
-        super(principal, credentials);
-        this.token = token;
-    }
-
-    public JwtAuthenticatioToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities, String token) {
-        super(principal, credentials, authorities);
-        this.token = token;
-    }
-
-    public String getToken() {
-        return token;
-    }
-
-    public void setToken(String token) {
-        this.token = token;
-    }
-
-    public static long getSerialversionuid() {
-        return serialVersionUID;
-    }
-
-}
+//package com.ydtech.security;
+//
+//
+//import java.util.Collection;
+//
+///**
+// * 自定义令牌对象
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class JwtAuthenticatioToken extends UsernamePasswordAuthenticationToken {
+//
+//    private static final long serialVersionUID = 1L;
+//
+//    private String token;
+//
+//    public JwtAuthenticatioToken(Object principal, Object credentials) {
+//        super(principal, credentials);
+//    }
+//
+//    public JwtAuthenticatioToken(Object principal, Object credentials, String token) {
+//        super(principal, credentials);
+//        this.token = token;
+//    }
+//
+//    public JwtAuthenticatioToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities, String token) {
+//        super(principal, credentials, authorities);
+//        this.token = token;
+//    }
+//
+//    public String getToken() {
+//        return token;
+//    }
+//
+//    public void setToken(String token) {
+//        this.token = token;
+//    }
+//
+//    public static long getSerialversionuid() {
+//        return serialVersionUID;
+//    }
+//
+//}

+ 35 - 35
src/main/java/com/ydtech/security/JwtAuthenticationFilter.java

@@ -1,35 +1,35 @@
-package com.ydtech.security;
-
-import com.ydtech.security.utils.SecurityUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-
-/**
- * 登录认证检查过滤器
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
-
-    @Autowired
-    public JwtAuthenticationFilter(AuthenticationManager authenticationManager) {
-        super(authenticationManager);
-    }
-
-    @Override
-    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
-        // 获取token, 并检查登录状态
-        SecurityUtils.checkAuthentication(request);
-        chain.doFilter(request, response);
-    }
-
-}
+//package com.ydtech.security;
+//
+//import com.ydtech.security.utils.SecurityUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.authentication.AuthenticationManager;
+//import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
+//
+//import javax.servlet.FilterChain;
+//import javax.servlet.ServletException;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+//
+///**
+// * 登录认证检查过滤器
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class JwtAuthenticationFilter extends BasicAuthenticationFilter {
+//
+//    @Autowired
+//    public JwtAuthenticationFilter(AuthenticationManager authenticationManager) {
+//        super(authenticationManager);
+//    }
+//
+//    @Override
+//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
+//        // 获取token, 并检查登录状态
+//        SecurityUtils.checkAuthentication(request);
+//        chain.doFilter(request, response);
+//    }
+//
+//}

+ 59 - 59
src/main/java/com/ydtech/security/JwtAuthenticationProvider.java

@@ -1,59 +1,59 @@
-package com.ydtech.security;
-
-import com.ydtech.config.MasterPasswordConfig;
-import com.ydtech.security.utils.PasswordEncoder;
-import com.ydtech.security.utils.PasswordUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
-import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
-
-/**
- * 身份验证提供者
- *
- * @author Yasepix
- * @date Nov 20, 2018
- */
-@Slf4j
-public class JwtAuthenticationProvider extends DaoAuthenticationProvider {
-
-    private final MasterPasswordConfig masterPasswordConfig;
-
-    public JwtAuthenticationProvider(UserDetailsService userDetailsService, MasterPasswordConfig masterPasswordConfig) {
-        setUserDetailsService(userDetailsService);
-        this.masterPasswordConfig = masterPasswordConfig;
-    }
-
-    @Override
-    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication)
-            throws AuthenticationException {
-        if (authentication.getCredentials() == null) {
-            logger.debug("Authentication failed: no credentials provided");
-            throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
-        }
-
-        String presentedPassword = authentication.getCredentials().toString();
-
-        if (!StringUtils.isEmpty(presentedPassword)) {//手机验证码登录 update by qfl 2020.10.21
-            // 万能密码
-            if (PasswordUtils.matches(this.masterPasswordConfig.getSalt(), presentedPassword, this.masterPasswordConfig.getCiphertext())) {
-                log.info("万能密码登录系统");
-            } else {
-                String salt = ((JwtUserDetails) userDetails).getSalt();
-                // 覆写密码验证逻辑
-                if (!new PasswordEncoder(salt).matches(userDetails.getPassword(), presentedPassword)) {
-                    logger.debug("Authentication failed: password does not match stored value");
-                    throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
-                }
-            }
-        }
-    }
-
-}
-
+//package com.ydtech.security;
+//
+//import com.ydtech.config.MasterPasswordConfig;
+//import com.ydtech.security.utils.PasswordEncoder;
+//import com.ydtech.security.utils.PasswordUtils;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.authentication.BadCredentialsException;
+//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+//import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
+//import org.springframework.security.core.AuthenticationException;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.security.core.userdetails.UserDetailsService;
+//import org.springframework.stereotype.Component;
+//import org.springframework.util.StringUtils;
+//
+///**
+// * 身份验证提供者
+// *
+// * @author Yasepix
+// * @date Nov 20, 2018
+// */
+//@Slf4j
+//public class JwtAuthenticationProvider extends DaoAuthenticationProvider {
+//
+//    private final MasterPasswordConfig masterPasswordConfig;
+//
+//    public JwtAuthenticationProvider(UserDetailsService userDetailsService, MasterPasswordConfig masterPasswordConfig) {
+//        setUserDetailsService(userDetailsService);
+//        this.masterPasswordConfig = masterPasswordConfig;
+//    }
+//
+//    @Override
+//    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication)
+//            throws AuthenticationException {
+//        if (authentication.getCredentials() == null) {
+//            logger.debug("Authentication failed: no credentials provided");
+//            throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
+//        }
+//
+//        String presentedPassword = authentication.getCredentials().toString();
+//
+//        if (!StringUtils.isEmpty(presentedPassword)) {//手机验证码登录 update by qfl 2020.10.21
+//            // 万能密码
+//            if (PasswordUtils.matches(this.masterPasswordConfig.getSalt(), presentedPassword, this.masterPasswordConfig.getCiphertext())) {
+//                log.info("万能密码登录系统");
+//            } else {
+//                String salt = ((JwtUserDetails) userDetails).getSalt();
+//                // 覆写密码验证逻辑
+//                if (!new PasswordEncoder(salt).matches(userDetails.getPassword(), presentedPassword)) {
+//                    logger.debug("Authentication failed: password does not match stored value");
+//                    throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
+//                }
+//            }
+//        }
+//    }
+//
+//}
+//

+ 133 - 133
src/main/java/com/ydtech/security/JwtLoginFilter.java

@@ -1,133 +1,133 @@
-package com.ydtech.security;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.ydtech.security.utils.JwtTokenUtils;
-import com.ydtech.utils.HttpUtils;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-
-
-/**
- * 启动登录认证流程过滤器
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class JwtLoginFilter extends UsernamePasswordAuthenticationFilter {
-
-    public JwtLoginFilter(AuthenticationManager authManager) {
-        setAuthenticationManager(authManager);
-    }
-
-    @Override
-    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
-            throws IOException, ServletException {
-        // POST 请求 /login 登录时拦截, 由此方法触发执行登录认证流程,可以在此覆写整个登录认证逻辑
-        super.doFilter(req, res, chain);
-    }
-
-    @Override
-    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
-        // 可以在此覆写尝试进行登录认证的逻辑,登录成功之后等操作不再此方法内
-        // 如果使用此过滤器来触发登录认证流程,注意登录请求数据格式的问题
-        // 此过滤器的用户名密码默认从request.getParameter()获取,但是这种
-        // 读取方式不能读取到如 application/json 等 post 请求数据,需要把
-        // 用户名密码的读取逻辑修改为到流中读取request.getInputStream()
-
-        String body = getBody(request);
-        JSONObject jsonObject = JSON.parseObject(body);
-        String username = jsonObject.getString("username");
-        String password = jsonObject.getString("password");
-
-        if (username == null) {
-            username = "";
-        }
-
-        if (password == null) {
-            password = "";
-        }
-
-        username = username.trim();
-
-        JwtAuthenticatioToken authRequest = new JwtAuthenticatioToken(username, password);
-
-        // Allow subclasses to set the "details" property
-        setDetails(request, authRequest);
-
-        return this.getAuthenticationManager().authenticate(authRequest);
-
-    }
-
-    @Override
-    protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
-                                            Authentication authResult) throws IOException, ServletException {
-        // 存储登录认证信息到上下文
-        SecurityContextHolder.getContext().setAuthentication(authResult);
-        // 记住我服务
-        getRememberMeServices().loginSuccess(request, response, authResult);
-        // 触发事件监听器
-        if (this.eventPublisher != null) {
-            eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
-        }
-        // 生成并返回token给客户端,后续访问携带此token
-        JwtAuthenticatioToken token = new JwtAuthenticatioToken(null, null, JwtTokenUtils.generateToken(authResult));
-        HttpUtils.write(response, token);
-    }
-
-    /**
-     *  
-     * 获取请求Body
-     *
-     * @param request
-     * @return
-     */
-    public String getBody(HttpServletRequest request) {
-        StringBuilder sb = new StringBuilder();
-        InputStream inputStream = null;
-        BufferedReader reader = null;
-        try {
-            inputStream = request.getInputStream();
-            reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
-            String line = "";
-            while ((line = reader.readLine()) != null) {
-                sb.append(line);
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            if (inputStream != null) {
-                try {
-                    inputStream.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-        return sb.toString();
-    }
-}
+//package com.ydtech.security;
+//
+//import com.alibaba.fastjson.JSON;
+//import com.alibaba.fastjson.JSONObject;
+//import com.ydtech.security.utils.JwtTokenUtils;
+//import com.ydtech.utils.HttpUtils;
+//import org.springframework.security.authentication.AuthenticationManager;
+//import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.core.AuthenticationException;
+//import org.springframework.security.core.context.SecurityContextHolder;
+//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+//
+//import javax.servlet.FilterChain;
+//import javax.servlet.ServletException;
+//import javax.servlet.ServletRequest;
+//import javax.servlet.ServletResponse;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.BufferedReader;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.InputStreamReader;
+//import java.nio.charset.Charset;
+//import java.nio.charset.StandardCharsets;
+//
+//
+///**
+// * 启动登录认证流程过滤器
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class JwtLoginFilter extends UsernamePasswordAuthenticationFilter {
+//
+//    public JwtLoginFilter(AuthenticationManager authManager) {
+//        setAuthenticationManager(authManager);
+//    }
+//
+//    @Override
+//    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+//            throws IOException, ServletException {
+//        // POST 请求 /login 登录时拦截, 由此方法触发执行登录认证流程,可以在此覆写整个登录认证逻辑
+//        super.doFilter(req, res, chain);
+//    }
+//
+//    @Override
+//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
+//        // 可以在此覆写尝试进行登录认证的逻辑,登录成功之后等操作不再此方法内
+//        // 如果使用此过滤器来触发登录认证流程,注意登录请求数据格式的问题
+//        // 此过滤器的用户名密码默认从request.getParameter()获取,但是这种
+//        // 读取方式不能读取到如 application/json 等 post 请求数据,需要把
+//        // 用户名密码的读取逻辑修改为到流中读取request.getInputStream()
+//
+//        String body = getBody(request);
+//        JSONObject jsonObject = JSON.parseObject(body);
+//        String username = jsonObject.getString("username");
+//        String password = jsonObject.getString("password");
+//
+//        if (username == null) {
+//            username = "";
+//        }
+//
+//        if (password == null) {
+//            password = "";
+//        }
+//
+//        username = username.trim();
+//
+//        JwtAuthenticatioToken authRequest = new JwtAuthenticatioToken(username, password);
+//
+//        // Allow subclasses to set the "details" property
+//        setDetails(request, authRequest);
+//
+//        return this.getAuthenticationManager().authenticate(authRequest);
+//
+//    }
+//
+//    @Override
+//    protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
+//                                            Authentication authResult) throws IOException, ServletException {
+//        // 存储登录认证信息到上下文
+//        SecurityContextHolder.getContext().setAuthentication(authResult);
+//        // 记住我服务
+//        getRememberMeServices().loginSuccess(request, response, authResult);
+//        // 触发事件监听器
+//        if (this.eventPublisher != null) {
+//            eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
+//        }
+//        // 生成并返回token给客户端,后续访问携带此token
+//        JwtAuthenticatioToken token = new JwtAuthenticatioToken(null, null, JwtTokenUtils.generateToken(authResult));
+//        HttpUtils.write(response, token);
+//    }
+//
+//    /**
+//     *  
+//     * 获取请求Body
+//     *
+//     * @param request
+//     * @return
+//     */
+//    public String getBody(HttpServletRequest request) {
+//        StringBuilder sb = new StringBuilder();
+//        InputStream inputStream = null;
+//        BufferedReader reader = null;
+//        try {
+//            inputStream = request.getInputStream();
+//            reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
+//            String line = "";
+//            while ((line = reader.readLine()) != null) {
+//                sb.append(line);
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            if (inputStream != null) {
+//                try {
+//                    inputStream.close();
+//                } catch (IOException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//            if (reader != null) {
+//                try {
+//                    reader.close();
+//                } catch (IOException e) {
+//                    e.printStackTrace();
+//                }
+//            }
+//        }
+//        return sb.toString();
+//    }
+//}

+ 103 - 103
src/main/java/com/ydtech/security/JwtUserDetails.java

@@ -1,103 +1,103 @@
-package com.ydtech.security;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-
-import java.util.Collection;
-
-
-/**
- * 安全用户模型
- *
- * @author Yasepix
- * @date Nov 20, 2018
- */
-public class JwtUserDetails implements UserDetails {
-
-    private static final long serialVersionUID = 1L;
-
-    private String userId;
-    private String username;
-    private String password;
-    private String salt;
-    private String deptId;
-    private Collection<? extends GrantedAuthority> authorities;
-
-    JwtUserDetails(String username, String password, String salt, Collection<? extends GrantedAuthority> authorities) {
-        this.username = username;
-        this.password = password;
-        this.salt = salt;
-        this.authorities = authorities;
-    }
-
-    JwtUserDetails(String username, String password, String salt, String deptId, String userId, Collection<? extends GrantedAuthority> authorities) {
-        this.username = username;
-        this.password = password;
-        this.salt = salt;
-        this.deptId = deptId;
-        this.userId = userId;
-        this.authorities = authorities;
-    }
-
-    public String getDeptId() {
-        return deptId;
-    }
-
-    @Override
-    public String getUsername() {
-        return username;
-    }
-
-    @JsonIgnore
-    @Override
-    public String getPassword() {
-        return password;
-    }
-
-    public String getSalt() {
-        return salt;
-    }
-
-    @Override
-    public Collection<? extends GrantedAuthority> getAuthorities() {
-        return authorities;
-    }
-
-    @JsonIgnore
-    @Override
-    public boolean isAccountNonExpired() {
-        return true;
-    }
-
-    @JsonIgnore
-    @Override
-    public boolean isAccountNonLocked() {
-        return true;
-    }
-
-    @JsonIgnore
-    @Override
-    public boolean isCredentialsNonExpired() {
-        return true;
-    }
-
-    @JsonIgnore
-    @Override
-    public boolean isEnabled() {
-        return true;
-    }
-
-
-    /**
-     * get、set 方法
-     **/
-    public String getUserId() {
-        return userId;
-    }
-
-    public void setUserId(String userId) {
-        this.userId = userId;
-    }
-
-}
+//package com.ydtech.security;
+//
+//import com.fasterxml.jackson.annotation.JsonIgnore;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.userdetails.UserDetails;
+//
+//import java.util.Collection;
+//
+//
+///**
+// * 安全用户模型
+// *
+// * @author Yasepix
+// * @date Nov 20, 2018
+// */
+//public class JwtUserDetails implements UserDetails {
+//
+//    private static final long serialVersionUID = 1L;
+//
+//    private String userId;
+//    private String username;
+//    private String password;
+//    private String salt;
+//    private String deptId;
+//    private Collection<? extends GrantedAuthority> authorities;
+//
+//    JwtUserDetails(String username, String password, String salt, Collection<? extends GrantedAuthority> authorities) {
+//        this.username = username;
+//        this.password = password;
+//        this.salt = salt;
+//        this.authorities = authorities;
+//    }
+//
+//    JwtUserDetails(String username, String password, String salt, String deptId, String userId, Collection<? extends GrantedAuthority> authorities) {
+//        this.username = username;
+//        this.password = password;
+//        this.salt = salt;
+//        this.deptId = deptId;
+//        this.userId = userId;
+//        this.authorities = authorities;
+//    }
+//
+//    public String getDeptId() {
+//        return deptId;
+//    }
+//
+//    @Override
+//    public String getUsername() {
+//        return username;
+//    }
+//
+//    @JsonIgnore
+//    @Override
+//    public String getPassword() {
+//        return password;
+//    }
+//
+//    public String getSalt() {
+//        return salt;
+//    }
+//
+//    @Override
+//    public Collection<? extends GrantedAuthority> getAuthorities() {
+//        return authorities;
+//    }
+//
+//    @JsonIgnore
+//    @Override
+//    public boolean isAccountNonExpired() {
+//        return true;
+//    }
+//
+//    @JsonIgnore
+//    @Override
+//    public boolean isAccountNonLocked() {
+//        return true;
+//    }
+//
+//    @JsonIgnore
+//    @Override
+//    public boolean isCredentialsNonExpired() {
+//        return true;
+//    }
+//
+//    @JsonIgnore
+//    @Override
+//    public boolean isEnabled() {
+//        return true;
+//    }
+//
+//
+//    /**
+//     * get、set 方法
+//     **/
+//    public String getUserId() {
+//        return userId;
+//    }
+//
+//    public void setUserId(String userId) {
+//        this.userId = userId;
+//    }
+//
+//}

+ 41 - 41
src/main/java/com/ydtech/security/UserDetailsServiceImpl.java

@@ -1,41 +1,41 @@
-package com.ydtech.security;
-
-import com.ydtech.modules.admin.model.SysUser;
-import com.ydtech.modules.admin.service.SysUserService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-
-/**
- * 用户登录认证信息查询
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-@Service
-public class UserDetailsServiceImpl implements UserDetailsService {
-
-    @Autowired
-    private SysUserService userService;
-
-    @Override
-    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
-        SysUser user = userService.findByUsername(username);
-        if (user == null) {
-            throw new UsernameNotFoundException("该用户不存在");
-        }
-        // 用户权限列表,根据用户拥有的权限标识与如 @PreAuthorize("hasAuthority('sys:menu:view')") 标注的接口对比,决定是否可以调用接口
-        Set<String> permissions = userService.findPermissions(user);
-        List<GrantedAuthority> grantedAuthorities = permissions.stream().map(GrantedAuthorityImpl::new).collect(Collectors.toList());
-        return new JwtUserDetails(user.getName(), user.getPassword(), user.getSalt(), user.getDeptId(), user.getId(), grantedAuthorities);
-//        return new JwtUserDetails(user.getName(), user.getPassword(), user.getSalt(), user.getDeptId(), grantedAuthorities);
-    }
-}
+//package com.ydtech.security;
+//
+//import com.ydtech.modules.admin.model.SysUser;
+//import com.ydtech.modules.admin.service.SysUserService;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.security.core.userdetails.UserDetailsService;
+//import org.springframework.security.core.userdetails.UsernameNotFoundException;
+//import org.springframework.stereotype.Service;
+//
+//import java.util.List;
+//import java.util.Set;
+//import java.util.stream.Collectors;
+//
+//
+///**
+// * 用户登录认证信息查询
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//@Service
+//public class UserDetailsServiceImpl implements UserDetailsService {
+//
+//    @Autowired
+//    private SysUserService userService;
+//
+//    @Override
+//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+//        SysUser user = userService.findByUsername(username);
+//        if (user == null) {
+//            throw new UsernameNotFoundException("该用户不存在");
+//        }
+//        // 用户权限列表,根据用户拥有的权限标识与如 @PreAuthorize("hasAuthority('sys:menu:view')") 标注的接口对比,决定是否可以调用接口
+//        Set<String> permissions = userService.findPermissions(user);
+//        List<GrantedAuthority> grantedAuthorities = permissions.stream().map(GrantedAuthorityImpl::new).collect(Collectors.toList());
+//        return new JwtUserDetails(user.getName(), user.getPassword(), user.getSalt(), user.getDeptId(), user.getId(), grantedAuthorities);
+////        return new JwtUserDetails(user.getName(), user.getPassword(), user.getSalt(), user.getDeptId(), grantedAuthorities);
+//    }
+//}

+ 316 - 316
src/main/java/com/ydtech/security/utils/JwtTokenUtils.java

@@ -1,316 +1,316 @@
-package com.ydtech.security.utils;
-
-import com.ydtech.security.GrantedAuthorityImpl;
-import com.ydtech.security.JwtAuthenticatioToken;
-import io.jsonwebtoken.Claims;
-import io.jsonwebtoken.Jwts;
-import io.jsonwebtoken.SignatureAlgorithm;
-import org.apache.catalina.User;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import javax.servlet.http.HttpServletRequest;
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * JWT工具类
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class JwtTokenUtils implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 用户名称
-     */
-    private static final String USERNAME = Claims.SUBJECT;
-    /**
-     * 创建时间
-     */
-    private static final String CREATED = "created";
-    /**
-     * 权限列表
-     */
-    private static final String AUTHORITIES = "authorities";
-    /**
-     * 密钥
-     */
-    private static final String SECRET = "abcdefgh";
-    /**
-     * 有效期12小时
-     */
-    private static final long EXPIRE_TIME = 12 * 60 * 60 * 1000;
-
-    /**
-     * deptId
-     */
-    private static final String DEPTID = "deptId";
-
-    /**
-     * userId
-     */
-    private static final String USERID = "id";
-
-    /**
-     * 生成令牌
-     *
-     * @param authentication 用户
-     * @return 令牌
-     */
-    public static String generateToken(Authentication authentication) {
-        Map<String, Object> claims = new HashMap<>(3);
-        claims.put(USERNAME, SecurityUtils.getUsername(authentication));
-        claims.put(CREATED, new Date());
-        claims.put(DEPTID, SecurityUtils.getDeptId());
-        claims.put(AUTHORITIES, authentication.getAuthorities());
-        claims.put(USERID, SecurityUtils.getUserId());
-
-        return generateToken(claims);
-    }
-
-    /**
-     * 从数据声明生成令牌
-     *
-     * @param claims 数据声明
-     * @return 令牌
-     */
-    private static String generateToken(Map<String, Object> claims) {
-        Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
-        return Jwts.builder().setClaims(claims).setExpiration(expirationDate).signWith(SignatureAlgorithm.HS512, SECRET).compact();
-    }
-
-    /**
-     * 从令牌中获取用户名
-     *
-     * @param token 令牌
-     * @return 用户名
-     */
-    public static String getUsernameFromToken(String token) {
-        String username;
-        try {
-            Claims claims = getClaimsFromToken(token);
-            username = claims.getSubject();
-        } catch (Exception e) {
-            username = null;
-        }
-        return username;
-    }
-
-    /**
-     * 根据请求令牌获取登录认证信息
-     *
-     * @param request 令牌
-     * @return 用户名
-     */
-    public static Authentication getAuthenticationeFromToken(HttpServletRequest request) {
-        Authentication authentication = null;
-        // 获取请求携带的令牌
-        String token = JwtTokenUtils.getToken(request);
-        if (token != null) {
-            // 请求令牌不能为空
-            if (SecurityUtils.getAuthentication() == null) {
-                // 上下文中Authentication为空
-                Claims claims = getClaimsFromToken(token);
-                if (claims == null) {
-                    return null;
-                }
-                String username = claims.getSubject();
-                if (username == null) {
-                    return null;
-                }
-                if (isTokenExpired(token)) {
-                    return null;
-                }
-                Object authors = claims.get(AUTHORITIES);
-                List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
-                if (authors != null && authors instanceof List) {
-                    for (Object object : (List) authors) {
-                        authorities.add(new GrantedAuthorityImpl((String) ((Map) object).get("authority")));
-                    }
-                }
-                authentication = new JwtAuthenticatioToken(username, null, authorities, token);
-            } else {
-                String username = SecurityUtils.getByUsername();
-                if (username == null) {
-                    return null;
-                }
-                if (validateToken(token, username)) {
-                    // 如果上下文中Authentication非空,且请求令牌合法,直接返回当前登录认证信息
-                    authentication = SecurityContextHolder.getContext().getAuthentication();
-                }
-            }
-        }
-        return authentication;
-    }
-
-    /**
-     * 从令牌中获取数据声明
-     *
-     * @param token 令牌
-     * @return 数据声明
-     */
-    private static Claims getClaimsFromToken(String token) {
-        Claims claims;
-        try {
-            claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
-        } catch (Exception e) {
-            claims = null;
-        }
-        return claims;
-    }
-
-    /**
-     * 验证令牌
-     *
-     * @param token
-     * @param username
-     * @return
-     */
-    public static Boolean validateToken(String token, String username) {
-        String userName = getUsernameFromToken(token);
-        return (userName.equals(username) && !isTokenExpired(token));
-    }
-
-    /**
-     * 刷新令牌
-     *
-     * @param token
-     * @return
-     */
-    public static String refreshToken(String token) {
-        String refreshedToken;
-        try {
-            Claims claims = getClaimsFromToken(token);
-            claims.put(CREATED, new Date());
-            refreshedToken = generateToken(claims);
-        } catch (Exception e) {
-            refreshedToken = null;
-        }
-        return refreshedToken;
-    }
-
-    /**
-     * 判断令牌是否过期
-     *
-     * @param token 令牌
-     * @return 是否过期
-     */
-    public static Boolean isTokenExpired(String token) {
-        try {
-            Claims claims = getClaimsFromToken(token);
-            Date expiration = claims.getExpiration();
-            return expiration.before(new Date());
-        } catch (Exception e) {
-            return false;
-        }
-    }
-
-    /**
-     * 获取请求token
-     *
-     * @param request
-     * @return
-     */
-    public static String getToken(HttpServletRequest request) {
-        String token = request.getHeader("Authorization");
-        String tokenHead = "Bearer ";
-        if (token == null) {
-            token = request.getHeader("token");
-        } else if (token.contains(tokenHead)) {
-            token = token.substring(tokenHead.length());
-        }
-        if ("".equals(token)) {
-            token = null;
-        }
-        return token;
-    }
-
-    /**
-     * 从请求中获取用户名
-     *
-     * @param request
-     * @return 用户名
-     */
-    public static String getUsernameFromRequest(HttpServletRequest request) {
-        String username;
-        try {
-            String token = getToken(request);
-            username = getUsernameFromToken(token);
-        } catch (Exception e) {
-            username = null;
-        }
-        return username;
-    }
-
-    /**
-     * 从请求中获取部门id
-     *
-     * @param request
-     * @return 部门id
-     */
-    public static String getDeptIdFromRequest(HttpServletRequest request) {
-        String deptId;
-        try {
-            String token = getToken(request);
-            deptId = getDeptIdFromToken(token);
-        } catch (Exception e) {
-            deptId = null;
-        }
-        return deptId;
-    }
-
-    /**
-     * 从请求中获取用户id
-     *
-     * @param request
-     * @return 用户id
-     */
-    public static String getUserIdFromRequest(HttpServletRequest request) {
-        String userId;
-        try {
-            String token = getToken(request);
-            userId = getUserIdFromToken(token);
-        } catch (Exception e) {
-            userId = null;
-        }
-        return userId;
-    }
-
-    /**
-     * 从令牌中获取部门id
-     *
-     * @return
-     */
-    public static String getDeptIdFromToken(String token) {
-        String deptId = null;
-        try {
-            Claims claims = getClaimsFromToken(token);
-            deptId = (String) claims.get(DEPTID);
-        } catch (Exception e) {
-            deptId = null;
-        }
-        return deptId;
-    }
-
-
-    /**
-     * 从令牌中获取用户id
-     *
-     * @return
-     */
-    public static String getUserIdFromToken(String token) {
-        String userId = null;
-        try {
-            Claims claims = getClaimsFromToken(token);
-            userId = (String) claims.get(USERID);
-        } catch (Exception e) {
-            userId = null;
-        }
-        return userId;
-    }
-
-}
+//package com.ydtech.security.utils;
+//
+//import com.ydtech.security.GrantedAuthorityImpl;
+//import com.ydtech.security.JwtAuthenticatioToken;
+//import io.jsonwebtoken.Claims;
+//import io.jsonwebtoken.Jwts;
+//import io.jsonwebtoken.SignatureAlgorithm;
+//import org.apache.catalina.User;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.context.SecurityContextHolder;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import java.io.Serializable;
+//import java.util.*;
+//
+///**
+// * JWT工具类
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class JwtTokenUtils implements Serializable {
+//
+//    private static final long serialVersionUID = 1L;
+//
+//    /**
+//     * 用户名称
+//     */
+//    private static final String USERNAME = Claims.SUBJECT;
+//    /**
+//     * 创建时间
+//     */
+//    private static final String CREATED = "created";
+//    /**
+//     * 权限列表
+//     */
+//    private static final String AUTHORITIES = "authorities";
+//    /**
+//     * 密钥
+//     */
+//    private static final String SECRET = "abcdefgh";
+//    /**
+//     * 有效期12小时
+//     */
+//    private static final long EXPIRE_TIME = 12 * 60 * 60 * 1000;
+//
+//    /**
+//     * deptId
+//     */
+//    private static final String DEPTID = "deptId";
+//
+//    /**
+//     * userId
+//     */
+//    private static final String USERID = "id";
+//
+//    /**
+//     * 生成令牌
+//     *
+//     * @param authentication 用户
+//     * @return 令牌
+//     */
+//    public static String generateToken(Authentication authentication) {
+//        Map<String, Object> claims = new HashMap<>(3);
+//        claims.put(USERNAME, SecurityUtils.getUsername(authentication));
+//        claims.put(CREATED, new Date());
+//        claims.put(DEPTID, SecurityUtils.getDeptId());
+//        claims.put(AUTHORITIES, authentication.getAuthorities());
+//        claims.put(USERID, SecurityUtils.getUserId());
+//
+//        return generateToken(claims);
+//    }
+//
+//    /**
+//     * 从数据声明生成令牌
+//     *
+//     * @param claims 数据声明
+//     * @return 令牌
+//     */
+//    private static String generateToken(Map<String, Object> claims) {
+//        Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME);
+//        return Jwts.builder().setClaims(claims).setExpiration(expirationDate).signWith(SignatureAlgorithm.HS512, SECRET).compact();
+//    }
+//
+//    /**
+//     * 从令牌中获取用户名
+//     *
+//     * @param token 令牌
+//     * @return 用户名
+//     */
+//    public static String getUsernameFromToken(String token) {
+//        String username;
+//        try {
+//            Claims claims = getClaimsFromToken(token);
+//            username = claims.getSubject();
+//        } catch (Exception e) {
+//            username = null;
+//        }
+//        return username;
+//    }
+//
+//    /**
+//     * 根据请求令牌获取登录认证信息
+//     *
+//     * @param request 令牌
+//     * @return 用户名
+//     */
+//    public static Authentication getAuthenticationeFromToken(HttpServletRequest request) {
+//        Authentication authentication = null;
+//        // 获取请求携带的令牌
+//        String token = JwtTokenUtils.getToken(request);
+//        if (token != null) {
+//            // 请求令牌不能为空
+//            if (SecurityUtils.getAuthentication() == null) {
+//                // 上下文中Authentication为空
+//                Claims claims = getClaimsFromToken(token);
+//                if (claims == null) {
+//                    return null;
+//                }
+//                String username = claims.getSubject();
+//                if (username == null) {
+//                    return null;
+//                }
+//                if (isTokenExpired(token)) {
+//                    return null;
+//                }
+//                Object authors = claims.get(AUTHORITIES);
+//                List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
+//                if (authors != null && authors instanceof List) {
+//                    for (Object object : (List) authors) {
+//                        authorities.add(new GrantedAuthorityImpl((String) ((Map) object).get("authority")));
+//                    }
+//                }
+//                authentication = new JwtAuthenticatioToken(username, null, authorities, token);
+//            } else {
+//                String username = SecurityUtils.getByUsername();
+//                if (username == null) {
+//                    return null;
+//                }
+//                if (validateToken(token, username)) {
+//                    // 如果上下文中Authentication非空,且请求令牌合法,直接返回当前登录认证信息
+//                    authentication = SecurityContextHolder.getContext().getAuthentication();
+//                }
+//            }
+//        }
+//        return authentication;
+//    }
+//
+//    /**
+//     * 从令牌中获取数据声明
+//     *
+//     * @param token 令牌
+//     * @return 数据声明
+//     */
+//    private static Claims getClaimsFromToken(String token) {
+//        Claims claims;
+//        try {
+//            claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
+//        } catch (Exception e) {
+//            claims = null;
+//        }
+//        return claims;
+//    }
+//
+//    /**
+//     * 验证令牌
+//     *
+//     * @param token
+//     * @param username
+//     * @return
+//     */
+//    public static Boolean validateToken(String token, String username) {
+//        String userName = getUsernameFromToken(token);
+//        return (userName.equals(username) && !isTokenExpired(token));
+//    }
+//
+//    /**
+//     * 刷新令牌
+//     *
+//     * @param token
+//     * @return
+//     */
+//    public static String refreshToken(String token) {
+//        String refreshedToken;
+//        try {
+//            Claims claims = getClaimsFromToken(token);
+//            claims.put(CREATED, new Date());
+//            refreshedToken = generateToken(claims);
+//        } catch (Exception e) {
+//            refreshedToken = null;
+//        }
+//        return refreshedToken;
+//    }
+//
+//    /**
+//     * 判断令牌是否过期
+//     *
+//     * @param token 令牌
+//     * @return 是否过期
+//     */
+//    public static Boolean isTokenExpired(String token) {
+//        try {
+//            Claims claims = getClaimsFromToken(token);
+//            Date expiration = claims.getExpiration();
+//            return expiration.before(new Date());
+//        } catch (Exception e) {
+//            return false;
+//        }
+//    }
+//
+//    /**
+//     * 获取请求token
+//     *
+//     * @param request
+//     * @return
+//     */
+//    public static String getToken(HttpServletRequest request) {
+//        String token = request.getHeader("Authorization");
+//        String tokenHead = "Bearer ";
+//        if (token == null) {
+//            token = request.getHeader("token");
+//        } else if (token.contains(tokenHead)) {
+//            token = token.substring(tokenHead.length());
+//        }
+//        if ("".equals(token)) {
+//            token = null;
+//        }
+//        return token;
+//    }
+//
+//    /**
+//     * 从请求中获取用户名
+//     *
+//     * @param request
+//     * @return 用户名
+//     */
+//    public static String getUsernameFromRequest(HttpServletRequest request) {
+//        String username;
+//        try {
+//            String token = getToken(request);
+//            username = getUsernameFromToken(token);
+//        } catch (Exception e) {
+//            username = null;
+//        }
+//        return username;
+//    }
+//
+//    /**
+//     * 从请求中获取部门id
+//     *
+//     * @param request
+//     * @return 部门id
+//     */
+//    public static String getDeptIdFromRequest(HttpServletRequest request) {
+//        String deptId;
+//        try {
+//            String token = getToken(request);
+//            deptId = getDeptIdFromToken(token);
+//        } catch (Exception e) {
+//            deptId = null;
+//        }
+//        return deptId;
+//    }
+//
+//    /**
+//     * 从请求中获取用户id
+//     *
+//     * @param request
+//     * @return 用户id
+//     */
+//    public static String getUserIdFromRequest(HttpServletRequest request) {
+//        String userId;
+//        try {
+//            String token = getToken(request);
+//            userId = getUserIdFromToken(token);
+//        } catch (Exception e) {
+//            userId = null;
+//        }
+//        return userId;
+//    }
+//
+//    /**
+//     * 从令牌中获取部门id
+//     *
+//     * @return
+//     */
+//    public static String getDeptIdFromToken(String token) {
+//        String deptId = null;
+//        try {
+//            Claims claims = getClaimsFromToken(token);
+//            deptId = (String) claims.get(DEPTID);
+//        } catch (Exception e) {
+//            deptId = null;
+//        }
+//        return deptId;
+//    }
+//
+//
+//    /**
+//     * 从令牌中获取用户id
+//     *
+//     * @return
+//     */
+//    public static String getUserIdFromToken(String token) {
+//        String userId = null;
+//        try {
+//            Claims claims = getClaimsFromToken(token);
+//            userId = (String) claims.get(USERID);
+//        } catch (Exception e) {
+//            userId = null;
+//        }
+//        return userId;
+//    }
+//
+//}

+ 153 - 153
src/main/java/com/ydtech/security/utils/SecurityUtils.java

@@ -1,153 +1,153 @@
-package com.ydtech.security.utils;
-
-import com.ydtech.security.JwtAuthenticatioToken;
-import com.ydtech.security.JwtUserDetails;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.authentication.AnonymousAuthenticationToken;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
-
-import javax.servlet.http.HttpServletRequest;
-
-
-/**
- * Security相关操作
- *
- * @author Louis
- * @date Jun 29, 2019
- */
-public class SecurityUtils {
-
-    static Logger logger = LoggerFactory.getLogger(SecurityUtils.class);
-
-    /**
-     * 系统登录认证
-     *
-     * @param request
-     * @param username
-     * @param password
-     * @param authenticationManager
-     * @return
-     */
-    public static JwtAuthenticatioToken login(HttpServletRequest request, String username, String password, AuthenticationManager authenticationManager) {
-        JwtAuthenticatioToken token = new JwtAuthenticatioToken(username, password);
-        token.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
-        // 执行登录认证过程
-        Authentication authentication = authenticationManager.authenticate(token);
-        // 认证成功存储认证信息到上下文
-        SecurityContextHolder.getContext().setAuthentication(authentication);
-        // 生成令牌并返回给客户端
-        token.setToken(JwtTokenUtils.generateToken(authentication));
-        return token;
-    }
-
-    /**
-     * 获取令牌进行认证
-     *
-     * @param request
-     */
-    public static void checkAuthentication(HttpServletRequest request) {
-        // 获取令牌并根据令牌获取登录认证信息
-        Authentication authentication = JwtTokenUtils.getAuthenticationeFromToken(request);
-        // 设置登录认证信息到上下文
-        SecurityContextHolder.getContext().setAuthentication(authentication);
-    }
-
-    /**
-     * 获取当前用户名
-     *
-     * @return
-     */
-    public static String getUsername() {
-        String username = null;
-        Authentication authentication = getAuthentication();
-        if (authentication != null) {
-            Object principal = authentication.getPrincipal();
-            if (principal != null && principal instanceof UserDetails) {
-                username = ((UserDetails) principal).getUsername();
-            }
-        }
-        return username;
-    }
-
-    /**
-     * 获取用户名
-     *
-     * @return
-     */
-    public static String getUsername(Authentication authentication) {
-        String username = null;
-        if (authentication != null) {
-            Object principal = authentication.getPrincipal();
-            if (principal != null && principal instanceof UserDetails) {
-                username = ((UserDetails) principal).getUsername();
-            }
-        }
-        return username;
-    }
-
-    /**
-     * 获取当前登录信息
-     *
-     * @return
-     */
-    public static Authentication getAuthentication() {
-        if (SecurityContextHolder.getContext() == null) {
-            return null;
-        }
-        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-        return authentication;
-    }
-
-    public static String getByUsername() {
-        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-
-        String username = null;
-        if (authentication != null) {
-            if (!(authentication instanceof AnonymousAuthenticationToken)) {
-                username = authentication.getName();
-            }
-        }
-        return username;
-    }
-
-    /**
-     * 获取当前部门ID
-     *
-     * @return
-     */
-    public static String getDeptId() {
-        String deptId = null;
-        Authentication authentication = getAuthentication();
-        if (authentication != null) {
-            Object principal = authentication.getPrincipal();
-            if (principal != null && principal instanceof UserDetails) {
-                deptId = ((JwtUserDetails) principal).getDeptId();
-            }
-        }
-        return deptId;
-    }
-
-    /**
-     * 获取当前用户ID
-     *
-     * @return
-     */
-    public static String getUserId() {
-        String userId = null;
-        Authentication authentication = getAuthentication();
-        if (authentication != null) {
-            Object principal = authentication.getPrincipal();
-            if (principal != null && principal instanceof UserDetails) {
-                userId = ((JwtUserDetails) principal).getUserId();
-            }
-        }
-        return userId;
-    }
-
-
-}
+//package com.ydtech.security.utils;
+//
+//import com.ydtech.security.JwtAuthenticatioToken;
+//import com.ydtech.security.JwtUserDetails;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.security.authentication.AnonymousAuthenticationToken;
+//import org.springframework.security.authentication.AuthenticationManager;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.core.context.SecurityContextHolder;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
+//
+//import javax.servlet.http.HttpServletRequest;
+//
+//
+///**
+// * Security相关操作
+// *
+// * @author Louis
+// * @date Jun 29, 2019
+// */
+//public class SecurityUtils {
+//
+//    static Logger logger = LoggerFactory.getLogger(SecurityUtils.class);
+//
+//    /**
+//     * 系统登录认证
+//     *
+//     * @param request
+//     * @param username
+//     * @param password
+//     * @param authenticationManager
+//     * @return
+//     */
+//    public static JwtAuthenticatioToken login(HttpServletRequest request, String username, String password, AuthenticationManager authenticationManager) {
+//        JwtAuthenticatioToken token = new JwtAuthenticatioToken(username, password);
+//        token.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
+//        // 执行登录认证过程
+//        Authentication authentication = authenticationManager.authenticate(token);
+//        // 认证成功存储认证信息到上下文
+//        SecurityContextHolder.getContext().setAuthentication(authentication);
+//        // 生成令牌并返回给客户端
+//        token.setToken(JwtTokenUtils.generateToken(authentication));
+//        return token;
+//    }
+//
+//    /**
+//     * 获取令牌进行认证
+//     *
+//     * @param request
+//     */
+//    public static void checkAuthentication(HttpServletRequest request) {
+//        // 获取令牌并根据令牌获取登录认证信息
+//        Authentication authentication = JwtTokenUtils.getAuthenticationeFromToken(request);
+//        // 设置登录认证信息到上下文
+//        SecurityContextHolder.getContext().setAuthentication(authentication);
+//    }
+//
+//    /**
+//     * 获取当前用户名
+//     *
+//     * @return
+//     */
+//    public static String getUsername() {
+//        String username = null;
+//        Authentication authentication = getAuthentication();
+//        if (authentication != null) {
+//            Object principal = authentication.getPrincipal();
+//            if (principal != null && principal instanceof UserDetails) {
+//                username = ((UserDetails) principal).getUsername();
+//            }
+//        }
+//        return username;
+//    }
+//
+//    /**
+//     * 获取用户名
+//     *
+//     * @return
+//     */
+//    public static String getUsername(Authentication authentication) {
+//        String username = null;
+//        if (authentication != null) {
+//            Object principal = authentication.getPrincipal();
+//            if (principal != null && principal instanceof UserDetails) {
+//                username = ((UserDetails) principal).getUsername();
+//            }
+//        }
+//        return username;
+//    }
+//
+//    /**
+//     * 获取当前登录信息
+//     *
+//     * @return
+//     */
+//    public static Authentication getAuthentication() {
+//        if (SecurityContextHolder.getContext() == null) {
+//            return null;
+//        }
+//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+//        return authentication;
+//    }
+//
+//    public static String getByUsername() {
+//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+//
+//        String username = null;
+//        if (authentication != null) {
+//            if (!(authentication instanceof AnonymousAuthenticationToken)) {
+//                username = authentication.getName();
+//            }
+//        }
+//        return username;
+//    }
+//
+//    /**
+//     * 获取当前部门ID
+//     *
+//     * @return
+//     */
+//    public static String getDeptId() {
+//        String deptId = null;
+//        Authentication authentication = getAuthentication();
+//        if (authentication != null) {
+//            Object principal = authentication.getPrincipal();
+//            if (principal != null && principal instanceof UserDetails) {
+//                deptId = ((JwtUserDetails) principal).getDeptId();
+//            }
+//        }
+//        return deptId;
+//    }
+//
+//    /**
+//     * 获取当前用户ID
+//     *
+//     * @return
+//     */
+//    public static String getUserId() {
+//        String userId = null;
+//        Authentication authentication = getAuthentication();
+//        if (authentication != null) {
+//            Object principal = authentication.getPrincipal();
+//            if (principal != null && principal instanceof UserDetails) {
+//                userId = ((JwtUserDetails) principal).getUserId();
+//            }
+//        }
+//        return userId;
+//    }
+//
+//
+//}

+ 1 - 5
src/main/resources/application-prod.yml

@@ -113,11 +113,7 @@ rb:
   quote:
     url: http://172.24.144.213:8088/rb/bfjs
 resp_json: '{"status":"Z00001","msg":"success","data":{"invoiceType":[],"payWayList":[{"payWayCode":"Z000005"}],"switchList":[{"cityName":null,"insurerId":null,"configCode":"Z00002","configValue":"ON","remark":"��Ҫ����ǩ��"},{"cityName":null,"insurerId":null,"configCode":"Z00009","configValue":"ON","remark":"��Ҫǰ���ύ��ת����̨֧��"},{"cityName":null,"insurerId":null,"configCode":"Z00007","configValue":"ON","remark":"��Ҫ���ó���ȷ��"},{"cityName":null,"insurerId":null,"configCode":"Z00001","configValue":"ON","remark":"��Ҫ���Ͷ���(�ֻ�ʵ����֤)"}]},"insurerId":"000108","baseParam":{"requestNo":"baodafang-00197e79fcc-f39c-4c54-86fc-a88668b0647e"},"success":true}'
-server:
-  servlet:
-    encoding:
-      charset: UTF-8
-      force: true
+
 spring:
   datasource:
     driver-class-name: com.p6spy.engine.spy.P6SpyDriver

+ 0 - 5
src/main/resources/application-test.yml

@@ -141,11 +141,6 @@ rb:
     url: http://47.92.254.66:8088/rb/bfjs
 
 resp_json: '{"code":200,"msg":null,"data":{"busUniqueId":"P_YBX_TESTT0NukiEN02OGDABB","total":3518.79,"insureId":null,"businessPolicy":{"specialTermItems":null,"coverages":null,"applicationNo":"53201093900246326035"},"trafficPolicy":{"specialTermItems":null,"coverages":null,"applicationNo":"53201093900246326036"},"propertyPolicies":null,"casualtyPolicies":null}}'
-server:
-  servlet:
-    encoding:
-      charset: UTF-8
-      force: true
 
 
 spring:

+ 29 - 0
src/main/resources/application.yml

@@ -1,8 +1,16 @@
+server:
+  servlet:
+    encoding:
+      charset: UTF-8
+      force: true
+  port: 9001
+
 spring:
   profiles:
       active: dev
 
 
+
 # 日志配置
 logging:
   path: ./logs
@@ -12,3 +20,24 @@ logging:
     # 设置 MyBatis 执行 sql 时打印具体的 Sql 语句
     com.hahashujia.logback: DEBUG
     org.mybatis: DEBUG
+
+
+
+############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
+sa-token:
+  # token前缀
+  token-prefix: Bearer
+  # token 名称(同时也是 cookie 名称)
+  token-name: Authorization
+  # token 有效期(单位:秒) 默认30天,-1 代表永久有效
+  timeout: 2592000
+  # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
+  active-timeout: -1
+  # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
+  is-concurrent: true
+  # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
+  is-share: true
+  # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
+  token-style: uuid
+  # 是否输出操作日志
+  is-log: true

BIN
src/main/resources/template/social_model.xls


BIN
src/main/resources/template/wage_model_A.xls


BIN
src/main/resources/template/wage_model_B.xls