本文整理汇总了Java中io.swagger.models.auth.SecuritySchemeDefinition类的典型用法代码示例。如果您正苦于以下问题:Java SecuritySchemeDefinition类的具体用法?Java SecuritySchemeDefinition怎么用?Java SecuritySchemeDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecuritySchemeDefinition类属于io.swagger.models.auth包,在下文中一共展示了SecuritySchemeDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterScan
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
@Override
public void afterScan(Reader reader, Swagger swagger) {
OAuth2Definition tokenScheme = new OAuth2Definition();
tokenScheme.setType("oauth2");
tokenScheme.setFlow("application");
tokenScheme.setTokenUrl("https://" + swagger.getHost() + "/oauth2/token");
tokenScheme.setAuthorizationUrl("https://" + swagger.getHost() + "/oauth2/authorize");
tokenScheme.addScope("write:everything", "Full access");
Map<String, SecuritySchemeDefinition> schemes = new HashMap<>();
schemes.put(TOKEN_AUTH_SCHEME, tokenScheme);
swagger.setSecurityDefinitions(schemes);
}
示例2: validateAuthTypes
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
/**
* Check if all operations contains valid authentication types
*/
private SwaggerModelInfo validateAuthTypes(final SwaggerModelInfo swaggerModelInfo) {
if (swaggerModelInfo.getModel() == null) {
return swaggerModelInfo;
}
final SwaggerModelInfo.Builder withWarnings = new SwaggerModelInfo.Builder().createFrom(swaggerModelInfo);
for (final Map.Entry<String, SecuritySchemeDefinition> definitionEntry : notNull(
swaggerModelInfo.getModel().getSecurityDefinitions()).entrySet()) {
final String authType = definitionEntry.getValue().getType();
if (!SUPPORTED_AUTH_TYPES.contains(authType)) {
withWarnings.addWarning(new Violation.Builder()//
.property("")//
.error("unsupported-auth")//
.message("Authentication type " + authType + " is currently not supported")//
.build());
}
}
return withWarnings.build();
}
示例3: processUris
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
private void processUris(final Map<String, Path> swagger,
final Map<String, Model> definitionsMap,
final Map<String, SecuritySchemeDefinition> securityDefinitionsMap,
final int i) {
int j = 0;
while (env.containsProperty(String.format("swagger[%d].uris[%d].swagger", i, j))) {
try {
final URL swaggerUrl = env.getProperty(String.format("swagger[%d].uris[%d].swagger", i, j), URL.class);
final Swagger remoteSwagger = io.swagger.util.Json.mapper().readerFor(Swagger.class).readValue(swaggerUrl.openConnection().getInputStream());
processPaths(swagger, definitionsMap, securityDefinitionsMap, remoteSwagger, i, j);
++j;
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}
}
示例4: isApiKeyRequired
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
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;
}
示例5: apply
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
String securitySchemeDefinitionName = params.securitySchemeDefinitionName;
SecuritySchemeDefinition securitySchemeDefinition = params.securitySchemeDefinition;
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, securitySchemeDefinitionName);
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
String description = securitySchemeDefinition.getDescription();
if (isNotBlank(description)) {
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
}
buildSecurityScheme(markupDocBuilder, securitySchemeDefinition);
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
return markupDocBuilder;
}
示例6: testSecuritySchemeDefinitionComponentWithOAuth
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
@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));
}
示例7: testSecuritySchemeDefinitionComponentWithApiKey
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
@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));
}
示例8: generateSecuritySchemeDefinitions
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
public Map<String, SecuritySchemeDefinition> generateSecuritySchemeDefinitions() throws GenerateException {
Map<String, SecuritySchemeDefinition> map = new HashMap<String, SecuritySchemeDefinition>();
List<JsonNode> securityDefinitions = new ArrayList<JsonNode>();
if (json != null || jsonPath != null) {
securityDefinitions = loadSecurityDefintionsFromJsonFile();
} else {
securityDefinitions.add(new ObjectMapper().valueToTree(this));
}
for (JsonNode securityDefinition : securityDefinitions) {
SecuritySchemeDefinition ssd = getSecuritySchemeDefinitionByType(securityDefinition.get("type").asText(), securityDefinition);
if (ssd != null) {
map.put(securityDefinition.get("name").asText(), ssd);
}
}
return map;
}
示例9: getSwagger
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
public ClonableSwagger getSwagger(final String basePath,
final UriInfo uriInfo) {
ClonableSwagger swagger = swaggerMap.get(basePath);
if (swagger == null) {
final int i = swaggerPaths.get(basePath);
swagger = new ClonableSwagger();
final String title = env.getProperty(String.format("swagger[%d].info.title", i));
final String version = env.getProperty(String.format("swagger[%d].info.version", i));
swagger.setBasePath('/' + basePath);
final Info info = new Info();
info.setTitle(title);
info.setVersion(version);
swagger.setInfo(info);
final Map<String, Path> pathsMap = new TreeMap<>();
final Map<String, Model> definitionsMap = new TreeMap<>();
final Map<String, SecuritySchemeDefinition> securityDefinitionsMap = new TreeMap<>();
processUris(pathsMap, definitionsMap, securityDefinitionsMap, i);
swagger.setPaths(pathsMap);
swagger.setDefinitions(definitionsMap);
swagger.setSecurityDefinitions(securityDefinitionsMap);
swaggerMap.putIfAbsent(basePath, swagger);
}
return swagger.withUriInfo(uriInfo);
}
示例10: processPaths
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
private void processPaths(final Map<String, Path> swagger,
final Map<String, Model> definitionsMap,
final Map<String, SecuritySchemeDefinition> securityDefinitionsMap,
final Swagger remoteSwagger,
final int i,
final int j) {
int k = 0;
while (env.containsProperty(String.format("swagger[%d].uris[%d].paths[%d].from", i, j, k)) || env.containsProperty(String.format("swagger[%d].uris[%d].paths[%d]", i, j, k))) {
if (env.containsProperty(String.format("swagger[%d].uris[%d].paths[%d].from", i, j, k))) {
final String from = env.getRequiredProperty(String.format("swagger[%d].uris[%d].paths[%d].from", i, j, k));
final String to = env.getRequiredProperty(String.format("swagger[%d].uris[%d].paths[%d].to", i, j, k));
LOG.debug("getting path={} from paths={} and transform to={}", from, remoteSwagger.getPaths().keySet(), to);
Optional.ofNullable(remoteSwagger.getPaths())
.ifPresent(t -> remoteSwagger.getPaths().keySet().parallelStream()
.filter(s -> s.startsWith(from))
.forEach(p -> swagger.put(to + p.substring(from.length()), remoteSwagger.getPath(p))));
updateDefinitions(definitionsMap, securityDefinitionsMap, remoteSwagger);
} else {
final String path = env.getRequiredProperty(String.format("swagger[%d].uris[%d].paths[%d]", i, j, k));
if (LOG.isDebugEnabled()) {
LOG.debug("getting path={} from paths={}", path, remoteSwagger.getPaths().keySet());
}
if (remoteSwagger.getPaths() != null) {
remoteSwagger.getPaths().keySet().parallelStream()
.filter(s -> s.startsWith(path))
.forEach(p -> swagger.put(p, remoteSwagger.getPath(p)));
}
updateDefinitions(definitionsMap, securityDefinitionsMap, remoteSwagger);
}
++k;
}
}
示例11: updateDefinitions
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
/**
* Update the current definition maps.
*
* @param currentDefinitionsMap
* current definitions map
* @param currentSecurityDefinitionsMap
* current security defintions map
* @param swagger
* remote swagger data
*/
private void updateDefinitions(final Map<String, Model> currentDefinitionsMap,
final Map<String, SecuritySchemeDefinition> currentSecurityDefinitionsMap,
final Swagger swagger) {
Optional.ofNullable(swagger.getDefinitions())
.ifPresent(t -> t.entrySet().parallelStream()
.forEach(e -> currentDefinitionsMap.put(e.getKey(), e.getValue())));
Optional.ofNullable(swagger.getSecurityDefinitions())
.ifPresent(t -> t.entrySet().parallelStream()
.forEach(e -> currentSecurityDefinitionsMap.put(e.getKey(), e.getValue())));
}
示例12: getOAuth2Name
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
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;
}
示例13: getAuthHandler
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
private AuthHandler getAuthHandler(String name) {
AuthHandler authHandler = this.authHandlers.get(name);
if (authHandler != null) {
return authHandler;
}
AuthProvider authProvider = getAuthProviderFactory().getAuthProviderByName(name);
if (authProvider == null) {
return null;
}
SecuritySchemeDefinition securityScheme = this.securitySchemes.get(name);
if(securityScheme != null) {
switch (securityScheme.getType()) {
case "apiKey":
ApiKeyAuthDefinition apiKeyAuthDefinition = (ApiKeyAuthDefinition) securityScheme;
Location apiKeyLocation = Location.valueOf(apiKeyAuthDefinition.getIn().name());
authHandler = ApiKeyAuthHandler.create(authProvider, apiKeyLocation, apiKeyAuthDefinition.getName());
break;
case "basic":
authHandler = BasicAuthHandler.create(authProvider);
break;
case "oauth2":
vertxLogger.warn("OAuth2 authentication has not been implemented yet!");
break;
default:
vertxLogger.warn("SecurityScheme is not authorized : " + securityScheme.getType());
break;
}
if (authHandler != null) {
this.authHandlers.put(name, authHandler);
}
} else {
vertxLogger.warn("No securityScheme definition in swagger file for auth provider: " + name);
}
return authHandler;
}
示例14: toScheme
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
private static SecuritySchemeDefinition toScheme(
IssuerConfig issuerConfig, ImmutableSet<String> audiences) {
OAuth2Definition tokenDef = new OAuth2Definition().implicit("");
tokenDef.setVendorExtension("x-google-issuer", issuerConfig.getIssuer());
if (!com.google.common.base.Strings.isNullOrEmpty(issuerConfig.getJwksUri())) {
tokenDef.setVendorExtension("x-google-jwks_uri", issuerConfig.getJwksUri());
}
tokenDef.setVendorExtension("x-google-audiences", COMMA_JOINER.join(audiences));
return tokenDef;
}
示例15: getOrCreateSecurityDefinitionMap
import io.swagger.models.auth.SecuritySchemeDefinition; //导入依赖的package包/类
private static Map<String, SecuritySchemeDefinition> getOrCreateSecurityDefinitionMap(
Swagger swagger) {
Map<String, SecuritySchemeDefinition> securityDefinitions = swagger.getSecurityDefinitions();
if (securityDefinitions == null) {
securityDefinitions = new HashMap<>();
swagger.setSecurityDefinitions(securityDefinitions);
}
return securityDefinitions;
}