refactor(api): 统一 API 接口前缀并优化登录认证
- 在 JsonAuthenticationFilter 中使用 startsWith 方法判断请求内容类型 - 更新 SpringSecurityConfig 中的 logoutUrl 为 /api/user/logout - 在 V1ChatController、V1DatasetController、V1ServerController 和 V1WorkflowController 中统一添加 /api 前缀
This commit is contained in:
parent
79ed8b3b9c
commit
426e57c5ac
@ -21,7 +21,7 @@ public class JsonAuthenticationFilter extends UsernamePasswordAuthenticationFilt
|
||||
if (!request.getMethod().equals("POST")) {
|
||||
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 {
|
||||
Map map = new ObjectMapper().readValue(request.getInputStream(), Map.class);
|
||||
String username = map.get("username").toString();
|
||||
|
@ -129,7 +129,7 @@ public class SpringSecurityConfig {
|
||||
.successHandler(customAuthenticationSuccessHandler)
|
||||
.failureHandler(customAuthenticationFailureHandler))
|
||||
.logout(logout -> logout
|
||||
.logoutUrl("/api/user/logout")
|
||||
.logoutUrl("/api/rest/user/logout")
|
||||
.logoutSuccessHandler((request, response, authentication) -> {}))
|
||||
// 添加自定义未授权和未登录结果返回
|
||||
.exceptionHandling(exception -> exception
|
||||
|
@ -21,7 +21,7 @@ import reactor.core.publisher.Mono;
|
||||
* @since 2025/3/25 10:48
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/v1/chat")
|
||||
@RequestMapping("/api/v1/chat")
|
||||
public class V1ChatController {
|
||||
|
||||
@Resource
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v1/dataset")
|
||||
@RequestMapping("/api/v1/dataset")
|
||||
public class V1DatasetController {
|
||||
@Resource
|
||||
private DifyDataset difyDataset;
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v1/server")
|
||||
@RequestMapping("/api/v1/server")
|
||||
public class V1ServerController {
|
||||
|
||||
@Resource
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v1/workflow")
|
||||
@RequestMapping("/api/v1/workflow")
|
||||
public class V1WorkflowController {
|
||||
|
||||
@Resource
|
||||
|
Loading…
Reference in New Issue
Block a user