Commit 543d7275b08f8ad7bc1f5eb1c0b64b658bf002a7
1 parent
ecda40d3
fix:【ai 大模型】兼容 mcp server 关闭的情况
Showing
1 changed file
with
7 additions
and
3 deletions
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -8,6 +8,8 @@ import org.springframework.context.annotation.Configuration; |
| 8 | 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 9 | 9 | import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; |
| 10 | 10 | |
| 11 | +import java.util.Optional; | |
| 12 | + | |
| 11 | 13 | /** |
| 12 | 14 | * AI 模块的 Security 配置 |
| 13 | 15 | */ |
| ... | ... | @@ -15,7 +17,7 @@ import org.springframework.security.config.annotation.web.configurers.AuthorizeH |
| 15 | 17 | public class SecurityConfiguration { |
| 16 | 18 | |
| 17 | 19 | @Resource |
| 18 | - private McpServerProperties serverProperties; | |
| 20 | + private Optional<McpServerProperties> serverProperties; | |
| 19 | 21 | |
| 20 | 22 | @Bean("aiAuthorizeRequestsCustomizer") |
| 21 | 23 | public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { |
| ... | ... | @@ -24,8 +26,10 @@ public class SecurityConfiguration { |
| 24 | 26 | @Override |
| 25 | 27 | public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) { |
| 26 | 28 | // MCP Server |
| 27 | - registry.requestMatchers(serverProperties.getSseEndpoint()).permitAll(); | |
| 28 | - registry.requestMatchers(serverProperties.getSseMessageEndpoint()).permitAll(); | |
| 29 | + serverProperties.ifPresent(properties -> { | |
| 30 | + registry.requestMatchers(properties.getSseEndpoint()).permitAll(); | |
| 31 | + registry.requestMatchers(properties.getSseMessageEndpoint()).permitAll(); | |
| 32 | + }); | |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | }; | ... | ... |