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);
}
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);
}
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);
}
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));
}
}
}
;
}
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);
}
Aggregations