доступ к статическому контенту в защищенном приложении Spring Boot
У меня есть отдельное приложение 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();
}
}