Spring 安全配置拦截器 URL 句柄

Spring Security configuration interceptor URL handle

我的 Spring 启动应用程序的安全配置有问题。我想在 URL 中应用基本身份验证。我的应用程序的默认 URL 是 app/v1/items 我的 ap's secure URL 是 app/v1/secure/items.

对于给定的配置,基本身份验证不起作用,我可以从两个 URL 中获取项目。我无法配置 antMatchers.

如何处理?

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/**").permitAll()    
            .antMatchers("/secure").access("hasRole('USER')")
            .anyRequest().authenticated();
    http
        .httpBasic();
    http
        .csrf().disable();
}

请试试这个代码。

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
    .antMatchers("/app/v1/items/**").permitAll()
    .antMatchers("/app/v1/secure/items/**").hasAuthority("USER")
    .anyRequest().authenticated();
    http.httpBasic();
    http.csrf().disable();

}