Estou com um problema que o Header Authorization não aparece não aparece no Swagger UI para alguns endpoints. Mais especificamente os que têm a permisssão USER.
Segue meu método configure:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(HttpMethod.POST, "/auth").permitAll()
.antMatchers(HttpMethod.GET, "/api/costumer/*").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT, "/api/costumer/*").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/api/costumer/*").hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/api/costumers").hasRole("ADMIN")
.antMatchers(HttpMethod.POST, "/api/costumer").permitAll()
.antMatchers(HttpMethod.GET, "/api/account/*").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/api/account/*").hasRole("ADMIN")
.antMatchers(HttpMethod.GET, "/api/accounts").hasRole("ADMIN")
.antMatchers(HttpMethod.POST, "/api/account").hasRole("USER")
.antMatchers(HttpMethod.PUT, "/api/transaction").hasRole("USER")
.antMatchers(HttpMethod.PUT, "/api/deposit").permitAll()
.antMatchers(HttpMethod.GET, "/actuator/**").permitAll()
.anyRequest().authenticated()
.and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().addFilterBefore(new AuthenticationViaTokenFilter(tokenService, costumerRepository), UsernamePasswordAuthenticationFilter.class);
}
SpringFoxConfig
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.donus.backend"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder()
.title("Donus")
.description("Donus - API REST")
.version("0.0.1-SNAPSHOT")
.contact(new Contact("Guilherme Melo", "https://www.linkedin.com/in/guilhermearmelo/", "guilhermearmelo@gmail.com"))
.build())
.globalOperationParameters(Arrays.asList(
new ParameterBuilder()
.name("Authorization")
.description("Header for JWT Token")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.build()));
}
OBS: Somente aparece o Authorization nos endpoints que têm .hasRole("USER"). No postman tudo funciona normal, pois posso colocar manualmente.