我的spring安全应用程序不接受从资源文件夹访问“新上传的图像”

w7t8yxp5  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(143)

我有一个启用了安全性的spring启动应用程序。这是我的安全配置文件:

@Override
public void configure(WebSecurity web) throws Exception {
    web
       .ignoring()
           .antMatchers("/resources/**"); 
}

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity
        .csrf().disable()
        .cors()
            .and()
        .authorizeRequests()
            .and()
        .authorizeRequests()
            .antMatchers("/login", 
              "/api/user/register",
              "/api/password/forgot_password", 
              "/api/password/reset_password",
              "/resources/**", 
              "/api/event/",
              "/api/photography/files/**").permitAll()
            .antMatchers( "/assets/img/**").permitAll()
            .anyRequest().authenticated()
            .and()
        .exceptionHandling()
            .authenticationEntryPoint(jwtAuthenticationEntryPoint)
            .and()
        .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    httpSecurity
        .addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}

当我试图从 /resource/static/assets/img/.png 它起作用了。但仅适用于现有图像。当我运行应用程序,然后上传一个图像。我明白了 Unauthorized error 401 .

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题