// open api
    name = "Basic Auth",
    type = SecuritySchemeType.HTTP,
    scheme = "basic",
    description = "Basic Auth")

// security config 2 users
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();

  protected void configure(HttpSecurity http) throws Exception {
        .authenticationEntryPoint(new Http403ForbiddenEntryPoint())

  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        .passwordEncoder(new BCryptPasswordEncoder())

// controllers
@SecurityRequirement(name = "Basic Auth")
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter