除了模式之外,如何忽略Spring Security配置

Dav*_*dda 4 spring-security url-mapping

我有一个rest webservice配置为spring boot应用程序.我所有的其他网址都有一个基本路径"/ api/...".我也在为我的应用程序提供静态内容.我只需要为Web服务配置安全性,即以"/ api/..."开头的URL,但是给其他静态内容不应用安全性.

我只看到了通过以下方式过滤一些网址模式的示例:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/resources/*");
}
Run Code Online (Sandbox Code Playgroud)

但不是......

hol*_*s83 7

使用类的antMatcher方法HttpSecurity:

@Configuration
@EnableWebSecurity
public class MySecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/api/**");
        // add security constraints for /api/... here
    }

    /* rest of config */
}
Run Code Online (Sandbox Code Playgroud)

  • @user6708151 一个星号=目录/一级的所有文件,两个星号=包括子目录/所有级别。 (3认同)