Já tentei ver se eu digitei algo de errado no SecurityConfigurations mas não vejo nada de errado.
Eu não consigo acessar a página.
@EnableWebSecurity
@Configuration
public class SecurityConfigurations extends WebSecurityConfigurerAdapter {
@Autowired
private AutenticacaoService autenticacaoService;
@Autowired
private TokenService tokenService;
@Autowired
private UsuarioRepository usuarioRepository;
@Override
@Bean
protected AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
//Conficuracoes de autenticacao.
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//Pegando a service que tem a logica de autenticacao.
auth.userDetailsService(autenticacaoService).passwordEncoder(new BCryptPasswordEncoder());
}
//Conficuracoes de Autorizacao.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
//Permitindo o acesso as seguintes rotas:
.antMatchers(HttpMethod.GET ,"/api/topicos").permitAll()
.antMatchers(HttpMethod.GET, "/api/topicos/*").permitAll()
.antMatchers(HttpMethod.POST, "/auth").permitAll()
.antMatchers(HttpMethod.GET, "/actuator/**").permitAll()
//Para o resto das rotas e necesario a autenticacao.
.anyRequest().authenticated()
.and().csrf().disable()
//Serve para não criar sessão
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().addFilterBefore(new AutenticacaoViaTokenFilter(tokenService, usuarioRepository), UsernamePasswordAuthenticationFilter.class);
}
//Conficuracoes de recursos estaticos(js, css, html, imagens, etc.).
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/**.html", "/v2/api-docs", "/webjars/**", "/configuration/**", "/swagger-resources/**");
}
}