Search in sources :

Example 1 with SecurityScheme

use of io.apicurio.datamodels.core.models.common.SecurityScheme in project apicurio-data-models by Apicurio.

the class ChangeSecuritySchemeCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangeSecuritySchemeCommand] Executing.");
    this._oldScheme = null;
    SecurityScheme scheme = this.getSchemeFromDocument(document);
    if (this.isNullOrUndefined(scheme)) {
        return;
    }
    // Back up the old scheme info (for undo)
    this._oldScheme = Library.writeNode(scheme);
    // Replace with new scheme info
    this.replaceSchemeWith(scheme, this._schemeObj);
}
Also used : SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme)

Example 2 with SecurityScheme

use of io.apicurio.datamodels.core.models.common.SecurityScheme in project apicurio-data-models by Apicurio.

the class RenameSecuritySchemeCommand method _doSecuritySchemeRename.

/**
 * Does the work of renaming a path from one name to another.
 * @param document
 * @param from
 * @param to
 * @private
 */
private void _doSecuritySchemeRename(Document document, String from, String to) {
    SecurityScheme scheme = null;
    // Different place to find the security scheme depending on the version.
    if (document.getDocumentType() == DocumentType.openapi2) {
        Oas20Document doc20 = (Oas20Document) document;
        if (ModelUtils.isDefined(doc20.securityDefinitions)) {
            // If the "to" scheme already exists, do nothing!
            if (ModelUtils.isDefined(doc20.securityDefinitions.getSecurityScheme(to))) {
                return;
            }
            scheme = doc20.securityDefinitions.removeSecurityScheme(from);
        }
    } else if (document.getDocumentType() == DocumentType.openapi3) {
        Oas30Document doc30 = (Oas30Document) document;
        if (ModelUtils.isDefined(doc30.components)) {
            // If the "to" scheme already exists, do nothing!
            if (!this.isNullOrUndefined(doc30.components.getSecurityScheme(to))) {
                return;
            }
            scheme = doc30.components.removeSecurityScheme(from);
        }
    } else {
        Aai20Document aai20Document = (Aai20Document) document;
        if (ModelUtils.isDefined(aai20Document.components)) {
            // If the "to" scheme already exists, do nothing!
            if (!this.isNullOrUndefined(aai20Document.components.getSecurityScheme(to))) {
                return;
            }
            scheme = aai20Document.components.removeSecurityScheme(from);
        }
    }
    // If we didn't find a scheme with the "from" name, then nothing to do.
    if (this.isNullOrUndefined(scheme)) {
        return;
    }
    // Now we have the scheme - rename it!
    scheme.rename(to);
    if (document.getDocumentType() == DocumentType.openapi2) {
        Oas20Document doc20 = (Oas20Document) document;
        doc20.securityDefinitions.addSecurityScheme(to, (Oas20SecurityScheme) scheme);
    } else if (document.getDocumentType() == DocumentType.openapi3) {
        Oas30Document doc30 = (Oas30Document) document;
        doc30.components.addSecurityScheme(to, (Oas30SecurityScheme) scheme);
    } else {
        Aai20Document aai20Document = (Aai20Document) document;
        aai20Document.components.addSecurityScheme(to, (Aai20SecurityScheme) scheme);
    }
    // Now find all security requirements that reference the scheme and change them too.
    VisitorUtil.visitTree(document, new CombinedVisitorAdapter() {

        @Override
        public void visitSecurityRequirement(SecurityRequirement node) {
            List<String> scopes = node.removeSecurityRequirementItem(from);
            if (ModelUtils.isDefined(scopes)) {
                node.addSecurityRequirementItem(to, scopes);
            }
        }
    }, TraverserDirection.down);
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Aai20SecurityScheme(io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) CombinedVisitorAdapter(io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter) List(java.util.List) SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Aai20SecurityScheme(io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme) Oas20SecurityScheme(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme) SecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)

Example 3 with SecurityScheme

use of io.apicurio.datamodels.core.models.common.SecurityScheme in project apicurio-data-models by Apicurio.

the class ChangeSecuritySchemeCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[ChangeSecuritySchemeCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldScheme)) {
        return;
    }
    SecurityScheme scheme = this.getSchemeFromDocument(document);
    if (this.isNullOrUndefined(scheme)) {
        return;
    }
    this.nullScheme(scheme);
    Library.readNode(this._oldScheme, scheme);
}
Also used : SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme)

Example 4 with SecurityScheme

use of io.apicurio.datamodels.core.models.common.SecurityScheme in project apicurio-data-models by Apicurio.

the class OasSecurityRequirementScopesMustBeEmptyRule method visitSecurityRequirement.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
 */
@Override
public void visitSecurityRequirement(SecurityRequirement node) {
    List<String> allowedTypes = new ArrayList<>();
    allowedTypes.add("oauth2");
    String options = "\"oauth2\"";
    if (node.ownerDocument().getDocumentType() == DocumentType.openapi3) {
        allowedTypes.add("openIdConnect");
        options = "\"oauth2\" or \"openIdConnect\"";
    }
    List<String> snames = node.getSecurityRequirementNames();
    for (String sname : snames) {
        SecurityScheme scheme = findSecurityScheme((OasDocument) node.ownerDocument(), sname);
        if (hasValue(scheme)) {
            if (allowedTypes.indexOf(scheme.type) == -1) {
                List<String> scopes = node.getScopes(sname);
                this.reportIfInvalid(hasValue(scopes) && scopes.size() == 0, node, null, map("sname", sname, "options", options));
            }
        }
    }
    ;
}
Also used : ArrayList(java.util.ArrayList) SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme)

Example 5 with SecurityScheme

use of io.apicurio.datamodels.core.models.common.SecurityScheme in project syndesis by syndesisio.

the class OpenApiPropertyGenerator method vendorExtension.

private static Optional<ConfigurationProperty> vendorExtension(final SecurityScheme definition, final ConfigurationProperty template, final String name) {
    final Collection<Extension> vendorExtensions = definition.getExtensions();
    if (vendorExtensions == null) {
        return empty();
    }
    final Optional<Extension> maybeExtension = vendorExtensions.stream().filter(extension -> name.equals(extension.name)).findFirst();
    if (!maybeExtension.isPresent()) {
        return empty();
    }
    final ConfigurationProperty property = new ConfigurationProperty.Builder().createFrom(template).defaultValue(String.valueOf(maybeExtension.get().value)).build();
    return Optional.of(property);
}
Also used : Extension(io.apicurio.datamodels.core.models.Extension) Optional.empty(java.util.Optional.empty) Optional.ofNullable(java.util.Optional.ofNullable) URISyntaxException(java.net.URISyntaxException) Collection(java.util.Collection) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme) List(java.util.List) Extension(io.apicurio.datamodels.core.models.Extension) Map(java.util.Map) OasModelHelper(io.syndesis.server.api.generator.openapi.util.OasModelHelper) Optional(java.util.Optional) URI(java.net.URI) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) Collections(java.util.Collections) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty)

Aggregations

SecurityScheme (io.apicurio.datamodels.core.models.common.SecurityScheme)5 List (java.util.List)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Aai20SecurityScheme (io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme)1 CombinedVisitorAdapter (io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter)1 Extension (io.apicurio.datamodels.core.models.Extension)1 SecurityRequirement (io.apicurio.datamodels.core.models.common.SecurityRequirement)1 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)1 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)1 Oas20SecurityScheme (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)1 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)1 Oas30SecurityScheme (io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)1 OasModelHelper (io.syndesis.server.api.generator.openapi.util.OasModelHelper)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1