我有一个具有相同要求的应用程序,要解决此问题,我基本上将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
。对于所有其他请求,此配置无效。