您可以在WebSecurityConfigurerAdapter
中使用configure(WebSecurity web)
超載的方法,並執行以下操作;
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/services/rest/registerUser");
}
此外,如果你允許系統從您的REST API被放置在另一臺主機上訪問您的REST API,那麼你需要使用CORS標頭。
what is the best practice with securing rest services? I definitely don't want to let someone send data to database through rest services. So what is the best way to allow using services from inside of my app and restrict every other rest request?
最廣泛使用和安全的保護REST Apis的方法是使用OAuth2。您可以使用Spring Security OAuth2項目來實現此目的。
另一種方法是使用JWT令牌,這也可以使用Spring Security和一些代碼來實現。
您需要啓用'permitAll'的匿名訪問才能工作。沒有它,你不會有一個認證對象,訪問仍然失敗。您可以忽略所有內容,但是這樣您也會丟失在請求中設置的安全標頭。 –