Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Documentação Swagger não aparece

Olá, finalizei o curso até a parte de deploy e gostaria de arrumar algumas no swagger mas quando rodei a aplicação e acessei pelo navegador http://localhost:8080/swagger-ui.html direcionou para essa página da imagem. Até fiz download no projeto na ultima versão e chego no mesmo resultado como posso fazer para acessa o swagger novamente?

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

4 respostas

Oi Graciele,

Parece que o Spring Security está bloqueando as requisições para o Swagger. Posta aqui o código completo da sua classe SecurityConfigurations

solução!
@EnableWebSecurity
@Configuration
@Profile(value={"prod", "test"})
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();
    }

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


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
        .antMatchers(HttpMethod.GET, "/topicos").permitAll()
        .antMatchers(HttpMethod.GET, "/topicos/*").permitAll()
        .antMatchers(HttpMethod.POST, "/auth").permitAll()
        .antMatchers(HttpMethod.GET, "/actuator/**").permitAll() 
        .antMatchers(HttpMethod.DELETE, "/topicos/*").hasRole("MODERADOR") 
        .anyRequest().authenticated()
        .and().csrf().disable()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and().addFilterBefore(new AutenticacaoViaTokenFilter(tokenService, usuarioRepository), 
                UsernamePasswordAuthenticationFilter.class); 
    }


    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(
                "/**.html",
                "/v2/api-docs",
                "/webjars/**",
                "/configuration/**",
                "/swagger-resources/**");
    }

}

Está certinho o código, mas essa classe está anotada com @Profile(value={"prod", "test"}) e com isso não será carregada quando você rodar localmente, pois não terá profile ativo.

Obrigada Rodrigo, fiz o teste aqui deu certinho comentei essa linha do @Profile na classe SecurityConfigurations. Agora entendi o porquê. Insira aqui a descrição dessa imagem para ajudar na acessibilidade

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