From 7558304702485a7b44f58a2296b9962f4423996a Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Tue, 29 Oct 2024 21:32:14 -0400 Subject: [PATCH] Incremented minor version to 2.3.0. Integrated code changes from metaschema-java 2.0.0 and liboscal-java 5.0.0 changes. --- pom.xml | 22 ++++++-- .../secauto/oscal/tools/cli/core/CLI.java | 21 ++++---- .../AbstractOscalValidationCommand.java | 54 +++++++++++-------- .../core/commands/AbstractResolveCommand.java | 10 ++-- .../cli/core/commands/ConvertCommand.java | 1 + .../commands/ListAllowedValuesCommand.java | 18 +++---- .../cli/core/commands/ValidateCommand.java | 12 +++-- .../assessmentplan/ValidateSubcommand.java | 12 +++-- .../assessmentresults/ValidateSubcommand.java | 12 +++-- .../core/commands/catalog/CatalogCommand.java | 1 - .../commands/catalog/ValidateSubcommand.java | 12 +++-- .../ComponentDefinitionCommand.java | 1 - .../ValidateSubcommand.java | 12 +++-- .../PlanOfActionsAndMilestonesCommand.java | 1 - .../commands/poam/ValidateSubcommand.java | 12 +++-- .../core/commands/profile/ProfileCommand.java | 1 - .../commands/profile/ValidateSubcommand.java | 12 +++-- .../core/commands/ssp/ValidateSubcommand.java | 12 +++-- 18 files changed, 127 insertions(+), 99 deletions(-) diff --git a/pom.xml b/pom.xml index 3ae8439..9ee2266 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ dev.metaschema.oscal oscal-cli-enhanced - 2.2.1-SNAPSHOT + 2.3.0-SNAPSHOT jar @@ -58,8 +58,8 @@ - 1.2.0 - 4.2.0 + 2.0.0-SNAPSHOT + 5.0.0-SNAPSHOT https://oscal-cli.metaschema.dev @@ -114,6 +114,11 @@ pom import + + org.apache.xmlbeans + xmlbeans + ${dependency.xmlbeans.version} + @@ -184,7 +189,6 @@ org.apache.xmlbeans xmlbeans - ${dependency.xmlbeans.version} com.github.erosb @@ -287,6 +291,15 @@ maven-pmd-plugin + pmd-analyze + + pmd + + + net.sourceforge.pmd.renderers.SarifRenderer + + + pmd-verify check @@ -296,7 +309,6 @@ true true - sarif diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java index 5577cb9..c926b87 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/CLI.java @@ -9,8 +9,8 @@ import gov.nist.secauto.metaschema.cli.processor.ExitStatus; import gov.nist.secauto.metaschema.core.MetaschemaJavaVersion; import gov.nist.secauto.metaschema.core.model.MetaschemaVersion; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.IVersionInfo; -import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.LibOscalVersion; import gov.nist.secauto.oscal.lib.OscalVersion; import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand; @@ -43,17 +43,14 @@ public static void main(String[] args) { @NonNull public static ExitStatus runCli(String... args) { - @SuppressWarnings("serial") Map versions = ObjectUtils.notNull( - new LinkedHashMap<>() { - { - put(CLIProcessor.COMMAND_VERSION, new OscalCliVersion()); - put("https://github.com/usnistgov/liboscal-java", new LibOscalVersion()); - put("https://github.com/usnistgov/OSCAL", new OscalVersion()); - put("https://github.com/usnistgov/metaschema-java", new MetaschemaJavaVersion()); - put("https://github.com/usnistgov/metaschema", new MetaschemaVersion()); - } - }); - CLIProcessor processor = new CLIProcessor("oscal-cli", versions); + @SuppressWarnings("PMD.UseConcurrentHashMap") Map versions = new LinkedHashMap<>(); + versions.put(CLIProcessor.COMMAND_VERSION, new OscalCliVersion()); + versions.put("https://github.com/usnistgov/liboscal-java", new LibOscalVersion()); + versions.put("https://github.com/usnistgov/OSCAL", new OscalVersion()); + versions.put("https://github.com/usnistgov/metaschema-java", new MetaschemaJavaVersion()); + versions.put("https://github.com/usnistgov/metaschema", new MetaschemaVersion()); + + CLIProcessor processor = new CLIProcessor("oscal-cli", CollectionUtil.unmodifiableMap(versions)); processor.addCommandHandler(new CatalogCommand()); processor.addCommandHandler(new ProfileCommand()); processor.addCommandHandler(new ComponentDefinitionCommand()); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java index e491b87..0466ec5 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractOscalValidationCommand.java @@ -8,40 +8,43 @@ import gov.nist.secauto.metaschema.cli.commands.AbstractValidateContentCommand; import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; +import gov.nist.secauto.metaschema.core.model.IModule; +import gov.nist.secauto.metaschema.core.model.MetaschemaException; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; -import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; -import gov.nist.secauto.metaschema.core.util.CollectionUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.databind.IBindingContext; +import gov.nist.secauto.metaschema.databind.IBindingContext.ISchemaValidationProvider; import gov.nist.secauto.oscal.lib.OscalBindingContext; +import gov.nist.secauto.oscal.lib.model.OscalCompleteModule; import org.apache.commons.cli.CommandLine; import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.net.URL; -import java.util.List; import java.util.Set; -import javax.xml.transform.Source; - import edu.umd.cs.findbugs.annotations.NonNull; public abstract class AbstractOscalValidationCommand extends AbstractValidateContentCommand { @NonNull - protected abstract List getOscalXmlSchemas() throws IOException; + protected abstract XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException; @NonNull - protected abstract JSONObject getOscalJsonSchema() throws IOException; + protected abstract JsonSchemaContentValidator getOscalJsonSchema() throws IOException; @Override public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine commandLine) { - return new OscalCommandExecutor(callingContext, commandLine); + return new AbstractOscalValidationCommand.OscalCommandExecutor(callingContext, commandLine); } protected class OscalCommandExecutor - extends AbstractValidationCommandExecutor { + extends AbstractValidateContentCommand.AbstractValidationCommandExecutor + implements ISchemaValidationProvider { protected OscalCommandExecutor( @NonNull CallingContext callingContext, @@ -51,28 +54,37 @@ protected OscalCommandExecutor( @Override protected IBindingContext getBindingContext(@NonNull Set constraintSets) { - IBindingContext retval; - if (constraintSets.isEmpty()) { - retval = OscalBindingContext.instance(); - } else { - ExternalConstraintsModulePostProcessor postProcessor - = new ExternalConstraintsModulePostProcessor(constraintSets); - - retval = new OscalBindingContext(CollectionUtil.singletonList(postProcessor)); - } - return retval; + return OscalBindingContext.builder() + .constraintSet(constraintSets) + .build(); } @Override @NonNull - public List getXmlSchemas(URL targetResource) throws IOException { + public XmlSchemaContentValidator getXmlSchemas(URL targetResource, IBindingContext bindingContext) + throws IOException, SAXException { return getOscalXmlSchemas(); } @Override @NonNull - public JSONObject getJsonSchema(JSONObject json) throws IOException { + public JsonSchemaContentValidator getJsonSchema(JSONObject json, IBindingContext bindingContext) + throws IOException { return getOscalJsonSchema(); } + + @NonNull + protected ISchemaValidationProvider getSchemaValidationProvider( + @NonNull IModule module, + @NonNull CommandLine commandLine, + @NonNull IBindingContext bindingContext) { + return this; + } + + @Override + protected IModule getModule(CommandLine commandLine, IBindingContext bindingContext) + throws IOException, MetaschemaException { + return bindingContext.registerModule(OscalCompleteModule.class); + } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java index 57b776d..59fda40 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/AbstractResolveCommand.java @@ -19,6 +19,7 @@ import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem; import gov.nist.secauto.metaschema.core.util.CustomCollectors; import gov.nist.secauto.metaschema.core.util.ObjectUtils; +import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.io.DeserializationFeature; import gov.nist.secauto.metaschema.databind.io.Format; import gov.nist.secauto.metaschema.databind.io.IBoundLoader; @@ -164,7 +165,8 @@ protected ExitStatus executeCommand( List extraArgs = cmdLine.getArgList(); Path source = resolvePathAgainstCWD(ObjectUtils.notNull(Paths.get(extraArgs.get(0)))); - IBoundLoader loader = OscalBindingContext.instance().newBoundLoader(); + IBindingContext bindingContext = OscalBindingContext.instance(); + IBoundLoader loader = bindingContext.newBoundLoader(); loader.disableFeature(DeserializationFeature.DESERIALIZE_VALIDATE_CONSTRAINTS); Format asFormat; @@ -258,8 +260,7 @@ protected ExitStatus executeCommand( // this is a profile DynamicContext dynamicContext = new DynamicContext(document.getStaticContext()); dynamicContext.setDocumentLoader(loader); - ProfileResolver resolver = new ProfileResolver(); - resolver.setDynamicContext(dynamicContext); + ProfileResolver resolver = new ProfileResolver(dynamicContext); IDocumentNodeItem resolvedProfile; try { @@ -276,8 +277,7 @@ protected ExitStatus executeCommand( // ((IBoundXdmNodeItem)resolvedProfile).validate(validator); // validator.finalizeValidation(); - ISerializer serializer - = OscalBindingContext.instance().newSerializer(toFormat, Catalog.class); + ISerializer serializer = bindingContext.newSerializer(toFormat, Catalog.class); try { if (destination == null) { @SuppressWarnings({ "resource", "PMD.CloseResource" }) PrintStream stdOut = ObjectUtils.notNull(System.out); diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java index 4333a09..4cd573a 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ConvertCommand.java @@ -60,6 +60,7 @@ protected void handleConversion(URI source, Format toFormat, Writer writer, IBou Class boundClass; IBoundObject object; try (InputStream is = source.toURL().openStream()) { + assert is != null; FormatDetector.Result formatResult = loader.detectFormat(is); Format sourceformat = formatResult.getFormat(); try (InputStream fis = formatResult.getDataStream()) { diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java index 3620a9d..612c3c5 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ListAllowedValuesCommand.java @@ -31,13 +31,11 @@ import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValue; import gov.nist.secauto.metaschema.core.model.constraint.IAllowedValuesConstraint; import gov.nist.secauto.metaschema.core.model.constraint.IConstraintSet; -import gov.nist.secauto.metaschema.core.model.xml.ExternalConstraintsModulePostProcessor; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.metaschema.core.util.UriUtils; import gov.nist.secauto.metaschema.databind.IBindingContext; import gov.nist.secauto.metaschema.databind.model.IBoundModule; -import gov.nist.secauto.metaschema.databind.model.metaschema.BindingConstraintLoader; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.lib.model.OscalCompleteModule; import gov.nist.secauto.oscal.lib.model.util.AllowedValueCollectingNodeItemVisitor; @@ -141,6 +139,7 @@ public ICommandExecutor newExecutor(CallingContext callingContext, CommandLine c */ @SuppressWarnings({ "PMD.OnlyOneReturn", // readability + "PMD.AvoidCatchingGenericException" }) protected ExitStatus executeCommand( @NonNull CallingContext callingContext, @@ -181,7 +180,7 @@ protected ExitStatus executeCommand( Set constraintSets; if (cmdLine.hasOption(CONSTRAINTS_OPTION)) { - IConstraintLoader constraintLoader = new BindingConstraintLoader(IBindingContext.instance()); + IConstraintLoader constraintLoader = IBindingContext.getConstraintLoader(); constraintSets = new LinkedHashSet<>(); String[] args = cmdLine.getOptionValues(CONSTRAINTS_OPTION); for (String arg : args) { @@ -199,14 +198,9 @@ protected ExitStatus executeCommand( IBindingContext bindingContext; try { - if (constraintSets.isEmpty()) { - bindingContext = OscalBindingContext.instance(); - } else { - ExternalConstraintsModulePostProcessor postProcessor - = new ExternalConstraintsModulePostProcessor(constraintSets); - - bindingContext = new OscalBindingContext(CollectionUtil.singletonList(postProcessor)); - } + bindingContext = OscalBindingContext.builder() + .constraintSet(constraintSets) + .build(); } catch (Exception ex) { return ExitCode.PROCESSING_ERROR .exitMessage("Unable to get binding context. " + ex.getMessage()) @@ -397,6 +391,6 @@ private static String metapath(@NonNull IDefinitionNodeItem item) { private static String metapath(@NonNull String path) { // remove position 1 predicates - return path.replaceAll("\\[1\\]", ""); + return path.replace("[1]", ""); } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java index 8103d92..3cf681d 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ValidateCommand.java @@ -7,11 +7,13 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -31,20 +33,20 @@ public String getDescription() { @Override @NonNull - public List getOscalXmlSchemas() throws IOException { + public XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-complete_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override @NonNull - public JSONObject getOscalJsonSchema() throws IOException { + public JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-complete_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java index cb8a7b8..b615d8d 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentplan/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-ap_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ap_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java index 0fd6901..5b91fa5 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/assessmentresults/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-ar_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ar_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java index 9e8bfc9..360557e 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/CatalogCommand.java @@ -31,5 +31,4 @@ public String getName() { public String getDescription() { return "Perform an operation on an OSCAL Catalog"; } - } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java index c8c0eac..e693406 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/catalog/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-catalog_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-catalog_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java index 1f1cdf8..3c7cf08 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ComponentDefinitionCommand.java @@ -27,5 +27,4 @@ public String getName() { public String getDescription() { return "Perform an operation on an OSCAL Component Definition"; } - } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java index bbcf6a0..aa868c0 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/componentdefinition/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-component-definition_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-component-definition_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java index d784b70..efd6911 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/PlanOfActionsAndMilestonesCommand.java @@ -27,5 +27,4 @@ public String getName() { public String getDescription() { return "Perform an operation on an OSCAL Plan of Actions and Milestones"; } - } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java index a00eced..62fb40e 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/poam/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -30,19 +32,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-poam_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-poam_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java index 68654e3..0633a9b 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ProfileCommand.java @@ -28,5 +28,4 @@ public String getName() { public String getDescription() { return "Perform an operation on an OSCAL Profile"; } - } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java index 9ccdd59..e269774 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/profile/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-profile_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-profile_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } } diff --git a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java index 72bf7dc..4e230ef 100644 --- a/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java +++ b/src/main/java/gov/nist/secauto/oscal/tools/cli/core/commands/ssp/ValidateSubcommand.java @@ -7,12 +7,14 @@ import gov.nist.secauto.metaschema.core.model.util.JsonUtil; import gov.nist.secauto.metaschema.core.model.util.XmlUtil; +import gov.nist.secauto.metaschema.core.model.validation.JsonSchemaContentValidator; +import gov.nist.secauto.metaschema.core.model.validation.XmlSchemaContentValidator; import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.ObjectUtils; import gov.nist.secauto.oscal.lib.OscalBindingContext; import gov.nist.secauto.oscal.tools.cli.core.commands.oscal.AbstractDeprecatedOscalValidationSubcommand; -import org.json.JSONObject; +import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; @@ -29,19 +31,19 @@ public String getDescription() { } @Override - protected List getOscalXmlSchemas() throws IOException { + protected XmlSchemaContentValidator getOscalXmlSchemas() throws IOException, SAXException { List retval = new LinkedList<>(); retval.add( XmlUtil.getStreamSource(ObjectUtils.requireNonNull( OscalBindingContext.class.getResource("/schema/xml/oscal-ssp_schema.xsd")))); - return CollectionUtil.unmodifiableList(retval); + return new XmlSchemaContentValidator(CollectionUtil.unmodifiableList(retval)); } @Override - protected JSONObject getOscalJsonSchema() throws IOException { + protected JsonSchemaContentValidator getOscalJsonSchema() throws IOException { try (InputStream is = ObjectUtils.requireNonNull( OscalBindingContext.class.getResourceAsStream("/schema/json/oscal-ssp_schema.json"))) { - return JsonUtil.toJsonObject(is); + return new JsonSchemaContentValidator(JsonUtil.toJsonObject(is)); } } }