标签: springfox

如何使用弹簧安全仅保护一个 url 并允许所有

我试图将 Spring 安全配置为仅阻止对 swagger 的请求,但是它阻止了所有 url。有谁知道如何只锁定 swagger 的 url 而其余的都不安全?

protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable()
        .authorizeRequests().anyRequest().permitAll()
        .and()
        .authorizeRequests()
            .antMatchers("/swagger*/**").authenticated();

        http.httpBasic();
    }
Run Code Online (Sandbox Code Playgroud)

java spring-security springfox

1
推荐指数
1
解决办法
4096
查看次数

在 SpringFox 2 中隐藏 Spring MVC 控制器的返回值

我有一个异步 Spring MVC 控制器,它返回Future. SpringFox 2 将其呈现为:

在此处输入图片说明

如何删除它?先感谢您!

spring spring-mvc documentation-generation swagger-ui springfox

1
推荐指数
1
解决办法
482
查看次数

尝试使用 springfox 配置访问 swagger-ui.html 时出现 WhiteLabel 错误页面

我正在尝试使用 Springfox 并遵循https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api文档从 springboot 项目生成 Swagger 文档。

最初,我收到错误“访问资源需要完全授权”,因为我在应用程序中使用 OAuth2。我更改了配置以允许所有以 /swagger-ui.html 结尾的请求。

现在,我在尝试访问本地的 /swagger-ui.html 时收到“WhiteLabel 错误页面 - 此应用程序没有 /error 的显式映射”。

我浏览了各种帖子,但没有一个解决方案对我有用 - 我没有使用可能干扰的@webmvcconfiguration。有人可以帮忙吗?

swagger spring-boot springfox

1
推荐指数
1
解决办法
1万
查看次数

springboot 不支持具有相同组名的多个 Docket

我有以下 swagger 的弹簧引导配置,当服务启动时,我收到以下错误,我不确定为什么会这样。我遵循了一个教程,它对他们有用。

java.lang.IllegalStateException: Multiple Dockets with the same group name are not supported. The following duplicate groups were discovered. default


@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SpringFoxConfig {

  @Bean
  public Docket apiDocket() {
    return new Docket(DocumentationType.SWAGGER_2)
      .select()
      .apis(RequestHandlerSelectors.basePackage("test.rest"))
      .paths(PathSelectors.ant("/test/**"))
      .build()
      .apiInfo(apiInfo());
  }

  // Describe the apis
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
      .title("test")
      .description("Test")
      .version("1.0.0")
      .license("vvv")
      .build();
  }

}
Run Code Online (Sandbox Code Playgroud)

我还有另一个配置

@OurApp
@EnableSwagger2
public class CoreApp extends OurApp {

}
Run Code Online (Sandbox Code Playgroud)

swagger spring-boot springfox

1
推荐指数
1
解决办法
7345
查看次数

仅对少数路径禁用过滤器

如何获取过滤器以应用于根路径之外的每个请求(我想忽略的请求除外)?这是我的例子:

我有一个 Spring Security 过滤器,如下所示:

private static class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .antMatcher("/**")
            .addFilterBefore(new AuthenticationFilter(), basicAuthenticationFilter.class);
    }

    @Override
    public void configure(WebSecurity web) {
        web
           .ignoring()
               .requestMatchers(SecurityServletRequestMatchers.servletIgnoreAuthMatcher());
    }
}
Run Code Online (Sandbox Code Playgroud)

该过滤器填充一个CustomApiToken包含所有标头信息的对象,并将其放入 Spring Security 上下文中SecurityContextHolder.getContext().setAuthentication(token),以便轻松访问请求控制器上的令牌。

我正在尝试将 Springfox 添加到项目中,这意味着我想禁用 UI 和 API 文档页面的过滤器。

我最初的尝试是在该方法中添加一个子句:

@Override
public void configure(HttpSecurity http) throws Exception {
    http
        .csrf().disable()
        .antMatcher("/**")
        .addFilterBefore(new AuthenticationFilter(), BasicAuthenticationFilter.class);

    http
        .requestMatcher(SecurityServletRequestMatchers.servletIgnoreAuthMatcher())
        .headers() //.servletIgnoreAuthMatchers has all the swagger urls also
            .defaultsDisabled()
            .disable() …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot springfox

1
推荐指数
1
解决办法
7092
查看次数

从Swagger UI测试API时Springfox 404错误

调查Springfox和Swagger UI,但我遇到了一个问题.我使用Spring Boot REST示例项目作为我的PoC的基础.我正在运行JDK 8,该项目利用了Gradle.

首先,这是项目的文件内容:

的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    jcenter()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("io.springfox:springfox-swagger2:2.2.2")
    compile("io.springfox:springfox-swagger-ui:2.2.2")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
Run Code Online (Sandbox Code Playgroud)

GreetingController.java

package hello;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui spring-boot springfox

0
推荐指数
1
解决办法
3025
查看次数