我有一个具有相同要求的应用程序,要解决此问题,我基本上将Spring Security限制为给定的ant match模式(使用
antMatcher),如下所示:
http.antMatcher("/api/**").authorizeRequests() // .anyRequest().authenticated() // .and() .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);你可以阅读以下内容:
http仅在与
/api/**授权
any request给
authenticated用户的ant模式匹配的请求上调用这些配置
and add filter authenticationTokenFilterBean() before UsernamePasswordAuthenticationFilter。对于所有其他请求,此配置无效。



