title: Swagger-ui with Spring security
body: <p>I have a simple REST application with authentication service. I tried to add swagger and swagger-ui to it, but I can only see my endpoints in <code>/v2/api-docs</code>.
  In <code>swagger-ui.html</code> I see only groups of endpoints but I am unable to extend any list.</p>
  <p>In chrome debug I see:</p>
  <blockquote>
  <p>Failed to load resource: the server responded with a status of 401 ()</p>
  <p>Uncaught TypeError: Cannot read property 'indexOf' of undefined</p>
  </blockquote>
  <p>and on a terminal with a server:</p>
  <blockquote>
  <p>ERROR 10020 --- [nio-5001-exec-3] c.t.r.a.p.JwtAuthenticationEntryPoint    : Responding with unauthorized error. Message - Full authentication is required to access this resource</p>
  </blockquote>
  <p>It looks like my config files are missing something, I tried few solutions I found on a web but still nothing work.</p>
  <p>This is my code:</p>
  <p>pom</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;io.springfox&lt;/groupId&gt;
      &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
      &lt;version&gt;2.9.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;io.springfox&lt;/groupId&gt;
      &lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt;
      &lt;version&gt;2.9.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>controller</p>
  <pre><code>@RestController
  @PreAuthorize(&quot;hasRole('USER')&quot;)
  @RequestMapping(path = &quot;restaurant&quot;)
  @Api(value=&quot;restaurant&quot;, description=&quot;Example operations for restaurants&quot;)
  public class RestaurantController {
  // endpoints
  }
  </code></pre>
  <p>swagger bean</p>
  <pre><code>@Configuration
  @EnableSwagger2
  public class SwaggerConfig {
      @Bean
      public Docket api() {
          return new Docket(DocumentationType.SWAGGER_2)
                  .select()
                  .apis(RequestHandlerSelectors.basePackage(&quot;com.tablebooker.restaurantservice.restaurant&quot;))
                  .paths(PathSelectors.any())
                  .build();
      }
  }
  </code></pre>
  <p>SecurityConfig</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(
          securedEnabled = true,
          jsr250Enabled = true,
          prePostEnabled = true
  )
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  //other methods
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
                  .cors()
                  .and()
                  .csrf()
                  .disable()
                  .exceptionHandling()
                  .authenticationEntryPoint(unauthorizedHandler)
                  .and()
                  .sessionManagement()
                  .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                  .and()
                  .authorizeRequests()
                  .antMatchers(&quot;/&quot;,
                          &quot;/favicon.ico&quot;,
                          &quot;/**/*.png&quot;,
                          &quot;/**/*.gif&quot;,
                          &quot;/**/*.svg&quot;,
                          &quot;/**/*.jpg&quot;,
                          &quot;/**/*.html&quot;,
                          &quot;/**/*.css&quot;,
                          &quot;/**/*.js&quot;)
                  .permitAll()
                  .antMatchers(&quot;/api/auth/**&quot;)
                  .permitAll()
                  .antMatchers(&quot;/restaurant/**&quot;)
                  .hasRole(&quot;USER&quot;)
                  .anyRequest()
                  .authenticated();
  
          http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
  
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers(&quot;/v2/api-docs&quot;, &quot;/configuration/ui&quot;, &quot;/swagger-resources&quot;, &quot;/configuration/security&quot;, &quot;/swagger-ui.html&quot;, &quot;/webjars/**&quot;);
      }
  }
  </code></pre>
  <p>Any ideas how can I make my configuration work?</p>