Skip to content

Commit

Permalink
Add support for SARIF-based results production.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Jun 20, 2024
1 parent 433908f commit c473d0e
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 41 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>gov.nist.secauto.metaschema</groupId>
<artifactId>metaschema-core</artifactId>
<version>${dependency.metaschema-framework.version}</version>
</dependency>

<dependency>
<groupId>gov.nist.secauto.metaschema</groupId>
<artifactId>metaschema-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Builder uuid(@NonNull UUID uuid) {
@SuppressWarnings("PMD.NullAssignment") // needed
@NonNull
public Builder namespace(@NonNull URI namespace) {
if (IProperty.OSCAL_NAMESPACE.equals(namespace)) {
if (OSCAL_NAMESPACE.equals(namespace)) {
this.namespace = null;
} else {
this.namespace = Objects.requireNonNull(namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItemFactory;
import gov.nist.secauto.metaschema.core.metapath.item.node.IRootAssemblyNodeItem;
import gov.nist.secauto.metaschema.core.model.IBoundObject;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.io.BindingException;
import gov.nist.secauto.metaschema.databind.io.DeserializationFeature;
import gov.nist.secauto.metaschema.databind.io.IBoundLoader;
import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly;
import gov.nist.secauto.metaschema.databind.model.IBoundObject;
import gov.nist.secauto.oscal.lib.OscalBindingContext;
import gov.nist.secauto.oscal.lib.OscalModelConstants;
import gov.nist.secauto.oscal.lib.OscalUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public enum TargetType {
static {
{
Map<Class<?>, TargetType> map = new ConcurrentHashMap<>();
for (TargetType type : TargetType.values()) {
for (TargetType type : values()) {
map.put(type.getClazz(), type);
}
CLASS_TO_TYPE = CollectionUtil.unmodifiableMap(map);
}

{
Map<String, TargetType> map = new ConcurrentHashMap<>();
for (TargetType type : TargetType.values()) {
for (TargetType type : values()) {
map.put(type.fieldName(), type);
}
NAME_TO_TYPE = CollectionUtil.unmodifiableMap(map);
Expand Down Expand Up @@ -157,7 +157,7 @@ public enum Position {

static {
Map<String, Position> map = new ConcurrentHashMap<>();
for (Position position : Position.values()) {
for (Position position : values()) {
map.put(position.name().toLowerCase(Locale.ROOT), position);
}
NAME_TO_POSITION = CollectionUtil.unmodifiableMap(map);
Expand Down Expand Up @@ -731,7 +731,7 @@ public boolean appliesTo(@NonNull Object obj) {
}
case PART: {
ControlPart part = (ControlPart) obj;
actualId = part.getId() == null ? null : part.getId().toString();
actualId = part.getId() == null ? null : part.getId();
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public enum TargetType {
static {
{
Map<Class<?>, TargetType> map = new ConcurrentHashMap<>();
for (TargetType type : TargetType.values()) {
for (TargetType type : values()) {
map.put(type.getClazz(), type);
}
CLASS_TO_TYPE = CollectionUtil.unmodifiableMap(map);
}

{
Map<String, TargetType> map = new ConcurrentHashMap<>();
for (TargetType type : TargetType.values()) {
for (TargetType type : values()) {
map.put(type.fieldName(), type);
}
NAME_TO_TYPE = CollectionUtil.unmodifiableMap(map);
Expand Down Expand Up @@ -184,11 +184,7 @@ private static <T> boolean handle(
}
}
} else if (handleChildren && handler != null) {
// if the child item type is applicable and there is a handler, iterate over
// children
Iterator<T> iter = supplier.get().iterator();
while (iter.hasNext()) {
T item = iter.next();
for (T item : supplier.get()) {
if (item != null) {
retval = retval || handler.apply(item);
}
Expand Down Expand Up @@ -265,14 +261,11 @@ public Boolean visitControl(Control control, Context context) {
null,
context);

// visit parts
retval = retval || handle(
return retval || handle(
TargetType.PART,
() -> CollectionUtil.listOrEmpty(control.getParts()),
child -> visitPart(child, context),
context);

return retval;
}

@Override
Expand All @@ -286,13 +279,11 @@ public Boolean visitParameter(Parameter parameter, Context context) {
null,
context);

// visit links
retval = retval || handle(
return retval || handle(
TargetType.LINK,
() -> CollectionUtil.listOrEmpty(parameter.getLinks()),
null,
context);
return retval;
}

/**
Expand Down Expand Up @@ -321,13 +312,11 @@ public boolean visitPart(ControlPart part, Context context) {
null,
context);

// visit parts
retval = retval || handle(
return retval || handle(
TargetType.PART,
() -> CollectionUtil.listOrEmpty(part.getParts()),
child -> visitPart(child, context),
context);
return retval;
}

static final class Context {
Expand Down Expand Up @@ -482,7 +471,7 @@ public boolean isApplicableTo(@NonNull Object obj) {
ControlPart part = (ControlPart) obj;
actualName = part.getName();
actualClass = part.getClazz();
actualId = part.getId() == null ? null : part.getId().toString();
actualId = part.getId() == null ? null : part.getId();
actualNamespace = part.getNs() == null ? IProperty.OSCAL_NAMESPACE.toString() : part.getNs().toString();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected Pair<Boolean, Boolean> match(String id) {
boolean withChild = first.getLeft() && first.getRight() || second.getLeft() && second.getRight();
result = Pair.of(true, withChild);
} else {
result = IControlSelectionFilter.NON_MATCH;
result = NON_MATCH;
}
return result;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public interface IControlSelectionFilter extends Function<IControl, Pair<Boolean
Pair<Boolean, Boolean> MATCH = ObjectUtils.notNull(Pair.of(true, true));

@NonNull
IControlSelectionFilter ALL_MATCH = control -> IControlSelectionFilter.MATCH;
IControlSelectionFilter ALL_MATCH = control -> MATCH;

@NonNull
IControlSelectionFilter NONE_MATCH = control -> IControlSelectionFilter.NON_MATCH;
IControlSelectionFilter NONE_MATCH = control -> NON_MATCH;

@NonNull
static IControlSelectionFilter matchIds(@NonNull String... identifiers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,9 @@ enum SelectionStatus {
"prop[@name='keep' and has-oscal-namespace('" + IProperty.OSCAL_NAMESPACE + "')]/@value = 'always'",
OscalBindingContext.OSCAL_STATIC_METAPATH_CONTEXT);

Predicate<IEntityItem> KEEP_ENTITY_PREDICATE = new Predicate<>() {

@Override
public boolean test(IEntityItem entity) {
return entity.getReferenceCount() > 0
|| (Boolean) ObjectUtils
.notNull(IIndexer.HAS_PROP_KEEP_METAPATH.evaluateAs(entity.getInstance(), ResultType.BOOLEAN));
}

};
Predicate<IEntityItem> KEEP_ENTITY_PREDICATE = entity -> entity.getReferenceCount() > 0
|| (Boolean) ObjectUtils
.notNull(HAS_PROP_KEEP_METAPATH.evaluateAs(entity.getInstance(), ResultType.BOOLEAN));

static boolean isReferencedEntity(@NonNull IEntityItem entity) {
return KEEP_ENTITY_PREDICATE.test(entity);
Expand Down
1 change: 0 additions & 1 deletion src/main/metaschema-bindings/oscal-metaschema-bindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,4 @@
</java>
</define-assembly-binding>
</metaschema-binding>

</metaschema-bindings>
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void test() throws FileNotFoundException, IOException, URISyntaxException {
// Profile profile = nodeItem.toBoundObject();

IDocumentNodeItem resolvedProfile = ResolveProfile.resolveProfile(nodeItem, dynamicContext);
OscalBindingContext.instance().validate(resolvedProfile, loader);
OscalBindingContext.instance().validate(resolvedProfile, loader, null);

// OscalBindingContext.instance().newSerializer(Format.XML,
// Catalog.class).serialize(resolvedProfile.toBoundObject(), new FileWriter(new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

import static org.junit.jupiter.api.Assertions.assertTrue;

import gov.nist.secauto.metaschema.core.model.IBoundObject;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.databind.DefaultBindingContext;
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.IDeserializer;
import gov.nist.secauto.metaschema.databind.io.ISerializer;
import gov.nist.secauto.metaschema.databind.model.IBoundObject;
import gov.nist.secauto.oscal.lib.model.Catalog;

import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.junit.jupiter.api.Assertions.fail;

import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.StaticContext;
import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
import gov.nist.secauto.metaschema.databind.io.DefaultBoundLoader;
import gov.nist.secauto.metaschema.databind.io.Format;
Expand Down

0 comments on commit c473d0e

Please sign in to comment.