1
resposta

javax.el.PropertyNotFoundException: Property [username] not found on type [java.lang.String]

Quando tento acessar a pagina sem estar logado acontece esse erro:

org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property [username] not found on type [java.lang.String]

Ja autorizei o acesso na classe SecurityConfiguration

package br.com.casadocodigo.loja.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import br.com.casadocodigo.loja.dao.UsuarioDAO;

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private UsuarioDAO usuarioDao;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/produtos/detalhes/**").permitAll()
            .antMatchers("/produtos/**").hasRole("ADMIN")
            .antMatchers("/carrinho/**").permitAll()    
            .antMatchers("/pagamento/**").permitAll()
            .antMatchers("/relatorio-produtos/**").permitAll()
            .antMatchers("/relatorio-produtos").permitAll()
            .antMatchers("/").permitAll()
            .antMatchers("/url-magica-maluca-oajksfbvad6584i57j54f9684nvi658efnoewfmnvowefnoeijn").permitAll()
            .anyRequest().authenticated()
            .and()
                .formLogin().loginPage("/login").defaultSuccessUrl("/").permitAll()
            .and()
                .logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll() 
                .logoutSuccessUrl("/login");
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(usuarioDao)
                .passwordEncoder(new BCryptPasswordEncoder());
    }

    // Forma recomendada de ignorar no filtro de segurança as requisições para recursos estáticos
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");
    }
}
1 resposta
O post foi fechado por inatividade após 3 meses. Para continuar o assunto, recomendamos criar um novo tópico. Bons Estudos!