Skip to content

Commit dcb0e55

Browse files
Fixed a binding error causing improper generation of some bound classes. Adjusted the resolve-resource Metapath function to only target bare fragments. Adjusted external constraints to avoid stack traces on malformed content. (#143)
1 parent 3bdde3f commit dcb0e55

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

src/main/java/gov/nist/secauto/oscal/lib/metapath/function/library/ResolveReference.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static ISequence<?> executeOneArg(
8989
@NonNull List<ISequence<?>> arguments,
9090
@NonNull DynamicContext dynamicContext,
9191
IItem focus) {
92-
IAnyUriItem uri = FunctionUtils.asTypeOrNull(ObjectUtils.requireNonNull(arguments.get(0).getFirstItem(true)));
92+
IAnyUriItem uri = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true));
9393

9494
if (uri == null) {
9595
return ISequence.empty();
@@ -151,14 +151,16 @@ public static IAnyUriItem resolveReference(
151151
INodeItem root = FnRoot.fnRoot(focusedItem);
152152
IOscalInstance oscalInstance = (IOscalInstance) INodeItem.toValue(root);
153153

154-
String fragment = reference.asUri().getFragment();
154+
URI referenceUri = reference.asUri();
155+
String fragment = referenceUri.getFragment();
155156

156-
return fragment == null
157-
? reference
158-
: IAnyUriItem.valueOf(resolveReference(
159-
fragment,
160-
mediaType == null ? null : mediaType.asString(),
161-
oscalInstance));
157+
return fragment != null
158+
&& (referenceUri.getPath() == null || referenceUri.getPath().isEmpty())
159+
? IAnyUriItem.valueOf(resolveReference(
160+
fragment,
161+
mediaType == null ? null : mediaType.asString(),
162+
oscalInstance))
163+
: reference;
162164
}
163165

164166
@NonNull

src/main/metaschema-bindings/oscal-metaschema-bindings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
</define-assembly-binding>
153153
</metaschema-binding>
154154
<metaschema-binding
155-
href="../../../oscal/src/metaschema/oscal_assessment-restults_metaschema.xml">
155+
href="../../../oscal/src/metaschema/oscal_assessment-results_metaschema.xml">
156156
<define-assembly-binding name="assessment-results">
157157
<java>
158158
<extend-base-class>gov.nist.secauto.oscal.lib.model.AbstractOscalInstance</extend-base-class>

src/main/metaschema-constraints/oscal-external-constraints.xml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -113,43 +113,19 @@
113113
</context>
114114

115115
<context>
116-
<metapath target="/profile"/>
116+
<metapath target="/profile/import"/>
117+
117118
<constraints>
118-
<let var="resolved-profile-imports" expression="resolve-profile(doc(resolve-uri(import/@href)))/catalog"/>
119-
<index id="oscal-profile-metadata-index-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($resolved-profile-imports/metadata/role ! map:entry(@id,.))?*">
120-
<formal-name>In-Scope Role Identifiers</formal-name>
121-
<description>An index of role identifiers that are in-scope for the profile model. Roles are collected from imported catalogs and profiles. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>
119+
<let var="resolved-profile-import" expression=".[@href] ! resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(@href))))/catalog"/>
120+
<index id="oscal-profile-import-index-control-id" name="profile-import-index-control-id" target="$resolved-profile-import//control">
121+
<formal-name>In-Scope Control Identifiers</formal-name>
122+
<description>An index of control identifiers that are in-scope for selection in the profile import.</description>
122123
<key-field target="@id"/>
123124
</index>
124-
<index id="oscal-profile-index-imports-metadata-scoped-location-uuid" name="index-imports-metadata-location-uuid" target="map:merge($resolved-profile-imports/metadata/location ! map:entry(@uuid,.))?*">
125-
<key-field target="@uuid"/>
126-
</index>
127-
<index id="oscal-profile-index-imports-metadata-scoped-party-uuid" name="index-imports-metadata-party-uuid" target="map:merge($resolved-profile-imports/metadata/party ! map:entry(@uuid,.))?*">
128-
<key-field target="@uuid"/>
129-
</index>
130-
<index id="oscal-profile-index-imports-metadata-scoped-party-organization-uuid" name="index-imports-metadata-party-organization-uuid" target="map:merge($resolved-profile-imports/metadata/party[@type='organization'] ! map:entry(@uuid,.))?*">
131-
<key-field target="@uuid"/>
132-
</index>
133-
<index id="oscal-profile-index-imports-metadata-scoped-property-uuid" name="index-imports-metadata-property-uuid" target="map:merge($resolved-profile-imports//prop[@uuid] ! map:entry(@uuid,.))?*">
134-
<key-field target="@uuid"/>
135-
</index>
125+
<index-has-key id="oscal-profile-import-has-key-include-exclude-control-id" name="profile-import-index-control-id" target="(include-controls|exclude-controls)/with-id">
126+
<key-field target="."/>
127+
</index-has-key>
136128
</constraints>
137-
138-
<context>
139-
<metapath target="import"/>
140-
141-
<constraints>
142-
<let var="resolved-profile-import" expression="resolve-profile(doc(resolve-uri(@href)))/catalog"/>
143-
<index id="oscal-profile-import-index-control-id" name="profile-import-index-control-id" target="$resolved-profile-import//control">
144-
<formal-name>In-Scope Control Identifiers</formal-name>
145-
<description>An index of control identifiers that are in-scope for selection in the profile import.</description>
146-
<key-field target="@id"/>
147-
</index>
148-
<index-has-key id="oscal-profile-import-has-key-include-exclude-control-id" name="profile-import-index-control-id" target="(include-controls|exclude-controls)/with-id">
149-
<key-field target="."/>
150-
</index-has-key>
151-
</constraints>
152-
</context>
153129
</context>
154130
<context>
155131
<metapath target="/mapping-collection"/>
@@ -176,7 +152,7 @@
176152
<context>
177153
<metapath target="/component-definition"/>
178154
<constraints>
179-
<let var="all-imports" expression="recurse-depth('doc(resolve-uri(import-component-definition/@href))/component-definition')"/>
155+
<let var="all-imports" expression="import-component-definition ! recurse-depth('doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(@href)))/component-definition')"/>
180156
<index id="oscal-component-definition-index-metadata-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($all-imports/metadata/role ! map:entry(@id,.))?*">
181157
<formal-name>In-Scope Role Identifiers</formal-name>
182158
<description>An index of role identifiers that are in-scope for the component-definition model. Roles are collected from imported component-definition. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>
@@ -199,7 +175,7 @@
199175
<context>
200176
<metapath target="/system-security-plan"/>
201177
<constraints>
202-
<let var="all-imports" expression="recurse-depth('resolve-profile(doc(resolve-uri(import-profile/@href)))/catalog')"/>
178+
<let var="all-imports" expression="resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-profile/@href))))/catalog"/>
203179
<index id="oscal-ssp-index-metadata-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($all-imports/metadata/role ! map:entry(@id,.))?*">
204180
<formal-name>In-Scope Role Identifiers</formal-name>
205181
<description>An index of role identifiers that are in-scope for the system-securtity-plan model. Roles are collected from imported profiles and catalogs. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>
@@ -222,7 +198,7 @@
222198
<context>
223199
<metapath target="/assessment-plan"/>
224200
<constraints>
225-
<let var="all-imports" expression="recurse-depth('.[import-ssp]/doc(resolve-uri(import-ssp/@href))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(import-profile/@href)))/catalog')"/>
201+
<let var="all-imports" expression="recurse-depth('.[import-ssp]/doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-ssp/@href)))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-profile/@href))))/catalog')"/>
226202
<index id="oscal-ap-index-metadata-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($all-imports/metadata/role ! map:entry(@id,.))?*">
227203
<formal-name>In-Scope Role Identifiers</formal-name>
228204
<description>An index of role identifiers that are in-scope for the assessment-plan model. Roles are collected from imported system-securtity-plans, which in turn includes referenced profiles and catalogs. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>
@@ -245,7 +221,7 @@
245221
<context>
246222
<metapath target="/assessment-results"/>
247223
<constraints>
248-
<let var="all-imports" expression="recurse-depth('.[import-ap]/doc(resolve-uri(import-ap/@href))/assessment-plan|.[import-ssp]/doc(resolve-uri(import-ssp/@href))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(import-profile/@href)))/catalog')"/>
224+
<let var="all-imports" expression="recurse-depth('.[import-ap]/doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-ap/@href)))/assessment-plan|.[import-ssp]/doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-ssp/@href)))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-profile/@href))))/catalog')"/>
249225
<index id="oscal-ar-index-metadata-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($all-imports/metadata/role ! map:entry(@id,.))?*">
250226
<formal-name>In-Scope Role Identifiers</formal-name>
251227
<description>An index of role identifiers that are in-scope for the assessment-result model. Roles are collected from imported assessment-plans, which in turn includes referenced system-securtity-plans, which in turn includes referenced profiles and catalogs. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>
@@ -268,7 +244,7 @@
268244
<context>
269245
<metapath target="/plan-of-action-and-milestones"/>
270246
<constraints>
271-
<let var="all-imports" expression="recurse-depth('.[import-ap]/doc(resolve-uri(import-ap/@href))/assessment-plan|.[import-ssp]/doc(resolve-uri(import-ssp/@href))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(import-profile/@href)))/catalog')"/>
247+
<let var="all-imports" expression="recurse-depth('.[import-ap]/doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-ap/@href)))/assessment-plan|.[import-ssp]/doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-ssp/@href)))/system-security-plan|.[import-profile]/resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(import-profile/@href))))/catalog')"/>
272248
<index id="oscal-poam-index-metadata-scoped-role-id" name="index-imports-metadata-role-id" target="map:merge($all-imports/metadata/role ! map:entry(@id,.))?*">
273249
<formal-name>In-Scope Role Identifiers</formal-name>
274250
<description>An index of role identifiers that are in-scope for the plan-of-action-and-milestones model. Roles are collected from imported system-securtity-plans, which in turn includes referenced profiles and catalogs. For a given role @id, a locally declared role takes precedence over a role that is imported, the role that was last imported.</description>

0 commit comments

Comments
 (0)