有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpring安全性:为什么在配置中将JWT过滤器添加到UsernamePasswordAuthenticationFilter之前?

我正在使用SpringSecurity和jwt,但是在配置文件中有一些我不理解的东西(jwt的所有教程中都有相同的配置) 这就是为什么要在UsernamePasswordAuthenticationFilter之前添加自定义jwt过滤器,因为我已经在项目的某个地方有了一个基于用户名和密码的公共身份验证控制器,为什么不按其他顺序添加它呢

@Bean
    public JwtAuthTokenFilter authenticationJwtTokenFilter() {
        return new JwtAuthTokenFilter();
    }
@Override
    protected void configure(HttpSecurity http) throws Exception {

        http.cors().and().csrf().disable()
        .authorizeRequests()
        .antMatchers("/api/auth/**").permitAll()
        .anyRequest().authenticated()
        .and()
        .exceptionHandling().authenticationEntryPoint((AuthenticationEntryPoint) unauthorizedHandler)
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        http.addFilterBefore((Filter) authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);

    }
}

共 (0) 个答案