[英]httpBasic() .disable() is not working spring boot 2.6.12
我正在嘗試創建一個資源服務器 oauth2 令牌驗證,它按預期工作,但我也默認啟用了 HTTP 基本功能,這不是預期的行為,因為我已將其配置為禁用:這是我的代碼:
@Configuration
@EnableWebSecurity
public class SecConfig{
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-uri}")
String introspectionUri;
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-client-id}")
String clientId;
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-client-secret}")
String clientSecret;
private static final String[] WHITE_LIST_URLS = {
"/v3/api-docs/**",
"/swagger-ui/**",
"/doc"
};
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.httpBasic()
.disable()
.authorizeHttpRequests((authorize) -> authorize
.antMatchers(WHITE_LIST_URLS).permitAll()
.anyRequest().authenticated()
)
.oauth2ResourceServer((oauth2) -> oauth2
.opaqueToken((opaque) -> opaque
.introspectionUri(this.introspectionUri)
.introspectionClientCredentials(this.clientId, this.clientSecret)
)
)
;
return http.build();
}
}
我也嘗試過使用下面的方法禁用自動配置,但沒有用,spring 啟動仍然自動配置它,即使我排除了它!!!
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class})
重要的是要提到我的應用程序非常簡單,僅使用 spring 數據和 spring 安全性和 openapi 來招搖!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.