[英]How to specific different authentications in different urls in springboot in my situation?
我有一些服務訪問的后端網址,以及網站登錄訪問的前端網址,我的情況是:
我不想啟動兩個不同的 springboot 進程。
我找到了這個答案,但 springboot 不允許禁用特定 url 的客戶端身份驗證:
server:
ssl:
client-auth: need
這個答案可能有幫助,但我不知道如何在我的情況下混合使用兩種身份驗證方法。
請幫忙。
對於 Spring-Boot 2.7.0,這應該像定義 SecurityFilterChain 的 2 個實例一樣簡單,理想情況下您希望其中一個成為默認值(刪除 http.mvcMatcher 行)並提供另一個 @Order(1)。 如果是較舊的實現,我不是 100% 確定,為了進一步研究,您可能會找到更好的結果,尋找一種方法來支持取決於端點的 2 登錄方法,而不是研究如何禁用某些元素。
@Configuration
public class WebSecurityConfig
{
@Bean
public SecurityFilterChain frontendFilterChain(HttpSecurity http) throws Exception
{
//@formatter:on
http
.mvcMatcher("/frontend/**")
.authorizeRequests(auth -> auth.anyRequest().permitAll());
//Extend with needed authentication
//@formatter:off
return http.build();
}
@Bean
@Order(1)
public SecurityFilterChain backendFilterChain(HttpSecurity http) throws Exception
{
//@formatter:on
http
.mvcMatcher("/backend/**")
.authorizeRequests(auth -> auth.anyRequest().permitAll());
//Extend with needed authentication
//@formatter:off
return http.build();
}
}
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.