Skip to content

Commit

Permalink
Updating for latest metaschema-java snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed May 26, 2024
1 parent 64982cd commit bfb1d57
Show file tree
Hide file tree
Showing 23 changed files with 333 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ target/
pom.xml.releaseBackup
release.properties
.fbExcludeFilterFile
/.apt_generated/
2 changes: 1 addition & 1 deletion oscal
Submodule oscal updated 38 files
+9 −64 .github/workflows/periodic.yml
+1 −1 .github/workflows/release.yml
+2 −2 .github/workflows/status.yml
+8 −3 CONTRIBUTING.md
+1 −1 README.md
+3 −3 README_validations.md
+1 −2 build/.gitignore
+7 −51 build/Makefile
+6 −131 build/README.md
+1 −1 build/metaschema-xslt
+135 −34 build/package-lock.json
+1 −1 build/package.json
+0 −65 build/pom.xml
+0 −60 build/resolve-entities.xsl
+0 −38 build/xslt-runner.sh
+1 −1 decisions/0005-repository-reorganization.md
+0 −32 decisions/0006-source-metaschema-xxes.md
+1 −1 src/metaschema/oscal_assessment-common_metaschema.xml
+1 −1 src/metaschema/oscal_assessment-plan_metaschema.xml
+3 −3 src/metaschema/oscal_assessment-results_metaschema.xml
+2 −2 src/metaschema/oscal_catalog_metaschema.xml
+2 −2 src/metaschema/oscal_complete_metaschema.xml
+3 −3 src/metaschema/oscal_component_metaschema.xml
+1 −1 src/metaschema/oscal_control-common_metaschema.xml
+3 −3 src/metaschema/oscal_implementation-common_metaschema.xml
+18 −2 src/metaschema/oscal_metadata_metaschema.xml
+3 −3 src/metaschema/oscal_poam_metaschema.xml
+2 −2 src/metaschema/oscal_profile_metaschema.xml
+3 −3 src/metaschema/oscal_ssp_metaschema.xml
+3 −3 src/release/README.txt
+7 −3 src/release/content-upgrade/README.md
+1 −1 src/specifications/profile-resolution/profile-resolution-specml-requirements.xspec
+1 −1 src/specifications/profile-resolution/profile-resolution-specml-working.xml
+1 −1 src/specifications/profile-resolution/profile-resolution-specml.xml
+1 −1 src/specifications/profile-resolution/resolution-testing.xml
+1 −1 src/utils/resolver-pipeline/Makefile
+1 −1 src/utils/resolver-pipeline/oscal-profile-resolve.sh
+2 −4 versioning-and-branching.md
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@
<dependency.infinispan.version>13.0.10.Final</dependency.infinispan.version>
<dependency.jetbrains-annotation.version>23.0.0</dependency.jetbrains-annotation.version>
<dependency.jmock-junit5.version>2.12.0</dependency.jmock-junit5.version>
<dependency.log4j2.version>2.22.0</dependency.log4j2.version>
<dependency.log4j2.version>2.23.1</dependency.log4j2.version>
<dependency.saxon.version>12.3</dependency.saxon.version>
<dependency.spotbugs-annotations.version>4.7.3</dependency.spotbugs-annotations.version>
<dependency.spotbugs-annotations.version>4.8.3</dependency.spotbugs-annotations.version>
<dependency.xmlbeans.version>5.2.0</dependency.xmlbeans.version>
<dependency.xmlresolver.version>4.6.0</dependency.xmlresolver.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package gov.nist.secauto.oscal.lib;

import gov.nist.secauto.metaschema.core.metapath.StaticContext;
import gov.nist.secauto.metaschema.core.model.IModuleLoader;
import gov.nist.secauto.metaschema.databind.DefaultBindingContext;
import gov.nist.secauto.oscal.lib.model.AssessmentPlan;
Expand All @@ -44,15 +45,19 @@
import java.util.List;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class OscalBindingContext
extends DefaultBindingContext {
@NonNull
public static final String NS_OSCAL = "http://csrc.nist.gov/ns/oscal/1.0";
public static final StaticContext OSCAL_STATIC_METAPATH_CONTEXT = StaticContext.builder()
.defaultModelNamespace(OscalModelConstants.NS_URI_OSCAL)
.build();
@NonNull
private static final OscalBindingContext SINGLETON = new OscalBindingContext();

@NonNull
@SuppressFBWarnings(value = "SING_SINGLETON_GETTER_NOT_SYNCHRONIZED", justification = "class initialization")
public static OscalBindingContext instance() {
return SINGLETON;
}
Expand All @@ -63,6 +68,8 @@ public static OscalBindingContext instance() {
* @param modulePostProcessors
* a list of module post processors to call after loading a module
*/
@SuppressFBWarnings(value = "SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR",
justification = "public constructor allows customized use in specialized usecases")
public OscalBindingContext(@NonNull List<IModuleLoader.IModulePostProcessor> modulePostProcessors) {
super(modulePostProcessors);
registerBindingMatcher(Catalog.class);
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/gov/nist/secauto/oscal/lib/OscalModelConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Portions of this software was developed by employees of the National Institute
* of Standards and Technology (NIST), an agency of the Federal Government and is
* being made available as a public service. Pursuant to title 17 United States
* Code Section 105, works of NIST employees are not subject to copyright
* protection in the United States. This software may be subject to foreign
* copyright. Permission in the United States and in foreign countries, to the
* extent that NIST may hold copyright, to use, copy, modify, create derivative
* works, and distribute this software and its documentation without fee is hereby
* granted on a non-exclusive basis, provided that this notice and disclaimer
* of warranty appears in all copies.
*
* THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
* EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
* INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
* SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
* INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
* OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
* CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
* PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/

package gov.nist.secauto.oscal.lib;

import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.net.URI;

import javax.xml.namespace.QName;

import edu.umd.cs.findbugs.annotations.NonNull;

public final class OscalModelConstants {

@NonNull
public static final String NS_OSCAL = "http://csrc.nist.gov/ns/oscal/1.0";
@NonNull
public static final URI NS_URI_OSCAL = ObjectUtils.notNull(URI.create(NS_OSCAL));
@NonNull
public static final QName QNAME_METADATA = new QName(NS_OSCAL, "metadata");
@NonNull
public static final QName QNAME_BACK_MATTER = new QName(NS_OSCAL, "back-matter");
@NonNull
public static final QName QNAME_PROFILE = new QName(NS_OSCAL, "profile");
@NonNull
public static final QName QNAME_IMPORT = new QName(NS_OSCAL, "import");
@NonNull
public static final QName QNAME_TITLE = new QName(NS_OSCAL, "title");
@NonNull
public static final QName QNAME_PROP = new QName(NS_OSCAL, "prop");
@NonNull
public static final QName QNAME_LINK = new QName(NS_OSCAL, "link");
@NonNull
public static final QName QNAME_CITATION = new QName(NS_OSCAL, "citation");
@NonNull
public static final QName QNAME_TEXT = new QName(NS_OSCAL, "text");
@NonNull
public static final QName QNAME_PROSE = new QName(NS_OSCAL, "prose");
@NonNull
public static final QName QNAME_PARAM = new QName(NS_OSCAL, "param");
@NonNull
public static final QName QNAME_ROLE = new QName(NS_OSCAL, "role");
@NonNull
public static final QName QNAME_LOCATION = new QName(NS_OSCAL, "location");
@NonNull
public static final QName QNAME_PARTY = new QName(NS_OSCAL, "party");
@NonNull
public static final QName QNAME_GROUP = new QName(NS_OSCAL, "group");
@NonNull
public static final QName QNAME_CONTROL = new QName(NS_OSCAL, "control");

private OscalModelConstants() {
// disable construction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.ISequence;
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
import gov.nist.secauto.metaschema.core.metapath.MetapathException;
import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.core.metapath.function.IArgument;
Expand All @@ -43,19 +44,23 @@
import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.OscalBindingContext;
import gov.nist.secauto.oscal.lib.OscalModelConstants;
import gov.nist.secauto.oscal.lib.model.metadata.AbstractProperty;

import java.net.URI;
import java.util.List;

import javax.xml.namespace.QName;

import edu.umd.cs.findbugs.annotations.NonNull;

public final class HasOscalNamespace {
@NonNull
private static final QName NS_FLAG_QNAME = new QName("ns");
@NonNull
static final IFunction SIGNATURE_ONE_ARG = IFunction.builder()
.name("has-oscal-namespace")
.namespace(OscalBindingContext.NS_OSCAL)
.namespace(OscalModelConstants.NS_OSCAL)
.argument(IArgument.builder()
.name("namespace")
.type(IStringItem.class)
Expand All @@ -73,7 +78,48 @@ public final class HasOscalNamespace {
@NonNull
static final IFunction SIGNATURE_TWO_ARGS = IFunction.builder()
.name("has-oscal-namespace")
.namespace(OscalBindingContext.NS_OSCAL)
.namespace(OscalModelConstants.NS_OSCAL)
.argument(IArgument.builder()
.name("propOrPart")
.type(IAssemblyNodeItem.class)
.one()
.build())
.argument(IArgument.builder()
.name("namespace")
.type(IStringItem.class)
.oneOrMore()
.build())
.allowUnboundedArity(true)
.focusIndependent()
.contextIndependent()
.deterministic()
.returnType(IBooleanItem.class)
.returnOne()
.functionHandler(HasOscalNamespace::executeTwoArg)
.build();

@NonNull
static final IFunction SIGNATURE_ONE_ARG_METAPATH = IFunction.builder()
.name("has-oscal-namespace")
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS)
.argument(IArgument.builder()
.name("namespace")
.type(IStringItem.class)
.oneOrMore()
.build())
.allowUnboundedArity(true)
.returnType(IBooleanItem.class)
.focusDependent()
.contextIndependent()
.deterministic()
.returnOne()
.functionHandler(HasOscalNamespace::executeOneArg)
.build();

@NonNull
static final IFunction SIGNATURE_TWO_ARGS_METAPATH = IFunction.builder()
.name("has-oscal-namespace")
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS)
.argument(IArgument.builder()
.name("propOrPart")
.type(IAssemblyNodeItem.class)
Expand Down Expand Up @@ -139,7 +185,7 @@ public static ISequence<?> executeTwoArg(
ObjectUtils.notNull(arguments.get(0)));

// always not null, since the first item is required
IAssemblyNodeItem node = FunctionUtils.requireFirstItem(nodeSequence, true);
IAssemblyNodeItem node = FunctionUtils.asType(ObjectUtils.requireNonNull(nodeSequence.getFirstItem(true)));
return ISequence.of(hasNamespace(node, namespaceArgs));
}

Expand All @@ -156,11 +202,11 @@ public static IBooleanItem hasNamespace(

URI nodeNamespace = null;
// get the "ns" flag value
IFlagNodeItem ns = propOrPart.getFlagByName("ns");
IFlagNodeItem ns = propOrPart.getFlagByName(NS_FLAG_QNAME);
if (ns == null) {
// check if the node actually has a "ns" flag
IAssemblyDefinition definition = propOrPart.getDefinition();
IFlagInstance flag = definition.getFlagInstanceByName("ns");
IFlagInstance flag = definition.getFlagInstanceByName(NS_FLAG_QNAME);
if (flag == null) {
throw new MetapathException(
String.format(
Expand All @@ -180,7 +226,7 @@ public static IBooleanItem hasNamespace(
}

String nodeNamespaceString = AbstractProperty.normalizeNamespace(nodeNamespace).toString();
return IBooleanItem.valueOf(namespaces.asStream()
return IBooleanItem.valueOf(namespaces.stream()
.map(node -> nodeNamespaceString.equals(node.asString()))
.anyMatch(bool -> bool));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public OscalFunctionLibrary() {
registerFunction(ResolveProfile.SIGNATURE_ONE_ARG);
registerFunction(HasOscalNamespace.SIGNATURE_ONE_ARG);
registerFunction(HasOscalNamespace.SIGNATURE_TWO_ARGS);

// for backwards compatibility with no function namespace
registerFunction(ResolveProfile.SIGNATURE_NO_ARG_METAPATH);
registerFunction(ResolveProfile.SIGNATURE_ONE_ARG_METAPATH);
registerFunction(HasOscalNamespace.SIGNATURE_ONE_ARG_METAPATH);
registerFunction(HasOscalNamespace.SIGNATURE_TWO_ARGS_METAPATH);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.ISequence;
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants;
import gov.nist.secauto.metaschema.core.metapath.MetapathException;
import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils;
import gov.nist.secauto.metaschema.core.metapath.function.IArgument;
Expand All @@ -36,7 +37,7 @@
import gov.nist.secauto.metaschema.core.metapath.item.node.IDocumentNodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.OscalBindingContext;
import gov.nist.secauto.oscal.lib.OscalModelConstants;
import gov.nist.secauto.oscal.lib.model.Catalog;
import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionException;
import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolver;
Expand All @@ -51,7 +52,7 @@ public final class ResolveProfile {
@NonNull
static final IFunction SIGNATURE_NO_ARG = IFunction.builder()
.name("resolve-profile")
.namespace(OscalBindingContext.NS_OSCAL)
.namespace(OscalModelConstants.NS_OSCAL)
.returnType(INodeItem.class)
.focusDependent()
.contextDependent()
Expand All @@ -63,7 +64,36 @@ public final class ResolveProfile {
@NonNull
static final IFunction SIGNATURE_ONE_ARG = IFunction.builder()
.name("resolve-profile")
.namespace(OscalBindingContext.NS_OSCAL)
.namespace(OscalModelConstants.NS_OSCAL)
.argument(IArgument.builder()
.name("profile")
.type(INodeItem.class)
.zeroOrOne()
.build())
.focusDependent()
.contextDependent()
.deterministic()
.returnType(INodeItem.class)
.returnOne()
.functionHandler(ResolveProfile::executeOneArg)
.build();

@NonNull
static final IFunction SIGNATURE_NO_ARG_METAPATH = IFunction.builder()
.name("resolve-profile")
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS)
.returnType(INodeItem.class)
.focusDependent()
.contextDependent()
.deterministic()
.returnOne()
.functionHandler(ResolveProfile::executeNoArg)
.build();

@NonNull
static final IFunction SIGNATURE_ONE_ARG_METAPATH = IFunction.builder()
.name("resolve-profile")
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS)
.argument(IArgument.builder()
.name("profile")
.type(INodeItem.class)
Expand Down Expand Up @@ -109,7 +139,7 @@ public static ISequence<?> executeOneArg(
ISequence<? extends IDocumentNodeItem> arg = FunctionUtils.asType(
ObjectUtils.notNull(arguments.get(0)));

IItem item = FunctionUtils.getFirstItem(arg, true);
IItem item = arg.getFirstItem(true);
if (item == null) {
return ISequence.empty();
}
Expand Down
Loading

0 comments on commit bfb1d57

Please sign in to comment.