我已经为此做了一些投资,但我什么也做不到,以下是我目前的情况:
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
招摇过市配置:
@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());
}
. . .
自己生成的ssl证书启动并运行,生成用于填充“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条答案
按热度按时间ff29svar1#
我不知道为什么-1关于我的问题,答案就在那里。
对我有效的是更改此项的依赖项: