Fórum Ao adicionar Filtro de Autenticação no Spring security, não é possível acessar o h2-console #612570
22/08/2020
0
Ola, criei a minha classe de configuração do spring security, mas ao adicionar o filtro de autorização o meu acesso ao h2-console foi perdido:
Gostaria de saber se esta faltando alguma configurção para liberar o h2-console?
Gostaria de saber se esta faltando alguma configurção para liberar o h2-console?
@Override
protected void configure(HttpSecurity http) throws Exception{
if(Arrays.asList(env.getActiveProfiles()).contains("test")){
http.headers().frameOptions().disable();
}
http.cors().and().csrf().disable();
http.authorizeRequests()
.antMatchers(HttpMethod.GET, PUBLIC_MATCHERS_GET).permitAll()
.antMatchers(PUBLIC_MATCHERS).permitAll()
.anyRequest().authenticated();
http.addFilter(new JWTAuthenticationFilter(authenticationManager(), jwtUtil));
http.addFilter(new JWTAuthorizationFilter(authenticationManager(), jwtUtil, userDetailsService));
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
Abmael Ferreira
Curtir tópico
+ 0
Responder
Posts
22/08/2020
Abmael Ferreira
Ola, criei a minha classe de configuração do spring security, mas ao adicionar o filtro de autorização o meu acesso ao h2-console foi perdido:
Gostaria de saber se esta faltando alguma configurção para liberar o h2-console?
Gostaria de saber se esta faltando alguma configurção para liberar o h2-console?
@Override
protected void configure(HttpSecurity http) throws Exception{
if(Arrays.asList(env.getActiveProfiles()).contains("test")){
http.headers().frameOptions().disable();
}
http.cors().and().csrf().disable();
http.authorizeRequests()
.antMatchers(HttpMethod.GET, PUBLIC_MATCHERS_GET).permitAll()
.antMatchers(PUBLIC_MATCHERS).permitAll()
.anyRequest().authenticated();
http.addFilter(new JWTAuthenticationFilter(authenticationManager(), jwtUtil));
http.addFilter(new JWTAuthorizationFilter(authenticationManager(), jwtUtil, userDetailsService));
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
Responder
Gostei + 0
22/08/2020
Abmael Ferreira
Resolvido.
Na classe JWTAuthorizationFilter dentro do método doFilterInternal, eu coloquei a chamada do metodo chain.doFilter(request, response); dentro do if errado.
Na classe JWTAuthorizationFilter dentro do método doFilterInternal, eu coloquei a chamada do metodo chain.doFilter(request, response); dentro do if errado.
@Override
protected void doFilterInternal ( HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String header = request.getHeader("Authorization");
if(header != null && header.startsWith("Bearer ")) {
UsernamePasswordAuthenticationToken auth = getAuthentication(header);
// UsernamePasswordAuthenticationToken auth = getAuthentication(header.substring(7));
if(auth != null) {
SecurityContextHolder.getContext().setAuthentication(auth);
}
**//Tinha colocado o metodo aqui**
}
chain.doFilter(request, response);
}
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)