Java Code Examples for io.swagger.v3.oas.models.Components#getSecuritySchemes()

The following examples show how to use io.swagger.v3.oas.models.Components#getSecuritySchemes() . 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: RefPointer.java    From openapi-diff with Apache License 2.0 6 votes vote down vote up
private Map<String, T> getMap(Components components) {
  switch (refType) {
    case REQUEST_BODIES:
      return (Map<String, T>) components.getRequestBodies();
    case RESPONSES:
      return (Map<String, T>) components.getResponses();
    case PARAMETERS:
      return (Map<String, T>) components.getParameters();
    case SCHEMAS:
      return (Map<String, T>) components.getSchemas();
    case HEADERS:
      return (Map<String, T>) components.getHeaders();
    case SECURITY_SCHEMES:
      return (Map<String, T>) components.getSecuritySchemes();
    default:
      throw new IllegalArgumentException("Not mapped for refType: " + refType);
  }
}
 
Example 2
Source File: OAS3Parser.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method returns the boolean value which checks whether the swagger is included default security scheme or not
 *
 * @param swaggerContent resource json
 * @return boolean
 * @throws APIManagementException
 */
private boolean isDefaultGiven(String swaggerContent) throws APIManagementException {
    OpenAPI openAPI = getOpenAPI(swaggerContent);

    Components components = openAPI.getComponents();
    if (components == null) {
        return false;
    }
    Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
    if (securitySchemes == null) {
        return false;
    }
    SecurityScheme checkDefault = openAPI.getComponents().getSecuritySchemes().get(OPENAPI_SECURITY_SCHEMA_KEY);
    if (checkDefault == null) {
        return false;
    }
    return true;
}
 
Example 3
Source File: PythonAbstractConnexionServerCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private void addSecurityExtensions(OpenAPI openAPI) {
    Components components = openAPI.getComponents();
    if (components != null && components.getSecuritySchemes() != null) {
        Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
        for (String securityName : securitySchemes.keySet()) {
            SecurityScheme securityScheme = securitySchemes.get(securityName);
            String baseFunctionName = controllerPackage + ".security_controller_.";
            switch (securityScheme.getType()) {
                case APIKEY:
                    addSecurityExtension(securityScheme, "x-apikeyInfoFunc", baseFunctionName + "info_from_" + securityName);
                    break;
                case HTTP:
                    if ("basic".equals(securityScheme.getScheme())) {
                        addSecurityExtension(securityScheme, "x-basicInfoFunc", baseFunctionName + "info_from_" + securityName);
                    } else if ("bearer".equals(securityScheme.getScheme())) {
                        addSecurityExtension(securityScheme, "x-bearerInfoFunc", baseFunctionName + "info_from_" + securityName);
                    }
                    break;
                case OPENIDCONNECT:
                    LOGGER.warn("Security type " + securityScheme.getType().toString() + " is not supported by connextion yet");
                case OAUTH2:
                    addSecurityExtension(securityScheme, "x-tokenInfoFunc", baseFunctionName + "info_from_" + securityName);
                    addSecurityExtension(securityScheme, "x-scopeValidateFunc", baseFunctionName + "validate_scope_" + securityName);
                    break;
                default:
                    LOGGER.warn("Unknown security type " + securityScheme.getType().toString());
            }
        }
    }
}
 
Example 4
Source File: ComponentsSecuritySchemesValuesValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String, SecurityScheme> getMapProperty(Components components) {
  return components.getSecuritySchemes();
}
 
Example 5
Source File: ComponentsSecuritySchemesKeysValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<String, ?> getMapProperty(Components components) {
  return components.getSecuritySchemes();
}
 
Example 6
Source File: OAS3Parser.java    From carbon-apimgt with Apache License 2.0 3 votes vote down vote up
/**
 * This is to avoid removing the `scopes` field of default security scheme when there are no scopes present. This
 * will set an empty scope object there.
 *
 *   securitySchemes:
 *     default:
 *       type: oauth2
 *       flows:
 *         implicit:
 *           authorizationUrl: 'https://test.com'
 *           scopes: {}
 *           x-scopes-bindings: {}
 *
 * @param swagger OpenAPI object
 */
private void checkAndSetEmptyScope(OpenAPI swagger) {
    Components comp = swagger.getComponents();
    Map<String, SecurityScheme> securitySchemeMap;
    SecurityScheme securityScheme;
    OAuthFlows oAuthFlows;
    OAuthFlow implicitFlow;
    if (comp != null && (securitySchemeMap = comp.getSecuritySchemes()) != null &&
            (securityScheme = securitySchemeMap.get(OPENAPI_SECURITY_SCHEMA_KEY)) != null &&
            (oAuthFlows = securityScheme.getFlows()) != null &&
            (implicitFlow = oAuthFlows.getImplicit()) != null && implicitFlow.getScopes() == null) {
        implicitFlow.setScopes(new Scopes());
    }
}