Spring Security中的白名单多部分文件上载

Spring Security中的白名单多部分文件上载,spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,这是我关于stackoverflow的第一篇文章。请容忍我。我有一个问题,允许文件上传无需授权,因为这是一个注册过程的一部分。我已经在antMatchers.permitAll()中添加了上传路径,但是当我尝试上传时,Spring仍然会抛出一个未经授权的401路径。有人能帮我吗?我已经为此挣扎了一段时间了 这是我的安全配置 @Autowired private CustomUserDetailsService customUserDetailsService; @Autowired priva

这是我关于stackoverflow的第一篇文章。请容忍我。我有一个问题,允许文件上传无需授权,因为这是一个注册过程的一部分。我已经在antMatchers.permitAll()中添加了上传路径,但是当我尝试上传时,Spring仍然会抛出一个未经授权的401路径。有人能帮我吗?我已经为此挣扎了一段时间了

这是我的安全配置

@Autowired
private CustomUserDetailsService customUserDetailsService;

@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;

@Bean
public JwtAuthenticationFilter jwtAuthenticationFilter() {
    return new JwtAuthenticationFilter();
}

@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder
            .userDetailsService(customUserDetailsService)
            .passwordEncoder(passwordEncoder());
}

@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .cors()
            .and()
            .csrf()
            .disable()
            .exceptionHandling()
            .authenticationEntryPoint(unauthorizedHandler)
            .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .authorizeRequests()
            .antMatchers("/api/v0/business-registration", "/api/v0/business-registration/file","/api/v0/admin/register", "/api/v0/admin/login")
            .permitAll()
            .anyRequest()
            .authenticated();

    // Add our custom JWT security filter
    http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);

}

我能够解决这个问题。我在antMatchers中缺少了/*/**并且我的控制器有路径变量,这就是我得到401错误的原因。我能够解决这个问题。我在antMatchers中缺少了/*/**并且我的控制器有路径变量,这就是我得到401错误的原因。