它实际上按预期工作,这是由于您编写配置的方式。
@Override protected void configure(HttpSecurity http) throws Exception { http .addFilterBefore(authenticationTokenFilter, BasicAuthenticationFilter.class) .antMatcher("/*") .authenticationProvider(tokenAuthenticationProvider) .authorizeRequests() .anyRequest().authenticated(); }
这是您自己的配置,我还有一些额外的缩进。当你写一个 antMatcher 这意味着一切都在那之后 antMatcher 适用于那里写的路径/表达式(参见Javadoc) AntPathMatcher 。
antMatcher
AntPathMatcher
现在就像你写的那样 /* 这适用于 /reports 它不适用于 /reports/ (是的,最后一次 / 问题!)。
/*
/reports
/reports/
/
你可能打算写的是
@Override protected void configure(HttpSecurity http) throws Exception { http .addFilterBefore(authenticationTokenFilter, BasicAuthenticationFilter.class) .antMatcher("/**") .authenticationProvider(tokenAuthenticationProvider) .authorizeRequests() .anyRequest().authenticated(); }
请注意 /** 代替 /* 。然而,这基本上与遗漏相同 antMatcher 只是写作
/**
@Override protected void configure(HttpSecurity http) throws Exception { http .addFilterBefore(authenticationTokenFilter, BasicAuthenticationFilter.class) .authenticationProvider(tokenAuthenticationProvider) .authorizeRequests() .anyRequest().authenticated(); }