1
resposta

Refused to apply style from 'http://localhost:8080/casadocodigo/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Pessoal, ao adicionar a tag <security> no home.jsp conforme o vídeo 5 da aula 4 me deparei com um problema no carregamento dos estilos quando tento acessar a home sem estar logado. Ao acessar a home sem logar anteriormente a página é carregada sem estilização CSS e aparece a mensagem de erro: "Refused to apply style from 'http://localhost:8080/casadocodigo/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled." Já realizei alguns testes mas não consegui arrumar. Alguém tem alguma ideia do que possa ser?

1 resposta

Olá Alex, tudo bem? Peço desculpas pela demora no retorno! Mas o problema é que subimos o SecurityConfiguration na inicialização da aplicação (root) e ai ele começa a bloquear todo o acesso que não é permitido, e usamos o seguinte código para acesso ao bootstrap:

<c:url value="/resources/css" var="cssPath"></c:url>
<link rel="stylesheet" href="${cssPath}/bootstrap.min.css">
<link rel="stylesheet" href="${cssPath}/bootstrap-theme.min.css">

Ele ele está bloqueando, para resolver esse problema, você pode ir na classe SecurityConfiguration e então adicionar outro antMatchers, agora permitindo todo o acesso a pasta resources, ficando como:

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").hasRole("ADMIN")
            .antMatchers("/resources/**").permitAll()
            .antMatchers("/produtos/**").permitAll()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated()
            .and().formLogin();
    }

Isso deve resolver o problema, espero ter ajudado!

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