您可以在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'的匿名访问才能工作。没有它,你不会有一个认证对象,访问仍然失败。您可以忽略所有内容,但是这样您也会丢失在请求中设置的安全标头。 –