[英]Allow language parameter in URL (Spring Boot / Security)
親愛的社區,您好,
關於我的目標的詳細信息:
實際結果:
然后我添加了安全性:
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
// Deny All
.anyRequest().authenticated();
}
由於.anyRequest().authenticated()
根路徑上的請求/?lang=de
將觸發身份驗證。
我試過的:
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
// Trick to allow Internationalization
.antMatchers("/*").permitAll()
// Deny All
.anyRequest().authenticated();
}
我添加了.antMatchers("/*").permitAll()
,它可以工作,但它允許根路徑上有很多資源。 我的目標是僅允許/?lang=de
無需身份驗證。
有機會嗎?
我研究過但不滿意的資源:
親切的問候
歐騰摩騰
好吧,終於可以用了。
上面我告訴我對提到的 stackoverflow 鏈接感到不舒服,但它仍然有效。
我已經添加:
.regexMatchers("/.*lang=.*").permitAll()
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
.regexMatchers("/.*lang=.*").permitAll()
// Deny All
.anyRequest().authenticated();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.