我希望过滤以“/api/**”开头端点URL,但customJwtAuthenticationFilter会过滤所有其他URL。
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/users","/api/users").authenticated()
.anyRequest().permitAll()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().exceptionHandling().accessDeniedPage("/403").authenticationEntryPoint(jwtAuthenticationEntryPoint).and().
formLogin()
.loginPage("/login")
.defaultSuccessUrl("/users")
.failureUrl("/login?error=true")
.permitAll()
.and()
.logout().logoutSuccessUrl("/").permitAll()
.and().addFilterBefore(customJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
}
好心帮忙?
提前致谢
1条答案
按热度按时间jv2fixgn1#
如果您只想筛选路径为/api/**url,则可以使用类AbstractAuthenticationProcessingFilter来扩展类CustomJwtAuthenticationFilter并且可以使用类RequestMatcher跳过该url路径例如
并且对于类RequestMatcher,