1
resposta

Spring Security e /resources/**

Caros,

Após habilitar o Spring Security os arquivos da pasta /resource ficaram inacessíveis. Foi necessário adicionar o diretório com permitAll():

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
            .antMatchers("/produtos/form").hasRole("ADMIN")
            .antMatchers("/carrinho").permitAll()
            .antMatchers(HttpMethod.POST, "/produtos").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/produtos").permitAll()

            .antMatchers(HttpMethod.GET, "/resources/**").permitAll()

            .antMatchers("/produtos/**").permitAll()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated()
            .and().formLogin();
    }

}

Está correto?

1 resposta

Olá Ythalo,

Uma outra forma de fazer isso é sobrescrevendo esse método:

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

[]s

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software