Java Code Examples for io.swagger.v3.oas.models.security.SecurityRequirement#addList()
The following examples show how to use
io.swagger.v3.oas.models.security.SecurityRequirement#addList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityParser.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Gets security requirements. * * @param securityRequirementsApi the security requirements api * @return the security requirements */ public Optional<List<SecurityRequirement>> getSecurityRequirements( io.swagger.v3.oas.annotations.security.SecurityRequirement[] securityRequirementsApi) { if (securityRequirementsApi == null || securityRequirementsApi.length == 0) return Optional.empty(); List<SecurityRequirement> securityRequirements = new ArrayList<>(); for (io.swagger.v3.oas.annotations.security.SecurityRequirement securityRequirementApi : securityRequirementsApi) { if (StringUtils.isBlank(securityRequirementApi.name())) continue; SecurityRequirement securityRequirement = new SecurityRequirement(); if (securityRequirementApi.scopes().length > 0) securityRequirement.addList(securityRequirementApi.name(), Arrays.asList(securityRequirementApi.scopes())); else securityRequirement.addList(securityRequirementApi.name()); securityRequirements.add(securityRequirement); } if (securityRequirements.isEmpty()) return Optional.empty(); return Optional.of(securityRequirements); }
Example 2
Source File: ProtoOpenAPI.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * Add Oauth2 security requirement to the operation/API. * If {@link Operation} object is null, security requirement is added to the API. * * @param operation {@link Operation} object * @param scopes array of scopes */ private void addOauth2SecurityRequirement(Operation operation, String[] scopes) { //if Oauth2 is not available as a security scheme, adding scopes would be meaningless. if (!isOauth2Enabled) { if (scopes != null && scopes.length > 0 && !scopes[0].isEmpty()) { throw new CLIRuntimeException("Scopes cannot be added if \"oauth2\" is not provided as security type."); } } SecurityRequirement oauth2Req = new SecurityRequirement(); //Since the scopes are not known at the start, the security scheme should be updated with newly identified //scopes as proceed if (scopes != null) { for (String scope : scopes) { addScopeToSchema(scope); } oauth2Req.addList(OAUTH2_SCHEME, Arrays.asList(scopes)); } else { oauth2Req.addList(OAUTH2_SCHEME); } if (operation == null) { openAPI.addSecurityItem(oauth2Req); } else { operation.addSecurityItem(oauth2Req); } }
Example 3
Source File: ProtoOpenAPI.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * Add Basic Auth security requirement to the operation/API. * If {@link Operation} object is null, security requirement is added to the API. * * @param operation {@link Operation} object */ private void addBasicAuthSecurityRequirement(Operation operation) { if (!isBasicAuthEnabled) { return; } if (openAPI.getComponents().getSecuritySchemes().get(BASIC_SCHEME) != null) { SecurityRequirement basicAuthReq = new SecurityRequirement(); basicAuthReq.addList(BASIC_SCHEME); if (operation == null) { openAPI.addSecurityItem(basicAuthReq); } else { operation.addSecurityItem(basicAuthReq); } } }
Example 4
Source File: ProtoOpenAPI.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * Add APIKey security requirement to the operation/API. * If {@link Operation} object is null, security requirement is added to the API. * * @param operation {@link Operation} object */ private void addAPIKeySecurityRequirement(Operation operation) { if (!isAPIKeyEnabled) { return; } if (openAPI.getComponents().getSecuritySchemes().get(APIKEY_SCHEME) != null) { SecurityRequirement apikeyReq = new SecurityRequirement(); apikeyReq.addList(APIKEY_SCHEME); if (operation == null) { openAPI.addSecurityItem(apikeyReq); } else { operation.addSecurityItem(apikeyReq); } } }
Example 5
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 5 votes |
private Operation createPostOperation(MethodDeclaration methodDeclaration) { Operation post = new Operation(); SecurityRequirement securityItem = new SecurityRequirement(); securityItem.addList(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME); post.addSecurityItem(securityItem); methodDeclaration.getJavadoc().ifPresent(javadoc -> post .setDescription(javadoc.getDescription().toText())); return post; }
Example 6
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 5 votes |
public List<SecurityRequirement> getSecurityRequirementsList(ArrayNode nodes, String location, ParseResult result) { if (nodes == null) return null; List<SecurityRequirement> securityRequirements = new ArrayList<>(); for (JsonNode node : nodes) { if (node.getNodeType().equals(JsonNodeType.OBJECT)) { SecurityRequirement securityRequirement = new SecurityRequirement(); Set<String> keys = getKeys((ObjectNode) node); if (keys.size() == 0){ securityRequirements.add(securityRequirement); }else { for (String key : keys) { if (key != null) { JsonNode value = node.get(key); if (key != null && JsonNodeType.ARRAY.equals(value.getNodeType())) { ArrayNode arrayNode = (ArrayNode) value; List<String> scopes = Stream .generate(arrayNode.elements()::next) .map((n) -> n.asText()) .limit(arrayNode.size()) .collect(Collectors.toList()); securityRequirement.addList(key, scopes); } } } if (securityRequirement.size() > 0) { securityRequirements.add(securityRequirement); } } } } return securityRequirements; }