chore(swagger): 移除Swagger相关配置和依赖
This commit is contained in:
+5
-3
@@ -47,8 +47,10 @@ public class BootApplication {
|
|||||||
env.getProperty("config.servlet.context-path");
|
env.getProperty("config.servlet.context-path");
|
||||||
log.info(
|
log.info(
|
||||||
"\n----------------------------------------------------------\n\t" +
|
"\n----------------------------------------------------------\n\t" +
|
||||||
"Application is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
|
"Application is running! Access URLs:\n\t" +
|
||||||
"External: \thttp://" + ip + ":" + port + path + "/\n\t" + "Swagger文档: \thttp://" + ip + ":" + port +
|
"Local: \t\thttp://localhost:" + port + path + "/\n\t" +
|
||||||
path + "/doc.html\n" + "----------------------------------------------------------");
|
"External: \thttp://" + ip + ":" + port + path + "/\n\t"
|
||||||
|
// + "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n"
|
||||||
|
+ "----------------------------------------------------------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+48
-48
@@ -1,48 +1,48 @@
|
|||||||
/*
|
///*
|
||||||
* Copyright 2021-2025 Odboy
|
// * Copyright 2021-2025 Odboy
|
||||||
*
|
// *
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
// * You may obtain a copy of the License at
|
||||||
*
|
// *
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
// * limitations under the License.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package cn.odboy.framework.doc;
|
//package cn.odboy.framework.doc;
|
||||||
|
//
|
||||||
import cn.odboy.framework.properties.AppProperties;
|
//import cn.odboy.framework.properties.AppProperties;
|
||||||
import io.swagger.v3.oas.models.Components;
|
//import io.swagger.v3.oas.models.Components;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
//import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.info.Info;
|
//import io.swagger.v3.oas.models.info.Info;
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
//import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
//import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
//import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* api页面 /doc.html
|
// * api页面 /doc.html
|
||||||
*/
|
// */
|
||||||
@Configuration
|
//@Configuration
|
||||||
public class SwaggerConfig {
|
//public class SwaggerConfig {
|
||||||
@Autowired
|
// @Autowired
|
||||||
private AppProperties properties;
|
// private AppProperties properties;
|
||||||
|
//
|
||||||
@Bean
|
// @Bean
|
||||||
public OpenAPI customOpenAPI() {
|
// public OpenAPI customOpenAPI() {
|
||||||
// 添加开关控制
|
// // 添加开关控制
|
||||||
if (!properties.getSwagger().getEnabled()) {
|
// if (!properties.getSwagger().getEnabled()) {
|
||||||
return new OpenAPI();
|
// return new OpenAPI();
|
||||||
}
|
// }
|
||||||
return new OpenAPI().components(new Components().addSecuritySchemes("Authorization",
|
// return new OpenAPI().components(new Components().addSecuritySchemes("Authorization",
|
||||||
new SecurityScheme().name("Authorization").type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)))
|
// new SecurityScheme().name("Authorization").type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)))
|
||||||
.info(new Info().title("CuteJava 接口文档").version("1.4.1").description("一个简单且易上手的自动化运维平台"))
|
// .info(new Info().title("CuteJava 接口文档").version("1.4.1").description("一个简单且易上手的自动化运维平台"))
|
||||||
.addSecurityItem(new SecurityRequirement().addList("Authorization"));
|
// .addSecurityItem(new SecurityRequirement().addList("Authorization"));
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
+19
-44
@@ -81,65 +81,40 @@ public class SpringSecurityConfig {
|
|||||||
|
|
||||||
return httpSecurity
|
return httpSecurity
|
||||||
// 禁用 CSRF
|
// 禁用 CSRF
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable).addFilter(corsFilter).addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class)
|
||||||
.addFilter(corsFilter)
|
|
||||||
.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class)
|
|
||||||
// 授权异常
|
// 授权异常
|
||||||
.exceptionHandling(exceptionHandling -> exceptionHandling
|
.exceptionHandling(
|
||||||
.authenticationEntryPoint(authenticationErrorHandler)
|
exceptionHandling -> exceptionHandling.authenticationEntryPoint(authenticationErrorHandler).accessDeniedHandler(jwtAccessDeniedHandler))
|
||||||
.accessDeniedHandler(jwtAccessDeniedHandler))
|
|
||||||
// 防止iframe 造成跨域
|
// 防止iframe 造成跨域
|
||||||
.headers(headers -> headers
|
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
|
||||||
.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable))
|
|
||||||
// 不创建会话
|
// 不创建会话
|
||||||
.sessionManagement(sessionManagement -> sessionManagement
|
.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
||||||
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
|
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
|
||||||
// 静态资源等等
|
// 静态资源等等
|
||||||
.requestMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/websocket/**")
|
.requestMatchers(HttpMethod.GET, "*.html", "*.css", "*.js", "/websocket/**").permitAll()
|
||||||
.permitAll()
|
// // Knife4j 和 OpenAPI 相关路径
|
||||||
// swagger 文档
|
// .requestMatchers("/doc.html", "/webjars/**", "/v3/api-docs", "/v3/api-docs/**", "/swagger-resources", "/swagger-resources/**",
|
||||||
.requestMatchers("/swagger-ui.html")
|
// "/configuration/ui", "/configuration/security").permitAll()
|
||||||
.permitAll()
|
|
||||||
.requestMatchers("/swagger-resources/**")
|
|
||||||
.permitAll()
|
|
||||||
.requestMatchers("/webjars/**")
|
|
||||||
.permitAll()
|
|
||||||
.requestMatchers("/*/api-docs")
|
|
||||||
.permitAll()
|
|
||||||
// 文件
|
// 文件
|
||||||
.requestMatchers("/avatar/**")
|
.requestMatchers("/avatar/**").permitAll().requestMatchers("/file/**").permitAll()
|
||||||
.permitAll()
|
|
||||||
.requestMatchers("/file/**")
|
|
||||||
.permitAll()
|
|
||||||
// 阿里巴巴 druid
|
// 阿里巴巴 druid
|
||||||
.requestMatchers("/druid/**")
|
.requestMatchers("/druid/**").permitAll()
|
||||||
.permitAll()
|
|
||||||
// 放行OPTIONS请求
|
// 放行OPTIONS请求
|
||||||
.requestMatchers(HttpMethod.OPTIONS, "/**")
|
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||||
.permitAll()
|
|
||||||
// 自定义匿名访问所有url放行:允许匿名和带Token访问,细腻化到每个 Request 类型
|
// 自定义匿名访问所有url放行:允许匿名和带Token访问,细腻化到每个 Request 类型
|
||||||
// GET
|
// GET
|
||||||
.requestMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0]))
|
.requestMatchers(HttpMethod.GET, anonymousUrls.get(RequestMethodEnum.GET.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// POST
|
// POST
|
||||||
.requestMatchers(HttpMethod.POST, anonymousUrls.get(RequestMethodEnum.POST.getType()).toArray(new String[0]))
|
.requestMatchers(HttpMethod.POST, anonymousUrls.get(RequestMethodEnum.POST.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// PUT
|
// PUT
|
||||||
.requestMatchers(HttpMethod.PUT, anonymousUrls.get(RequestMethodEnum.PUT.getType()).toArray(new String[0]))
|
.requestMatchers(HttpMethod.PUT, anonymousUrls.get(RequestMethodEnum.PUT.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// PATCH
|
// PATCH
|
||||||
.requestMatchers(HttpMethod.PATCH, anonymousUrls.get(RequestMethodEnum.PATCH.getType()).toArray(new String[0]))
|
.requestMatchers(HttpMethod.PATCH, anonymousUrls.get(RequestMethodEnum.PATCH.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// DELETE
|
// DELETE
|
||||||
.requestMatchers(HttpMethod.DELETE, anonymousUrls.get(RequestMethodEnum.DELETE.getType()).toArray(new String[0]))
|
.requestMatchers(HttpMethod.DELETE, anonymousUrls.get(RequestMethodEnum.DELETE.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// 所有类型的接口都放行
|
// 所有类型的接口都放行
|
||||||
.requestMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0]))
|
.requestMatchers(anonymousUrls.get(RequestMethodEnum.ALL.getType()).toArray(new String[0])).permitAll()
|
||||||
.permitAll()
|
|
||||||
// 所有请求都需要认证
|
// 所有请求都需要认证
|
||||||
.anyRequest()
|
.anyRequest().authenticated()).build();
|
||||||
.authenticated())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,12 +161,12 @@
|
|||||||
<version>3.9.1</version>
|
<version>3.9.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger UI 相关 -->
|
<!-- Spring Boot 3 只支持OpenAPI3规范,暂时不接 -->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
<!-- <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>-->
|
||||||
<version>4.5.0</version>
|
<!-- <version>4.4.0</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user