io.swagger.models.Swagger.getSecurityDefinitions()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中io.swagger.models.Swagger.getSecurityDefinitions()方法的一些代码示例,展示了Swagger.getSecurityDefinitions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Swagger.getSecurityDefinitions()方法的具体详情如下:
包路径:io.swagger.models.Swagger
类名称:Swagger
方法名:getSecurityDefinitions

Swagger.getSecurityDefinitions介绍

暂无

代码示例

代码示例来源:origin: Swagger2Markup/swagger2markup

public SecuritySchemeComponent(Swagger2MarkupConverter.Context context,
                DocumentResolver securityDocumentResolver) {
  super(context);
  this.securityDefinitions = context.getSwagger().getSecurityDefinitions();
  this.securityDocumentResolver = Validate.notNull(securityDocumentResolver, "SecurityDocumentResolver must not be null");
  this.tableComponent = new TableComponent(context);
}

代码示例来源:origin: Swagger2Markup/swagger2markup

private MarkupDocBuilder applySecurityDocument() {
  return securityDocument.apply(
      context.createMarkupDocBuilder(),
      SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions()));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testSecuritySchemeDefinitionComponentWithApiKey() throws URISyntaxException {
  //Given
  Path file = Paths.get(SecuritySchemeDefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
  Swagger swagger = converter.getContext().getSwagger();
  SecuritySchemeDefinition securitySchemeDefinition = swagger.getSecurityDefinitions().get("api_key");
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  markupDocBuilder = new SecuritySchemeDefinitionComponent(context).apply(
      markupDocBuilder, SecuritySchemeDefinitionComponent.parameters("api_key",
          securitySchemeDefinition,
          OverviewDocument.SECTION_TITLE_LEVEL));
  markupDocBuilder.writeToFileWithoutExtension(apiKeyOutputDirectory, StandardCharsets.UTF_8);
  Path expectedFile = getExpectedFile(API_KEY_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, apiKeyOutputDirectory, getReportName(API_KEY_NAME));
}

代码示例来源:origin: Swagger2Markup/swagger2markup

@Test
public void testSecuritySchemeDefinitionComponentWithOAuth() throws URISyntaxException {
  //Given
  Path file = Paths.get(SecuritySchemeDefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
  Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
  Swagger swagger = converter.getContext().getSwagger();
  SecuritySchemeDefinition securitySchemeDefinition = swagger.getSecurityDefinitions().get("petstore_auth");
  Swagger2MarkupConverter.Context context = converter.getContext();
  MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
  markupDocBuilder = new SecuritySchemeDefinitionComponent(context).apply(
      markupDocBuilder, SecuritySchemeDefinitionComponent.parameters("petstore_auth",
          securitySchemeDefinition,
          OverviewDocument.SECTION_TITLE_LEVEL));
  markupDocBuilder.writeToFileWithoutExtension(oauthOutputDirectory, StandardCharsets.UTF_8);
  Path expectedFile = getExpectedFile(O_AUTH_NAME);
  DiffUtils.assertThatFileIsEqual(expectedFile, oauthOutputDirectory, getReportName(O_AUTH_NAME));
}

代码示例来源:origin: io.syndesis.server/server-api-generator

private static <T extends AbstractSecuritySchemeDefinition> Optional<T> securityDefinition(final Swagger swagger, final Class<T> type) {
  final Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions == null) {
    return empty();
  }
  return securityDefinitions.values().stream().filter(type::isInstance).map(type::cast).findFirst();
}

代码示例来源:origin: io.syndesis.rest/rest-connector-generator

private static <T extends AbstractSecuritySchemeDefinition> Optional<T> securityDefinition(final Swagger swagger, final Class<T> type) {
  final Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions == null) {
    return Optional.empty();
  }
  return securityDefinitions.values().stream().filter(type::isInstance).map(type::cast).findFirst();
}

代码示例来源:origin: io.syndesis/connector-generator

private static <T extends AbstractSecuritySchemeDefinition> Optional<T> securityDefinition(final Swagger swagger, final Class<T> type) {
  final Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions == null) {
    return Optional.empty();
  }
  return securityDefinitions.values().stream().filter(type::isInstance).map(type::cast).findFirst();
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

private static <T extends AbstractSecuritySchemeDefinition> Optional<T> securityDefinition(final Swagger swagger, final Class<T> type) {
  final Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions == null) {
    return empty();
  }
  return securityDefinitions.values().stream().filter(type::isInstance).map(type::cast).findFirst();
}

代码示例来源:origin: wso2/carbon-apimgt

private String getOauthSecurityName(Swagger swagger) {
  String oauthSecurityName = null;
  Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions != null) {
    for (Map.Entry<String, SecuritySchemeDefinition> securitySchemeDefinitionEntry :
        securityDefinitions.entrySet()) {
      if (securitySchemeDefinitionEntry.getValue() instanceof OAuth2Definition) {
        oauthSecurityName = securitySchemeDefinitionEntry.getKey();
        break;
      }
    }
  }
  return oauthSecurityName;
}

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.core

private String getOauthSecurityName(Swagger swagger) {
  String oauthSecurityName = null;
  Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
  if (securityDefinitions != null) {
    for (Map.Entry<String, SecuritySchemeDefinition> securitySchemeDefinitionEntry :
        securityDefinitions.entrySet()) {
      if (securitySchemeDefinitionEntry.getValue() instanceof OAuth2Definition) {
        oauthSecurityName = securitySchemeDefinitionEntry.getKey();
        break;
      }
    }
  }
  return oauthSecurityName;
}

代码示例来源:origin: phiz71/vertx-swagger

private static SwaggerAuthHandlerFactory getSwaggerAuthHandlerFactory(Swagger swagger) {
  SwaggerAuthHandlerFactory authHandlerFactory = null;
  if(swagger.getSecurityDefinitions() != null && !swagger.getSecurityDefinitions().isEmpty()) {
    boolean hasAuthProvidersForOperation = swagger.getSecurityDefinitions().entrySet().stream()
        .map(Map.Entry::getKey)
        .map(name -> getAuthProviderFactory().getAuthProviderByName(name))
        .anyMatch(Objects::nonNull);
    if (hasAuthProvidersForOperation) {
      authHandlerFactory = SwaggerAuthHandlerFactory.create(swagger.getSecurityDefinitions());
    }
  }
  return authHandlerFactory;
}

代码示例来源:origin: networknt/light-rest-4j

private static String getOAuth2Name() {
  String name = null;
  Map<String, SecuritySchemeDefinition> defMap = swagger.getSecurityDefinitions();
  if(defMap != null) {
    for(Map.Entry<String, SecuritySchemeDefinition> entry : defMap.entrySet()) {
      if(entry.getValue().getType().equals("oauth2")) {
        name = entry.getKey();
        break;
      }
    }
  }
  return name;
}

代码示例来源:origin: com.google.api/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 if (swagger.getSecurityDefinitions() == null) {
  return;
 }
 TreeSet<String> swaggerSecurityDefNames =
   Sets.newTreeSet(swagger.getSecurityDefinitions().keySet());
 for (String swaggerSecurityDefName : swaggerSecurityDefNames) {
  addAuthProvider(
    serviceBuilder,
    swaggerSecurityDefName,
    swagger.getSecurityDefinitions().get(swaggerSecurityDefName));
 }
 addSecurityRequirementForEntireService(serviceBuilder, swagger.getSecurity());
 addSecurityRequirementExtensionForEntireService(serviceBuilder, swagger);
}

代码示例来源:origin: googleapis/api-compiler

@Override
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) {
 if (swagger.getSecurityDefinitions() == null) {
  return;
 }
 TreeSet<String> swaggerSecurityDefNames =
   Sets.newTreeSet(swagger.getSecurityDefinitions().keySet());
 for (String swaggerSecurityDefName : swaggerSecurityDefNames) {
  addAuthProvider(
    serviceBuilder,
    swaggerSecurityDefName,
    swagger.getSecurityDefinitions().get(swaggerSecurityDefName));
 }
 addSecurityRequirementForEntireService(serviceBuilder, swagger.getSecurity());
 addSecurityRequirementExtensionForEntireService(serviceBuilder, swagger);
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

public SecuritySchemeComponent(Swagger2MarkupConverter.Context context,
                DocumentResolver securityDocumentResolver) {
  super(context);
  this.securityDefinitions = context.getSwagger().getSecurityDefinitions();
  this.securityDocumentResolver = Validate.notNull(securityDocumentResolver, "SecurityDocumentResolver must not be null");
  this.tableComponent = new TableComponent(context);
}

代码示例来源:origin: amazon-archives/aws-apigateway-importer

private Boolean isApiKeyRequired(Operation op) {
  Optional<Map.Entry<String, SecuritySchemeDefinition>> apiKeySecurityDefinition = Optional.empty();
  if (swagger.getSecurityDefinitions() != null) {
    apiKeySecurityDefinition = swagger.getSecurityDefinitions().entrySet()
        .stream().filter(p -> p.getValue().getType().equals("apiKey")).findFirst();
  }
  if (!apiKeySecurityDefinition.isPresent()) {
    return false;
  }
  String securityDefinitionName = apiKeySecurityDefinition.get().getKey();
  if (op.getSecurity() != null) {
    return op.getSecurity().stream().anyMatch(s -> s.containsKey(securityDefinitionName));
  }
  if (swagger.getSecurityRequirement() != null) {
    return swagger.getSecurityRequirement().stream().anyMatch(s -> s.getName().equals(securityDefinitionName));
  }
  return false;
}

代码示例来源:origin: io.github.swagger2markup/swagger2markup

private MarkupDocBuilder applySecurityDocument() {
  return securityDocument.apply(
      context.createMarkupDocBuilder(),
      SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions()));
}

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.core

@Override
public String updateScopesOnSwaggerDefinition(String resourceConfigJSON, Scope scope) {
  SwaggerParser swaggerParser = new SwaggerParser();
  Swagger swagger = swaggerParser.parse(resourceConfigJSON);
  Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = swagger.getSecurityDefinitions();
  if (securitySchemeDefinitionMap != null && !securitySchemeDefinitionMap.isEmpty()) {
    OAuth2Definition oAuth2Definition = (OAuth2Definition) securitySchemeDefinitionMap.get(APIMgtConstants
        .OAUTH2SECURITY);
    if (oAuth2Definition != null) {
      // Removing Scope from Swagger SecurityDefinition
      Map<String, String> scopeMap = oAuth2Definition.getScopes();
      if (scopeMap != null && scopeMap.containsKey(scope.getName())) {
        scopeMap.replace(scope.getName(), scope.getDescription());
      }
    }
  }
  return Json.pretty(swagger);
}

代码示例来源:origin: wso2/carbon-apimgt

@Override
public String updateScopesOnSwaggerDefinition(String resourceConfigJSON, Scope scope) {
  SwaggerParser swaggerParser = new SwaggerParser();
  Swagger swagger = swaggerParser.parse(resourceConfigJSON);
  Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = swagger.getSecurityDefinitions();
  if (securitySchemeDefinitionMap != null && !securitySchemeDefinitionMap.isEmpty()) {
    OAuth2Definition oAuth2Definition = (OAuth2Definition) securitySchemeDefinitionMap.get(APIMgtConstants
        .OAUTH2SECURITY);
    if (oAuth2Definition != null) {
      // Removing Scope from Swagger SecurityDefinition
      Map<String, String> scopeMap = oAuth2Definition.getScopes();
      if (scopeMap != null && scopeMap.containsKey(scope.getName())) {
        scopeMap.replace(scope.getName(), scope.getDescription());
      }
    }
  }
  return Json.pretty(swagger);
}

代码示例来源:origin: com.reprezen.genflow/genflow-api

@Override
public void swagger(Swagger swagger) {
  swagger.setSchemes(fillList(swagger.getSchemes()));
  swagger.setConsumes(fillList(swagger.getConsumes()));
  swagger.setProduces(fillList(swagger.getProduces()));
  swagger.setPaths(fillMap(swagger.getPaths()));
  swagger.setDefinitions(fillMap(swagger.getDefinitions()));
  swagger.setParameters(fillMap(swagger.getParameters()));
  swagger.setResponses(fillMap(swagger.getResponses()));
  swagger.setSecurityDefinitions(fillMap(swagger.getSecurityDefinitions()));
  swagger.setSecurity(fillList(swagger.getSecurity()));
  swagger.setTags(fillList(swagger.getTags()));
}

相关文章