Swagger-ui + Spring 安全 => localhost:8080/swagger-ui.html <= 未找到 404
Swagger-ui + Spring Security => localhost:8080/swagger-ui.html <= Not Found 404
我一直在为此做一些投资,但一无所获,这是我目前的情况:
1.我正在使用 Spring Boot + Spring Security,这是我的配置:
。
.
.
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final PasswordEncoder passwordEncoder;
@Autowired
private UserRepository userRepository;
@Autowired
public WebSecurityConfig(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
};
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests(authorize -> {
authorize
.antMatchers("/h2-console/**").permitAll() //do not use in production!
.antMatchers("/", "/webjars/**", "/login/**", "/resources/**", "/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**").permitAll();
} )
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.and().csrf().ignoringAntMatchers("/h2-console/**", "/api/**");
http.headers().frameOptions().sameOrigin();
};
application.properties:
server.ssl.key-store: classpath:springboot.p12
server.ssl.key-store-password:password
server.ssl.key-store-type: pkcs12
server.ssl.key-alias: springboot
server.ssl.key-password: password
Swagger 配置:
@Configuration
@EnableSwagger2
public class SwaggerConfig { //} extends WebMvcConfigurationSupport {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("enide.logicon.backend.controllers"))
.paths(PathSelectors.any())
.build()
.apiInfo(metaData());
}
。
.
.
- Own-generated SSL Certificate up&运行, generated to fill the
“editor.swagger.io”https 请求需要 & 使基本身份验证更安全。
。
.
.
- 为什么找不到 SWAGGER-UI.HTML 页面?在这里你有我的依赖项:
。
.
.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
。
.
.
**
- 还允许所有路径无需登录
antMatchers("/**").permitAll()
这允许“editor.swagger.io”
从 API 但不是 /swagger-ui.html 检索数据,有什么想法吗?
**
不知道为什么我的问题是 -1,答案就在那里。
对我有用的是改变这个的依赖关系:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
我一直在为此做一些投资,但一无所获,这是我目前的情况:
1.我正在使用 Spring Boot + Spring Security,这是我的配置:
。 . .
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final PasswordEncoder passwordEncoder;
@Autowired
private UserRepository userRepository;
@Autowired
public WebSecurityConfig(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
};
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests(authorize -> {
authorize
.antMatchers("/h2-console/**").permitAll() //do not use in production!
.antMatchers("/", "/webjars/**", "/login/**", "/resources/**", "/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**").permitAll();
} )
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.and().csrf().ignoringAntMatchers("/h2-console/**", "/api/**");
http.headers().frameOptions().sameOrigin();
};
application.properties:
server.ssl.key-store: classpath:springboot.p12
server.ssl.key-store-password:password
server.ssl.key-store-type: pkcs12
server.ssl.key-alias: springboot
server.ssl.key-password: password
Swagger 配置:
@Configuration
@EnableSwagger2
public class SwaggerConfig { //} extends WebMvcConfigurationSupport {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("enide.logicon.backend.controllers"))
.paths(PathSelectors.any())
.build()
.apiInfo(metaData());
}
。 . .
- Own-generated SSL Certificate up&运行, generated to fill the “editor.swagger.io”https 请求需要 & 使基本身份验证更安全。
。 . .
- 为什么找不到 SWAGGER-UI.HTML 页面?在这里你有我的依赖项:
。 . .
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
。 . .
**
- 还允许所有路径无需登录
antMatchers("/**").permitAll()
这允许“editor.swagger.io” 从 API 但不是 /swagger-ui.html 检索数据,有什么想法吗?
**
不知道为什么我的问题是 -1,答案就在那里。
对我有用的是改变这个的依赖关系:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>