use of io.apicurio.datamodels.core.models.common.SecurityRequirement in project apicurio-data-models by Apicurio.
the class DeleteSecurityRequirementCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteSecurityRequirementCommand] Reverting.");
if (this.isNullOrUndefined(this._oldRequirement)) {
return;
}
ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
SecurityRequirement restoredRequirement = parent.createSecurityRequirement();
Library.readNode(this._oldRequirement, restoredRequirement);
parent.addSecurityRequirement(restoredRequirement);
}
use of io.apicurio.datamodels.core.models.common.SecurityRequirement in project apicurio-data-models by Apicurio.
the class DeleteAllSecurityRequirementsCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteAllSecurityRequirementsCommand] Reverting.");
if (ModelUtils.isDefined(this._oldSecurityRequirements) && this._oldSecurityRequirements.size() == 0) {
return;
}
ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
List<SecurityRequirement> requirements = parent.getSecurityRequirements();
if (this.isNullOrUndefined(requirements)) {
requirements = new ArrayList<>();
NodeCompat.setProperty(parent, Constants.PROP_SECURITY, requirements);
}
for (Object oldSecurityRequirement : this._oldSecurityRequirements) {
SecurityRequirement requirement = parent.createSecurityRequirement();
Library.readNode(oldSecurityRequirement, requirement);
requirements.add(requirement);
}
}
use of io.apicurio.datamodels.core.models.common.SecurityRequirement in project apicurio-data-models by Apicurio.
the class SecurityRequirementUniquenessValidationRule method visitSecurityRequirement.
/**
* @param node
* @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
*/
public void visitSecurityRequirement(SecurityRequirement node) {
ISecurityRequirementParent parent = (ISecurityRequirementParent) node.parent();
List<SecurityRequirement> securityRequirements = parent.getSecurityRequirements();
if (securityRequirements.size() <= 1) {
return;
}
if (checkForDuplicates(node, securityRequirements)) {
this.report(node, Constants.PROP_SECURITY, map("securityReq", node.getSecurityRequirementNames().toString()));
}
}
use of io.apicurio.datamodels.core.models.common.SecurityRequirement in project apicurio-data-models by Apicurio.
the class ReplaceSecurityRequirementCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[ReplaceSecurityRequirementCommand] Reverting.");
if (!this._replaced) {
return;
}
ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
SecurityRequirement replacementRequirement = parent.createSecurityRequirement();
Library.readNode(this._newRequirement, replacementRequirement);
int idx = this.indexOfRequirement(parent.getSecurityRequirements(), replacementRequirement);
if (idx == -1) {
return;
}
SecurityRequirement originalRequirement = parent.createSecurityRequirement();
Library.readNode(this._oldRequirement, originalRequirement);
parent.getSecurityRequirements().set(idx, originalRequirement);
}
use of io.apicurio.datamodels.core.models.common.SecurityRequirement 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);
}
Aggregations