【问题标题】:Unable to infer base url - Spring 4.2, Spring Security 4.2, Swagger 2.8.0无法推断基本 url - Spring 4.2、Spring Security 4.2、Swagger 2.8.0
【发布时间】:2018-08-09 17:29:19
【问题描述】:
  1. 当我访问我的 api 时:http://xx/api/v1/reference,点击 大摇大摆,我得到:Unable to infer base url 我该如何解决这个问题? 在我的课堂上,我有:

    @Configuration
    @EnableWebSecurity
    @Order(1)
    public class SecurityJavaConfig extends WebSecurityConfigurerAdapter {
    
    @Value("${yourapp.http.auth-token-header-name}")
    private String principalRequestHeader;
    
    @Value("${yourapp.http.auth-token}")
    private String principalRequestValue;
    
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        APIKeyAuthFilter filter = new APIKeyAuthFilter(principalRequestHeader);
        filter.setAuthenticationManager(new AuthenticationManager() {
    
            @Override
            public Authentication authenticate(Authentication authentication) throws AuthenticationException {
                String principal = (String) authentication.getPrincipal();
                if (!principalRequestValue.equals(principal))
                {
                    throw new BadCredentialsException("The API key was not found or not the expected value.");
                }
                authentication.setAuthenticated(true);
                return authentication;
            }
        });
        httpSecurity.           
           antMatcher("/api/**").
            csrf().disable().
            sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).
            and().
    
            addFilter(filter).authorizeRequests().anyRequest().authenticated();
    
    }
    

    }

我知道已经发布了几个这样的问题: 没有人回答我的问题。显然,这已在 Springfox 2.8.1-SNAPSHOT 中修复。谁能给我一个适用于 Springfox 2.8.0 的解决方案?

【问题讨论】:

    标签: java spring rest spring-security swagger


    【解决方案1】:

    您是否尝试将以下内容列入白名单?

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

    【讨论】:

    • 试过了,但对我不起作用。使用 Swagger- 2.9.2、Spring 2.1.3.RELEASE、Spring security 5.1.4.RELEASE
    猜你喜欢
    • 2017-04-14
    • 1970-01-01
    • 2018-07-12
    • 2018-10-21
    • 2021-04-06
    • 1970-01-01
    • 2019-12-21
    • 2017-05-17
    • 2018-08-15
    相关资源
    最近更新 更多