Springfox swagger-ui.html unable to infer base URL - Caused by missing cookies












0















I have filed an issue on the github page. But was wondering if anyone else has a suggestion for workaround for this issue:



We have our Spring Boot services behind an API Gateway. With an earlier version of Springfox - 2.1.2 we had no issues in loading the swagger-ui.html page. This worked with Spring Boot 1.4.3.RELEASE. We have since upgraded to Boot 1.5.7 and upgraded Springfox to 2.8.0.



Now if we load the page we get an alert box with a long message that starts with "Unable to infer base URL".



Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually



I got some hints searching online, but it does not seem those situations apply to us. For one, if I simply revert back the versions, it starts working again through the same API Gateway.



Tracking the traffic, it seems calls to three XHR resources made by the html page is causing issues. These are returning 401 from our api-gateway. And the reason they return 401 is because the cookies are not passed along.



The three calls are:




  • https://base_address/base_context/swagger-resources/configuration/ui

  • https://base_address/base_context/swagger-resources/configuration/security

  • https://base_address/base_context/swagger-resources


If I load these URLs as pure browser requests - they work - because cookies are sent.



I doubt if CORS applies since the HTML is being served from the same address as the swagger JSON and actual service calls.



Any idea why this may be happening? Anybody faced similar issues? Suggestions for workaround? Thanks much in advance.



Regards,
Arnab.










share|improve this question





























    0















    I have filed an issue on the github page. But was wondering if anyone else has a suggestion for workaround for this issue:



    We have our Spring Boot services behind an API Gateway. With an earlier version of Springfox - 2.1.2 we had no issues in loading the swagger-ui.html page. This worked with Spring Boot 1.4.3.RELEASE. We have since upgraded to Boot 1.5.7 and upgraded Springfox to 2.8.0.



    Now if we load the page we get an alert box with a long message that starts with "Unable to infer base URL".



    Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually



    I got some hints searching online, but it does not seem those situations apply to us. For one, if I simply revert back the versions, it starts working again through the same API Gateway.



    Tracking the traffic, it seems calls to three XHR resources made by the html page is causing issues. These are returning 401 from our api-gateway. And the reason they return 401 is because the cookies are not passed along.



    The three calls are:




    • https://base_address/base_context/swagger-resources/configuration/ui

    • https://base_address/base_context/swagger-resources/configuration/security

    • https://base_address/base_context/swagger-resources


    If I load these URLs as pure browser requests - they work - because cookies are sent.



    I doubt if CORS applies since the HTML is being served from the same address as the swagger JSON and actual service calls.



    Any idea why this may be happening? Anybody faced similar issues? Suggestions for workaround? Thanks much in advance.



    Regards,
    Arnab.










    share|improve this question



























      0












      0








      0


      1






      I have filed an issue on the github page. But was wondering if anyone else has a suggestion for workaround for this issue:



      We have our Spring Boot services behind an API Gateway. With an earlier version of Springfox - 2.1.2 we had no issues in loading the swagger-ui.html page. This worked with Spring Boot 1.4.3.RELEASE. We have since upgraded to Boot 1.5.7 and upgraded Springfox to 2.8.0.



      Now if we load the page we get an alert box with a long message that starts with "Unable to infer base URL".



      Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually



      I got some hints searching online, but it does not seem those situations apply to us. For one, if I simply revert back the versions, it starts working again through the same API Gateway.



      Tracking the traffic, it seems calls to three XHR resources made by the html page is causing issues. These are returning 401 from our api-gateway. And the reason they return 401 is because the cookies are not passed along.



      The three calls are:




      • https://base_address/base_context/swagger-resources/configuration/ui

      • https://base_address/base_context/swagger-resources/configuration/security

      • https://base_address/base_context/swagger-resources


      If I load these URLs as pure browser requests - they work - because cookies are sent.



      I doubt if CORS applies since the HTML is being served from the same address as the swagger JSON and actual service calls.



      Any idea why this may be happening? Anybody faced similar issues? Suggestions for workaround? Thanks much in advance.



      Regards,
      Arnab.










      share|improve this question
















      I have filed an issue on the github page. But was wondering if anyone else has a suggestion for workaround for this issue:



      We have our Spring Boot services behind an API Gateway. With an earlier version of Springfox - 2.1.2 we had no issues in loading the swagger-ui.html page. This worked with Spring Boot 1.4.3.RELEASE. We have since upgraded to Boot 1.5.7 and upgraded Springfox to 2.8.0.



      Now if we load the page we get an alert box with a long message that starts with "Unable to infer base URL".



      Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually



      I got some hints searching online, but it does not seem those situations apply to us. For one, if I simply revert back the versions, it starts working again through the same API Gateway.



      Tracking the traffic, it seems calls to three XHR resources made by the html page is causing issues. These are returning 401 from our api-gateway. And the reason they return 401 is because the cookies are not passed along.



      The three calls are:




      • https://base_address/base_context/swagger-resources/configuration/ui

      • https://base_address/base_context/swagger-resources/configuration/security

      • https://base_address/base_context/swagger-resources


      If I load these URLs as pure browser requests - they work - because cookies are sent.



      I doubt if CORS applies since the HTML is being served from the same address as the swagger JSON and actual service calls.



      Any idea why this may be happening? Anybody faced similar issues? Suggestions for workaround? Thanks much in advance.



      Regards,
      Arnab.







      spring spring-boot swagger swagger-ui springfox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 '18 at 15:26







      Arnab Gupta

















      asked Mar 7 '18 at 15:20









      Arnab GuptaArnab Gupta

      815




      815
























          4 Answers
          4






          active

          oldest

          votes


















          2














          This happened to me, I was using SpringBoot 1.5.16 and Springfox 2.9.1.



          In my application.properties, I had defined server.servlet-path=/api, but, somehow, the swagger-ui was ignoring the value defined. I've tried so many different way to make this work, and finally I found a workaround:



           @Configuration
          @EnableSwagger2
          public class SwaggerConfiguration extends WebMvcConfigurationSupport {

          @Bean
          public Docket apiMonitoramento() {
          return new Docket(DocumentationType.SWAGGER_2)
          .select()
          .apis(RequestHandlerSelectors.any())
          .paths(PathSelectors.any())
          .build()
          .apiInfo(apiInfo());
          }

          private ApiInfo apiInfo() {
          return new ApiInfoBuilder()
          .title("REST API")
          .description("Servicesx")
          .build();
          }

          @Override
          protected void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("swagger-ui.html")
          .addResourceLocations("classpath:/META-INF/resources/");
          registry.addResourceHandler("/webjars/**")
          .addResourceLocations("classpath:/META-INF/resources/webjars/");
          }
          }


          I was accessing http://localhost:8080/context/swagger-ui.html, but with that configuration the correct URL is: http://localhost:8080/context/api/swagger-ui.html






          share|improve this answer































            1














            SEE EDIT BELOW



            Do you use spring security?



            If yes, probably you skip some resources like this (right?):

            "/swagger-resources/**",
            "/swagger-ui.html",
            "/v2/api-docs",
            "/webjars/**"



            Try to change it "/swagger-resources/**" to "**/swagger-resources/**".



            My specific security config for swagger is:



            private static final String AUTH_LIST = {
            // -- swagger ui
            "**/swagger-resources/**",
            "/swagger-ui.html",
            "/v2/api-docs",
            "/webjars/**"
            };

            @Override
            protected void configure(HttpSecurity http) throws Exception {
            http
            .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
            .and()
            .httpBasic().authenticationEntryPoint(swaggerAuthenticationEntryPoint())
            .and()
            .csrf().disable();
            }

            @Bean
            public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
            BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
            entryPoint.setRealmName("Swagger Realm");
            return entryPoint;
            }


            If you need/want I can send a sample project to GitHub to you know more about my security/swagger configs.



            EDIT 2018/04/10



            This problem is caused by a wrong version in springfox. See this issue on github to solve the problem.



            To posterity:



            In pom.xml



            ...
            <repositories>
            <repository>
            <id>swagger</id>
            <name>swagger</name>
            <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
            </repository>
            </repositories>
            ...
            <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.1-SNAPSHOT</version>
            </dependency>
            <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.1-SNAPSHOT</version>
            </dependency>
            ...


            Class that extends WebSecurityConfigAdapter:



            @Configuration
            public class WebSecurityConfigEntryPointApplication extends WebSecurityConfigurerAdapter {

            private static final List<String> AUTH_LIST = Arrays.asList(
            "/swagger-resources/**",
            "/swagger-ui.html**",
            "/webjars/**",
            "favicon.ico");

            @Autowired
            private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

            @Override
            protected void configure(HttpSecurity http) throws Exception {
            http
            .antMatcher("/**").authorizeRequests().anyRequest().authenticated()
            .and()
            .exceptionHandling()
            .defaultAuthenticationEntryPointFor(swaggerAuthenticationEntryPoint(), new CustomRequestMatcher(AUTH_LIST))
            .and()
            .httpBasic()
            .authenticationEntryPoint(restAuthenticationEntryPoint)
            .and()
            .csrf().disable();
            }

            @Bean
            public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
            BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
            entryPoint.setRealmName("Swagger Realm");
            return entryPoint;
            }

            private class CustomRequestMatcher implements RequestMatcher {

            private List<AntPathRequestMatcher> matchers;

            private CustomRequestMatcher(List<String> matchers) {
            this.matchers = matchers.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
            }

            @Override
            public boolean matches(HttpServletRequest request) {
            return matchers.stream().anyMatch(a -> a.matches(request));
            }

            }

            }


            RestAuthenticationEntryPoint:



            @Component
            public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

            @Override
            public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
            }
            }





            share|improve this answer


























            • I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

              – Arnab Gupta
              Apr 9 '18 at 22:39











            • Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

              – Marco Blos
              Apr 10 '18 at 13:00













            • Can somebody guide here : stackoverflow.com/questions/53377229/…

              – Jeff Cook
              Nov 19 '18 at 15:08



















            1














            Add in the security config -- following URLS that are skipped for authentication ::



            private static final String AUTH_WHITELIST = {
            "/swagger-resources/**",
            "/swagger-ui.html",
            "/v2/api-docs",
            "/webjars/**"
            };

            @Override
            public void configure(WebSecurity web) throws Exception {
            web.ignoring().antMatchers(AUTH_WHITELIST);
            }





            share|improve this answer































              0














              Adding below annotation at the spring boot class resolved this issue for me.




              @EnableSwagger2




              I am using swagger version



               <version>2.9.2</version>





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49155420%2fspringfox-swagger-ui-html-unable-to-infer-base-url-caused-by-missing-cookies%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                This happened to me, I was using SpringBoot 1.5.16 and Springfox 2.9.1.



                In my application.properties, I had defined server.servlet-path=/api, but, somehow, the swagger-ui was ignoring the value defined. I've tried so many different way to make this work, and finally I found a workaround:



                 @Configuration
                @EnableSwagger2
                public class SwaggerConfiguration extends WebMvcConfigurationSupport {

                @Bean
                public Docket apiMonitoramento() {
                return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
                }

                private ApiInfo apiInfo() {
                return new ApiInfoBuilder()
                .title("REST API")
                .description("Servicesx")
                .build();
                }

                @Override
                protected void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
                registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
                }
                }


                I was accessing http://localhost:8080/context/swagger-ui.html, but with that configuration the correct URL is: http://localhost:8080/context/api/swagger-ui.html






                share|improve this answer




























                  2














                  This happened to me, I was using SpringBoot 1.5.16 and Springfox 2.9.1.



                  In my application.properties, I had defined server.servlet-path=/api, but, somehow, the swagger-ui was ignoring the value defined. I've tried so many different way to make this work, and finally I found a workaround:



                   @Configuration
                  @EnableSwagger2
                  public class SwaggerConfiguration extends WebMvcConfigurationSupport {

                  @Bean
                  public Docket apiMonitoramento() {
                  return new Docket(DocumentationType.SWAGGER_2)
                  .select()
                  .apis(RequestHandlerSelectors.any())
                  .paths(PathSelectors.any())
                  .build()
                  .apiInfo(apiInfo());
                  }

                  private ApiInfo apiInfo() {
                  return new ApiInfoBuilder()
                  .title("REST API")
                  .description("Servicesx")
                  .build();
                  }

                  @Override
                  protected void addResourceHandlers(ResourceHandlerRegistry registry) {
                  registry.addResourceHandler("swagger-ui.html")
                  .addResourceLocations("classpath:/META-INF/resources/");
                  registry.addResourceHandler("/webjars/**")
                  .addResourceLocations("classpath:/META-INF/resources/webjars/");
                  }
                  }


                  I was accessing http://localhost:8080/context/swagger-ui.html, but with that configuration the correct URL is: http://localhost:8080/context/api/swagger-ui.html






                  share|improve this answer


























                    2












                    2








                    2







                    This happened to me, I was using SpringBoot 1.5.16 and Springfox 2.9.1.



                    In my application.properties, I had defined server.servlet-path=/api, but, somehow, the swagger-ui was ignoring the value defined. I've tried so many different way to make this work, and finally I found a workaround:



                     @Configuration
                    @EnableSwagger2
                    public class SwaggerConfiguration extends WebMvcConfigurationSupport {

                    @Bean
                    public Docket apiMonitoramento() {
                    return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build()
                    .apiInfo(apiInfo());
                    }

                    private ApiInfo apiInfo() {
                    return new ApiInfoBuilder()
                    .title("REST API")
                    .description("Servicesx")
                    .build();
                    }

                    @Override
                    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
                    registry.addResourceHandler("swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
                    registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
                    }
                    }


                    I was accessing http://localhost:8080/context/swagger-ui.html, but with that configuration the correct URL is: http://localhost:8080/context/api/swagger-ui.html






                    share|improve this answer













                    This happened to me, I was using SpringBoot 1.5.16 and Springfox 2.9.1.



                    In my application.properties, I had defined server.servlet-path=/api, but, somehow, the swagger-ui was ignoring the value defined. I've tried so many different way to make this work, and finally I found a workaround:



                     @Configuration
                    @EnableSwagger2
                    public class SwaggerConfiguration extends WebMvcConfigurationSupport {

                    @Bean
                    public Docket apiMonitoramento() {
                    return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build()
                    .apiInfo(apiInfo());
                    }

                    private ApiInfo apiInfo() {
                    return new ApiInfoBuilder()
                    .title("REST API")
                    .description("Servicesx")
                    .build();
                    }

                    @Override
                    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
                    registry.addResourceHandler("swagger-ui.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
                    registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
                    }
                    }


                    I was accessing http://localhost:8080/context/swagger-ui.html, but with that configuration the correct URL is: http://localhost:8080/context/api/swagger-ui.html







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 19 '18 at 2:46









                    carolnogueiracarolnogueira

                    34129




                    34129

























                        1














                        SEE EDIT BELOW



                        Do you use spring security?



                        If yes, probably you skip some resources like this (right?):

                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"



                        Try to change it "/swagger-resources/**" to "**/swagger-resources/**".



                        My specific security config for swagger is:



                        private static final String AUTH_LIST = {
                        // -- swagger ui
                        "**/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"
                        };

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
                        .and()
                        .httpBasic().authenticationEntryPoint(swaggerAuthenticationEntryPoint())
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }


                        If you need/want I can send a sample project to GitHub to you know more about my security/swagger configs.



                        EDIT 2018/04/10



                        This problem is caused by a wrong version in springfox. See this issue on github to solve the problem.



                        To posterity:



                        In pom.xml



                        ...
                        <repositories>
                        <repository>
                        <id>swagger</id>
                        <name>swagger</name>
                        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
                        </repository>
                        </repositories>
                        ...
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger2</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        ...


                        Class that extends WebSecurityConfigAdapter:



                        @Configuration
                        public class WebSecurityConfigEntryPointApplication extends WebSecurityConfigurerAdapter {

                        private static final List<String> AUTH_LIST = Arrays.asList(
                        "/swagger-resources/**",
                        "/swagger-ui.html**",
                        "/webjars/**",
                        "favicon.ico");

                        @Autowired
                        private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .antMatcher("/**").authorizeRequests().anyRequest().authenticated()
                        .and()
                        .exceptionHandling()
                        .defaultAuthenticationEntryPointFor(swaggerAuthenticationEntryPoint(), new CustomRequestMatcher(AUTH_LIST))
                        .and()
                        .httpBasic()
                        .authenticationEntryPoint(restAuthenticationEntryPoint)
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }

                        private class CustomRequestMatcher implements RequestMatcher {

                        private List<AntPathRequestMatcher> matchers;

                        private CustomRequestMatcher(List<String> matchers) {
                        this.matchers = matchers.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
                        }

                        @Override
                        public boolean matches(HttpServletRequest request) {
                        return matchers.stream().anyMatch(a -> a.matches(request));
                        }

                        }

                        }


                        RestAuthenticationEntryPoint:



                        @Component
                        public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

                        @Override
                        public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
                        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
                        }
                        }





                        share|improve this answer


























                        • I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                          – Arnab Gupta
                          Apr 9 '18 at 22:39











                        • Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                          – Marco Blos
                          Apr 10 '18 at 13:00













                        • Can somebody guide here : stackoverflow.com/questions/53377229/…

                          – Jeff Cook
                          Nov 19 '18 at 15:08
















                        1














                        SEE EDIT BELOW



                        Do you use spring security?



                        If yes, probably you skip some resources like this (right?):

                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"



                        Try to change it "/swagger-resources/**" to "**/swagger-resources/**".



                        My specific security config for swagger is:



                        private static final String AUTH_LIST = {
                        // -- swagger ui
                        "**/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"
                        };

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
                        .and()
                        .httpBasic().authenticationEntryPoint(swaggerAuthenticationEntryPoint())
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }


                        If you need/want I can send a sample project to GitHub to you know more about my security/swagger configs.



                        EDIT 2018/04/10



                        This problem is caused by a wrong version in springfox. See this issue on github to solve the problem.



                        To posterity:



                        In pom.xml



                        ...
                        <repositories>
                        <repository>
                        <id>swagger</id>
                        <name>swagger</name>
                        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
                        </repository>
                        </repositories>
                        ...
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger2</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        ...


                        Class that extends WebSecurityConfigAdapter:



                        @Configuration
                        public class WebSecurityConfigEntryPointApplication extends WebSecurityConfigurerAdapter {

                        private static final List<String> AUTH_LIST = Arrays.asList(
                        "/swagger-resources/**",
                        "/swagger-ui.html**",
                        "/webjars/**",
                        "favicon.ico");

                        @Autowired
                        private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .antMatcher("/**").authorizeRequests().anyRequest().authenticated()
                        .and()
                        .exceptionHandling()
                        .defaultAuthenticationEntryPointFor(swaggerAuthenticationEntryPoint(), new CustomRequestMatcher(AUTH_LIST))
                        .and()
                        .httpBasic()
                        .authenticationEntryPoint(restAuthenticationEntryPoint)
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }

                        private class CustomRequestMatcher implements RequestMatcher {

                        private List<AntPathRequestMatcher> matchers;

                        private CustomRequestMatcher(List<String> matchers) {
                        this.matchers = matchers.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
                        }

                        @Override
                        public boolean matches(HttpServletRequest request) {
                        return matchers.stream().anyMatch(a -> a.matches(request));
                        }

                        }

                        }


                        RestAuthenticationEntryPoint:



                        @Component
                        public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

                        @Override
                        public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
                        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
                        }
                        }





                        share|improve this answer


























                        • I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                          – Arnab Gupta
                          Apr 9 '18 at 22:39











                        • Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                          – Marco Blos
                          Apr 10 '18 at 13:00













                        • Can somebody guide here : stackoverflow.com/questions/53377229/…

                          – Jeff Cook
                          Nov 19 '18 at 15:08














                        1












                        1








                        1







                        SEE EDIT BELOW



                        Do you use spring security?



                        If yes, probably you skip some resources like this (right?):

                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"



                        Try to change it "/swagger-resources/**" to "**/swagger-resources/**".



                        My specific security config for swagger is:



                        private static final String AUTH_LIST = {
                        // -- swagger ui
                        "**/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"
                        };

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
                        .and()
                        .httpBasic().authenticationEntryPoint(swaggerAuthenticationEntryPoint())
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }


                        If you need/want I can send a sample project to GitHub to you know more about my security/swagger configs.



                        EDIT 2018/04/10



                        This problem is caused by a wrong version in springfox. See this issue on github to solve the problem.



                        To posterity:



                        In pom.xml



                        ...
                        <repositories>
                        <repository>
                        <id>swagger</id>
                        <name>swagger</name>
                        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
                        </repository>
                        </repositories>
                        ...
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger2</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        ...


                        Class that extends WebSecurityConfigAdapter:



                        @Configuration
                        public class WebSecurityConfigEntryPointApplication extends WebSecurityConfigurerAdapter {

                        private static final List<String> AUTH_LIST = Arrays.asList(
                        "/swagger-resources/**",
                        "/swagger-ui.html**",
                        "/webjars/**",
                        "favicon.ico");

                        @Autowired
                        private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .antMatcher("/**").authorizeRequests().anyRequest().authenticated()
                        .and()
                        .exceptionHandling()
                        .defaultAuthenticationEntryPointFor(swaggerAuthenticationEntryPoint(), new CustomRequestMatcher(AUTH_LIST))
                        .and()
                        .httpBasic()
                        .authenticationEntryPoint(restAuthenticationEntryPoint)
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }

                        private class CustomRequestMatcher implements RequestMatcher {

                        private List<AntPathRequestMatcher> matchers;

                        private CustomRequestMatcher(List<String> matchers) {
                        this.matchers = matchers.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
                        }

                        @Override
                        public boolean matches(HttpServletRequest request) {
                        return matchers.stream().anyMatch(a -> a.matches(request));
                        }

                        }

                        }


                        RestAuthenticationEntryPoint:



                        @Component
                        public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

                        @Override
                        public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
                        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
                        }
                        }





                        share|improve this answer















                        SEE EDIT BELOW



                        Do you use spring security?



                        If yes, probably you skip some resources like this (right?):

                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"



                        Try to change it "/swagger-resources/**" to "**/swagger-resources/**".



                        My specific security config for swagger is:



                        private static final String AUTH_LIST = {
                        // -- swagger ui
                        "**/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"
                        };

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .authorizeRequests().antMatchers(AUTH_LIST).authenticated()
                        .and()
                        .httpBasic().authenticationEntryPoint(swaggerAuthenticationEntryPoint())
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }


                        If you need/want I can send a sample project to GitHub to you know more about my security/swagger configs.



                        EDIT 2018/04/10



                        This problem is caused by a wrong version in springfox. See this issue on github to solve the problem.



                        To posterity:



                        In pom.xml



                        ...
                        <repositories>
                        <repository>
                        <id>swagger</id>
                        <name>swagger</name>
                        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
                        </repository>
                        </repositories>
                        ...
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger2</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-swagger-ui</artifactId>
                        <version>2.8.1-SNAPSHOT</version>
                        </dependency>
                        ...


                        Class that extends WebSecurityConfigAdapter:



                        @Configuration
                        public class WebSecurityConfigEntryPointApplication extends WebSecurityConfigurerAdapter {

                        private static final List<String> AUTH_LIST = Arrays.asList(
                        "/swagger-resources/**",
                        "/swagger-ui.html**",
                        "/webjars/**",
                        "favicon.ico");

                        @Autowired
                        private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

                        @Override
                        protected void configure(HttpSecurity http) throws Exception {
                        http
                        .antMatcher("/**").authorizeRequests().anyRequest().authenticated()
                        .and()
                        .exceptionHandling()
                        .defaultAuthenticationEntryPointFor(swaggerAuthenticationEntryPoint(), new CustomRequestMatcher(AUTH_LIST))
                        .and()
                        .httpBasic()
                        .authenticationEntryPoint(restAuthenticationEntryPoint)
                        .and()
                        .csrf().disable();
                        }

                        @Bean
                        public BasicAuthenticationEntryPoint swaggerAuthenticationEntryPoint() {
                        BasicAuthenticationEntryPoint entryPoint = new BasicAuthenticationEntryPoint();
                        entryPoint.setRealmName("Swagger Realm");
                        return entryPoint;
                        }

                        private class CustomRequestMatcher implements RequestMatcher {

                        private List<AntPathRequestMatcher> matchers;

                        private CustomRequestMatcher(List<String> matchers) {
                        this.matchers = matchers.stream().map(AntPathRequestMatcher::new).collect(Collectors.toList());
                        }

                        @Override
                        public boolean matches(HttpServletRequest request) {
                        return matchers.stream().anyMatch(a -> a.matches(request));
                        }

                        }

                        }


                        RestAuthenticationEntryPoint:



                        @Component
                        public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

                        @Override
                        public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
                        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
                        }
                        }






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Apr 10 '18 at 13:07

























                        answered Apr 3 '18 at 17:18









                        Marco BlosMarco Blos

                        370314




                        370314













                        • I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                          – Arnab Gupta
                          Apr 9 '18 at 22:39











                        • Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                          – Marco Blos
                          Apr 10 '18 at 13:00













                        • Can somebody guide here : stackoverflow.com/questions/53377229/…

                          – Jeff Cook
                          Nov 19 '18 at 15:08



















                        • I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                          – Arnab Gupta
                          Apr 9 '18 at 22:39











                        • Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                          – Marco Blos
                          Apr 10 '18 at 13:00













                        • Can somebody guide here : stackoverflow.com/questions/53377229/…

                          – Jeff Cook
                          Nov 19 '18 at 15:08

















                        I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                        – Arnab Gupta
                        Apr 9 '18 at 22:39





                        I have these set up. The issue is actually with 2.8.0 itself. I filed issue here: github.com/springfox/springfox/issues/2281

                        – Arnab Gupta
                        Apr 9 '18 at 22:39













                        Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                        – Marco Blos
                        Apr 10 '18 at 13:00







                        Hi @ArnabGupta. You are right! I made one comment on github with all steps to solve this problem. You get it here: github.com/springfox/springfox/issues/2191

                        – Marco Blos
                        Apr 10 '18 at 13:00















                        Can somebody guide here : stackoverflow.com/questions/53377229/…

                        – Jeff Cook
                        Nov 19 '18 at 15:08





                        Can somebody guide here : stackoverflow.com/questions/53377229/…

                        – Jeff Cook
                        Nov 19 '18 at 15:08











                        1














                        Add in the security config -- following URLS that are skipped for authentication ::



                        private static final String AUTH_WHITELIST = {
                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/v2/api-docs",
                        "/webjars/**"
                        };

                        @Override
                        public void configure(WebSecurity web) throws Exception {
                        web.ignoring().antMatchers(AUTH_WHITELIST);
                        }





                        share|improve this answer




























                          1














                          Add in the security config -- following URLS that are skipped for authentication ::



                          private static final String AUTH_WHITELIST = {
                          "/swagger-resources/**",
                          "/swagger-ui.html",
                          "/v2/api-docs",
                          "/webjars/**"
                          };

                          @Override
                          public void configure(WebSecurity web) throws Exception {
                          web.ignoring().antMatchers(AUTH_WHITELIST);
                          }





                          share|improve this answer


























                            1












                            1








                            1







                            Add in the security config -- following URLS that are skipped for authentication ::



                            private static final String AUTH_WHITELIST = {
                            "/swagger-resources/**",
                            "/swagger-ui.html",
                            "/v2/api-docs",
                            "/webjars/**"
                            };

                            @Override
                            public void configure(WebSecurity web) throws Exception {
                            web.ignoring().antMatchers(AUTH_WHITELIST);
                            }





                            share|improve this answer













                            Add in the security config -- following URLS that are skipped for authentication ::



                            private static final String AUTH_WHITELIST = {
                            "/swagger-resources/**",
                            "/swagger-ui.html",
                            "/v2/api-docs",
                            "/webjars/**"
                            };

                            @Override
                            public void configure(WebSecurity web) throws Exception {
                            web.ignoring().antMatchers(AUTH_WHITELIST);
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 21:03









                            panksy2kpanksy2k

                            7111




                            7111























                                0














                                Adding below annotation at the spring boot class resolved this issue for me.




                                @EnableSwagger2




                                I am using swagger version



                                 <version>2.9.2</version>





                                share|improve this answer




























                                  0














                                  Adding below annotation at the spring boot class resolved this issue for me.




                                  @EnableSwagger2




                                  I am using swagger version



                                   <version>2.9.2</version>





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    Adding below annotation at the spring boot class resolved this issue for me.




                                    @EnableSwagger2




                                    I am using swagger version



                                     <version>2.9.2</version>





                                    share|improve this answer













                                    Adding below annotation at the spring boot class resolved this issue for me.




                                    @EnableSwagger2




                                    I am using swagger version



                                     <version>2.9.2</version>






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 1 at 9:09









                                    ArindamArindam

                                    758




                                    758






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49155420%2fspringfox-swagger-ui-html-unable-to-infer-base-url-caused-by-missing-cookies%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        RAC Tourist Trophy