I'm using:
Spring boot 1.5.4
Package spring-boot-starter-jersey
Swagger UI 3.0.4
Package swagger-jersey2-jaxrs 1.5.13

We're using digest authentication, but I've temporarily added basic 
authentication to the app to see if we could get this to work with Swagger 
UI.   I'd like to apply it to the entire application rather than specify it 
on each method.

Our JerseyConfig looks like this:



@Component
public class JerseyConfiguration extends ResourceConfig {
  private static Log logger = LogFactory.getLog(JerseyConfiguration.class);


  @Value("${spring.jersey.application-path:/}")
  private String apiPath;


  public JerseyConfiguration() {
    registerEndpoints();
    configureSwagger();
  }


  private void registerEndpoints() {
    register(MyEndpoints.class);
    
    // Generate Jersey WADL at /<Jersey's servlet path>/application.wadl
    register(WadlResource.class);
    
    // Lets us get to static content like swagger
    property(ServletProperties.FILTER_STATIC_CONTENT_REGEX, 
"((/swagger/.*)|(.*\\.html))");
   }


  /**
   * Configure the Swagger documentation for this API.
   * 
   * Very useful article:
   * 
http://tech.asimio.net/2016/04/05/Microservices-using-Spring-Boot-Jersey-Swagger-and-Docker.html
   */
  private void configureSwagger() {
    // Creates file at localhost:port/swagger.json
    this.register(ApiListingResource.class);
    this.register(SwaggerSerializers.class);


    BeanConfig config = new BeanConfig();
    config.setConfigId("example-jersey-app");
    config.setTitle("Spring Boot + Jersey + Swagger");
    config.setVersion("2");
    config.setContact("Me <[email protected]>");
    config.setSchemes(new String[] {"http", "https"});
    config.setResourcePackage("com.example.api");
    config.setBasePath(this.apiPath);
    config.setPrettyPrint(true);
    config.setScan(true);
  }
}


Our swagger.json file is created entirely from annotations at this point. 
 How do I incorporate authentication definitions?  From what I've been 
reading, it sounds like I have to add code to both my app and Swagger UI to 
get the authorization documented and then test it with Swagger UI "Try It." 
 I found this question and 
answer: https://github.com/swagger-api/swagger-core/issues/1257 "Annotation 
for Authentication?" but I am not explicitly defining my Servlet so I'm not 
sure how to incorporate the example code referenced there.

What are the next steps I need to take to get authentication working from 
Swagger UI?  


-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to