Spring安全配置
@Bean
public SecurityWebFilterChain securityWebFilterChainBean(ServerHttpSecurity httpSecurity) {
httpSecurity.authorizeExchange()
.pathMatchers("/v2/api-docs").permitAll()
.pathMatchers("/configuration/ui").permitAll()
.pathMatchers("/swagger-resources/**").permitAll()
.pathMatchers("/configuration/security").permitAll()
.pathMatchers("/swagger-ui.html").permitAll()
.pathMatchers("/webjars/**").permitAll()
.pathMatchers("/v2/**").permitAll()
.anyExchange().authenticated();
return httpSecurity.build();
}
其他控制器
@RestController
public class MyController {
@PostMapping("myPath")
public MyResponse newLoansOffers(@RequestBody MyRequest request) {
return new MyResponse();
}
}
Spring fox配置:
@Bean
public Docket api() {
Class[] clazz = {AuthenticationPrincipal.class};
return new Docket(DocumentationType.SWAGGER_2)
.securitySchemes(Lists.newArrayList(apiKey()))
.select()
.paths(PathSelectors.any())
.build();
}
private ApiKey apiKey() {
return new ApiKey("xauth", "X-Auth-Token", "header");
}
出了什么问题?
我单击“授权”按钮:
然后输入有效值
但是当我从swagger ui发送myPath
请求时,没有X-Auth-Token
标头随请求一起传递。 :(
据我了解,springfox不会在摇动生成过程中“考虑” spring安全配置: