Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erros ao configurar acesso

Ao fazer o exercício proposto na aula tive 2 problemas, as páginas não estavam mais carregando os resources e ao tentar cadastrar um novo produto eu recebia o seguinte erro: https://imgur.com/siP7Vbk.

Os resources consegui carregar ao implementar o método configure(WebSecurity) na classe SecurityConfiguration da seguinte maneira:

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

Porém, ainda não consegui resolver o problema do cadastro de produtos, alguém poderia me dar uma ajuda? Segue o link para o erro que encontro https://imgur.com/siP7Vbk e também o código da minha classe SecurityConfiguration:

package br.com.casadocodigo.loja.conf;

import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

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

        http.authorizeRequests()
            .antMatchers("/resources/**").permitAll()
            .antMatchers("/carrinho/**").permitAll()
            .antMatchers("/pagamento/**").permitAll()
            .antMatchers("/produtos/form").hasRole("ADMIN")
            .antMatchers(HttpMethod.POST, "/produtos").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/produtos").hasRole("ADMIN")
            .antMatchers("/produtos/**").permitAll()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated()
            .and().formLogin();

    }

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

}
1 resposta
solução!

Essa dúvida é respondida numa aula mais a frente. Quem estiver passando pela mesma coisa espere até a aula de ataque CSFR.