title: Add Swagger Basic AUTH to Spring Boot App
body: <p>Requirements:</p>
  
  <ul>
  <li>Spring Boot application with Springfox </li>
  <li>Add BASIC authentication to Swagger</li>
  <li>Pass on all other requests</li>
  </ul>
  
  <p>Code: implemented</p>
  
  <pre><code>@EnableWebSecurity
  @Configuration
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .antMatchers("/swagger-resources/*", "*.html", "/api/v1/swagger.json")
                  .hasAuthority("SWAGGER")
                  .anyRequest().permitAll()
              .and()
                  .httpBasic()
              .and()
                  .csrf().disable();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication().withUser("admin").password("admin").authorities("SWAGGER");
      }
  }
  </code></pre>
  
  <p>This code however does not work - you can freely browse /swagger-ui.html#/ without any authentcation.</p>
  
  <p>Question is - why BASIC auth and user do not apply to swagger ui endpoint?</p>