【发布时间】:2014-05-14 11:15:09
【问题描述】:
我有一个独立的 Spring Boot 应用程序,其模板位于 /src/main/resources/templates 中,静态内容位于 /src/main/resources/static 中。我希望在身份验证之前可以访问静态内容,因此 CSS 也会加载到登录页面上。现在它只在身份验证后加载。我的安全配置如下所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger logger = Logger.getLogger(SecurityConfig.class);
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
try {
auth.inMemoryAuthentication()
...
} catch (Exception e) {
logger.error(e);
}
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.formLogin()
.defaultSuccessUrl("/projects", true)
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
.permitAll()
.and()
.authorizeRequests()
.antMatchers("/static/**").permitAll()
.anyRequest().authenticated();
}
}
【问题讨论】:
标签: spring spring-boot