我正在尝试访问“ src \ main \ resources \ static”文件夹中的内容,但在chrome的检查窗口中出现401错误。
在“静态”文件夹中,我有一个名为“资产”的子文件夹,其结构有点像这样。
assets/css/**
assets/js/**
assets/fonts/**
assets/image/**
assets/css/boostrap/**
这是我的WebMvcConfigurerAdapter
班
@Configuration
public class OAuthWebFormConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
registry.addViewController("/oauth/confirm_access").setViewName("authorize");
}
@Configuration
@Order(-20)
protected static class LoginConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationManager customAuthenticationManager;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().loginPage("/login").permitAll()
.and()
.requestMatchers()
.antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")//,"/resources/**", "/assets/**"
.and()
.authorizeRequests()
.anyRequest()
.authenticated();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(customAuthenticationManager);
}
}
}
答案 0 :(得分:1)
添加以下内容:
.antMatchers("/assets/**").permitAll()
因此,通过这种方式,您将允许所有与/ assets / **匹配的请求(因此,您需要的所有可能性)
希望这会有所帮助