簡體   English   中英

允許 URL 中的語言參數(Spring Boot / Security)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM