Skip to content

surajddmm/Spring-boot-3.1.3-with-swagger-and-basic-Auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-boot-3.1.3-with-OPEN API 3-and-basic-Auth

This Is an spring boot 3.1.3 project and integrate swagger open api 3.1.0 with InMemory Basic Auth

1 . Add Spring doc web mvc dependancy https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui

2 . Enable Swagger UI and path . Add below properties into application.properties

    springdoc.swagger-ui.enabled=true
    springdoc.api-docs.enabled=true
    springdoc.api-docs.path=/docs
    springdoc.swagger-ui.path=/docs/openapi.html
  1. Permit access to specific swagger URL in security filter chain

     @Bean
     SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
     http.csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.disable())
             .authorizeHttpRequests((authorize) -> {
                 authorize.requestMatchers("/docs/**").permitAll();
                 authorize.anyRequest().authenticated();
             }).httpBasic(Customizer.withDefaults());
       return http.build();
    }
    

4 . Swagger UI

swagger

5 . testing with postman

basicAuth-401

basicAuth

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages