refactor(api): 统一 API 接口前缀并优化登录认证

- 在 JsonAuthenticationFilter 中使用 startsWith 方法判断请求内容类型
- 更新 SpringSecurityConfig 中的 logoutUrl 为 /api/user/logout
- 在 V1ChatController、V1DatasetController、V1ServerController 和 V1WorkflowController 中统一添加 /api 前缀
This commit is contained in:
vertoryao 2025-05-05 01:48:22 +08:00
parent 79ed8b3b9c
commit 426e57c5ac
6 changed files with 6 additions and 6 deletions

View File

@ -21,7 +21,7 @@ public class JsonAuthenticationFilter extends UsernamePasswordAuthenticationFilt
if (!request.getMethod().equals("POST")) { if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
} }
if (request.getContentType().equals(MediaType.APPLICATION_JSON_VALUE)) { if (request.getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)) {
try { try {
Map map = new ObjectMapper().readValue(request.getInputStream(), Map.class); Map map = new ObjectMapper().readValue(request.getInputStream(), Map.class);
String username = map.get("username").toString(); String username = map.get("username").toString();

View File

@ -129,7 +129,7 @@ public class SpringSecurityConfig {
.successHandler(customAuthenticationSuccessHandler) .successHandler(customAuthenticationSuccessHandler)
.failureHandler(customAuthenticationFailureHandler)) .failureHandler(customAuthenticationFailureHandler))
.logout(logout -> logout .logout(logout -> logout
.logoutUrl("/api/user/logout") .logoutUrl("/api/rest/user/logout")
.logoutSuccessHandler((request, response, authentication) -> {})) .logoutSuccessHandler((request, response, authentication) -> {}))
// 添加自定义未授权和未登录结果返回 // 添加自定义未授权和未登录结果返回
.exceptionHandling(exception -> exception .exceptionHandling(exception -> exception

View File

@ -21,7 +21,7 @@ import reactor.core.publisher.Mono;
* @since 2025/3/25 10:48 * @since 2025/3/25 10:48
*/ */
@RestController @RestController
@RequestMapping("/v1/chat") @RequestMapping("/api/v1/chat")
public class V1ChatController { public class V1ChatController {
@Resource @Resource

View File

@ -10,7 +10,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping("/v1/dataset") @RequestMapping("/api/v1/dataset")
public class V1DatasetController { public class V1DatasetController {
@Resource @Resource
private DifyDataset difyDataset; private DifyDataset difyDataset;

View File

@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/v1/server") @RequestMapping("/api/v1/server")
public class V1ServerController { public class V1ServerController {
@Resource @Resource

View File

@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@RestController @RestController
@RequestMapping("/v1/workflow") @RequestMapping("/api/v1/workflow")
public class V1WorkflowController { public class V1WorkflowController {
@Resource @Resource