Explorar o código

解决盐值登录问题

fuyuchuan hai 3 semanas
pai
achega
e31ee99287

+ 17 - 16
flow-common/flow-common-oauth2-starter/src/main/java/com/flow/common/oauth2/configure/ResourceServerConfigure.java

@@ -29,26 +29,27 @@ public class ResourceServerConfigure extends ResourceServerConfigurerAdapter {
     @Override
     public void configure(HttpSecurity http) throws Exception {
         http
+                // 添加全局 CORS 配置
                 //.cors().configurationSource(corsConfigurationSource()).and()
-                //.cors().and()
+                .cors().and()
                 .csrf().disable()
 
                 // 跨域异常处理
-                // .exceptionHandling()
-                // .authenticationEntryPoint((request, response, authException) -> {
-                //     // 手动添加 CORS 头
-                //     response.setHeader("Access-Control-Allow-Origin", "*");
-                //     response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
-                //     response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
-                //
-                //     // 返回 JSON 格式的错误信息
-                //     response.setContentType("application/json;charset=UTF-8");
-                //     response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-                //     response.getWriter().write(
-                //             "{\"code\": 401, \"message\": \"Token 无效或已过期,请重新登录\"}"
-                //     );
-                // })
-                // .and()
+                .exceptionHandling()
+                .authenticationEntryPoint((request, response, authException) -> {
+                    // 手动添加 CORS 头
+                    response.setHeader("Access-Control-Allow-Origin", "*");
+                    response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
+                    response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
+
+                    // 返回 JSON 格式的错误信息
+                    response.setContentType("application/json;charset=UTF-8");
+                    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+                    response.getWriter().write(
+                            "{\"code\": 401, \"message\": \"Token 无效或已过期,请重新登录\"}"
+                    );
+                })
+                .and()
 
                 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                 .and()

+ 1 - 1
flow-oauth/flow-oauth-api/src/main/java/com/flow/service/AuthService.java

@@ -23,7 +23,7 @@ public interface AuthService{
     List<Route> buildMenu(List<Menu> menus);
 
     // salt登录
-    AccessToken saltLogin(String salt);
+    AccessToken saltLogin(SaltLogin salt);
 
     // 获取时间戳
     Long getTimeStamp();

+ 10 - 2
flow-oauth/flow-oauth-biz/src/main/java/com/flow/service/impl/AuthServiceImpl.java

@@ -88,12 +88,20 @@ public class AuthServiceImpl implements AuthService {
 
     // 盐值登录
     @Override
-    public AccessToken saltLogin(String salt) {
+    public AccessToken saltLogin(SaltLogin salt) {
+        log.info("盐值登录");
+        if (StringUtils.isBlank(salt.getSalt())) {
+            throw new BaseException("盐值不能为空");
+        }
+        log.info("盐值: " + salt.getSalt());
+
+        String saltData = salt.getSalt();
+
         AccessToken accessToken = null;
         long now = System.currentTimeMillis();
         String decryptedData = null;
         try {
-            decryptedData = decrypt(salt);
+            decryptedData = decrypt(saltData);
         } catch (Exception e) {
             throw new BaseException("盐值解析异常,请联系管理员" + e.getMessage());
         }

+ 2 - 5
flow-oauth/flow-oauth-controller/src/main/java/com/flow/controller/AuthController.java

@@ -2,10 +2,7 @@ package com.flow.controller;
 
 import com.flow.common.core.model.Result;
 import com.flow.entity.User;
-import com.flow.model.AccessToken;
-import com.flow.model.ImageCode;
-import com.flow.model.LoginForm;
-import com.flow.model.Permission;
+import com.flow.model.*;
 import com.flow.service.AuthService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -28,7 +25,7 @@ public class AuthController {
     // 盐值登录
     //@CrossOrigin(origins = "http://192.168.10.140:9089")
     @PostMapping("/saltLogin")
-    public Result<AccessToken> saltLogin(@RequestParam String salt) {
+    public Result<AccessToken> saltLogin(@RequestBody SaltLogin salt) {
         return Result.success(authService.saltLogin(salt));
     }
 

+ 14 - 0
flow-oauth/flow-oauth-entity/src/main/java/com/flow/model/SaltLogin.java

@@ -0,0 +1,14 @@
+package com.flow.model;
+
+import lombok.Data;
+
+/**
+ *
+ * @author fyc
+ * @email yuchuan.fu@chinausky.com
+ * @date 2025/4/27
+ */
+@Data
+public class SaltLogin {
+    String salt;
+}

+ 0 - 3
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/FlowDefine.java

@@ -60,9 +60,6 @@ public class FlowDefine extends BaseEntity {
     @TableField(exist = false)
     private Integer suspend;
 
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime createTime;
-
     public FlowDefine(ProcessDefinition processDefinition) {
         this.defineId = processDefinition.getId();
         this.key = processDefinition.getKey();