Reputation: 23
Here is the scenario,
Spring-boot version: 2.3.2.RELEASE
Swagger-ui version: 2.9.2
Has anyone worked on a similar use case?
Here is some of my config classes/methods.
@Configuration
@EnableSwagger2
public class SpringFoxConfig {
~~
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage(SpringbootApplication.class.getPackage().getName()))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
*//.securitySchemes(Arrays.asList(new ApiKey(BEARER, AUTHORIZATION, HEADER))) << currently I have this code but what I want is to have basic auth where user can enter his credentials*
.securitySchemes(Arrays.asList(new BasicAuth("basicAuth")))
.securityContexts(Arrays.asList(SecurityContext.builder()
.securityReferences(Arrays.asList(new SecurityReference(BEARER, new AuthorizationScope[] {})))
.forPaths(PathSelectors.any())
.build()));
}
~~
}
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
~~
@Override
public void configure(HttpSecurity http) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
registry.antMatchers("/actuator/health")
.permitAll()
.antMatchers("/actuator/info")
.permitAll()
.antMatchers("/swagger-ui.html")
.permitAll()
.anyRequest()
.authenticated();
}
~~
}
Upvotes: 0
Views: 1006
Reputation: 23
I figured out the solution with custom solution. More details below.
Upvotes: 1