no meu DB aparece apenas as tables ( produto, produto_precos e usuario_role) porque nao aparece as roles e usuarios?
UsuarioDao
@Repository
public class UsuarioDAO implements UserDetailsService {
@PersistenceContext
private EntityManager manager;
@Override
public Usuario loadUserByUsername(String email) {
List<Usuario> usuarios = manager.createQuery("select u from Usuario where u.email = :email", Usuario.class)
.setParameter("email", email).getResultList();
if (usuarios.isEmpty()) {
throw new UsernameNotFoundException("Usuario " + email + " não foi encontrado");
}
return usuarios.get(0);
}
}
Role
@Entity
public class Role implements GrantedAuthority {
private static final long serialVersionUID = 7872503757574608017L;
@Id
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
@Override
public String getAuthority() {
return this.nome;
}
}
ServletSpreingMVC
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { SecurityConfiguration.class, AppWebConfiguration.class, JPAConfiguration.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {};
}
...
SecurityConfig.
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UsuarioDAO usuarioDao;
@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")
.hasRole("ADMIN").antMatchers("/produtos/**").permitAll().antMatchers("/").permitAll().anyRequest()
.authenticated().and().formLogin();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(usuarioDao).passwordEncoder(new BCryptPasswordEncoder());
}
}