Markings#3469
Conversation
e86e7ba to
0e0b4d2
Compare
07765cd to
65db1ad
Compare
8bc250c to
98f8567
Compare
98f8567 to
b07ead2
Compare
cceab28 to
e72fd54
Compare
| @SuppressWarnings({"unchecked", "rawtypes"}) | ||
| public static Markings<?> combine(MarkingFunctions<?> markingFunctions, Collection<? extends Markings<?>> markings) throws MarkingFunctions.Exception { | ||
| return ((MarkingFunctions) markingFunctions).combine(markings); | ||
| } |
There was a problem hiding this comment.
I think we can be a little more specific with generics here:
| @SuppressWarnings({"unchecked", "rawtypes"}) | |
| public static Markings<?> combine(MarkingFunctions<?> markingFunctions, Collection<? extends Markings<?>> markings) throws MarkingFunctions.Exception { | |
| return ((MarkingFunctions) markingFunctions).combine(markings); | |
| } | |
| public static <T extends Markings<?>, U extends MarkingFunctions<T>> T combine(U markingFunctions, Collection<T> markings) throws MarkingFunctions.Exception { | |
| return markingFunctions.combine(markings); | |
| } |
There was a problem hiding this comment.
lets see if we can address this down the road on another MR
| if (markings1 instanceof AccessExpressionMarkings && markings2 instanceof AccessExpressionMarkings) { | ||
| AccessExpressionMarkings aem1 = (AccessExpressionMarkings) markings1; | ||
| AccessExpressionMarkings aem2 = (AccessExpressionMarkings) markings2; | ||
| return combine(markingFunctions, List.of(aem1, aem2)); |
There was a problem hiding this comment.
If the above generic suggestion works, i think you'll need to modify this slightly:
| if (markings1 instanceof AccessExpressionMarkings && markings2 instanceof AccessExpressionMarkings) { | |
| AccessExpressionMarkings aem1 = (AccessExpressionMarkings) markings1; | |
| AccessExpressionMarkings aem2 = (AccessExpressionMarkings) markings2; | |
| return combine(markingFunctions, List.of(aem1, aem2)); | |
| if (markingFunctions instanceof MarkingFunctions.Default && markings1 instanceof AccessExpressionMarkings && markings2 instanceof AccessExpressionMarkings) { | |
| MarkingFunctions<AccessExpressionMarkings> defaultMarkingFunctions = (MarkingFunctions.Default) markingFunctions; | |
| AccessExpressionMarkings aem1 = (AccessExpressionMarkings) markings1; | |
| AccessExpressionMarkings aem2 = (AccessExpressionMarkings) markings2; | |
| return combine(defaultMarkingFunctions, List.of(aem1, aem2)); |
There was a problem hiding this comment.
lets see if we can address this down the road on another MR
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
|
||
| @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) | ||
| public interface Markings<T> { |
There was a problem hiding this comment.
Can we restrict T here at all?
There was a problem hiding this comment.
lets see if we can address this down the road on another MR
| public interface HasMarkings { | ||
|
|
||
| void setMarkings(Map<String,String> markings); | ||
| void setMarkings(Markings<?> markings); | ||
|
|
||
| Map<String,String> getMarkings(); | ||
| Markings<?> getMarkings(); | ||
| } |
There was a problem hiding this comment.
I'm guessing there's some issue you'll eventually run into, but here's a naive suggestion (which will require a lot of associated changes, some of which may be impossible):
public interface HasMarkings <T> {
void setMarkings(Markings<T> markings);
Markings<T> getMarkings();
}There was a problem hiding this comment.
lets see if we can address this down the road on another MR
…expression markings are present
| public void inheritFromRootPayload(RawRecordContainer event, Map<String,Collection<Object>> metadata) { | ||
| // TODO: No-op here, but need to refactor the following in upstream | ||
| // if (metadata == null) | ||
| // return; | ||
| // | ||
| // IBaseDataObject payload = (IBaseDataObject) event.getAuxData(); | ||
| // if (payload != null) { | ||
| // for (String field : helper.getInheritedPayloadFields()) { | ||
| // if (metadata.containsKey(field) && (!payload.hasParameter(field))) { | ||
| // payload.putParameter(field, metadata.get(field)); | ||
| // } | ||
| // } | ||
| // } | ||
| } | ||
|
|
||
| public void addMetadataFromParms(RawRecordContainer event, Map<String,Collection<Object>> metadata, String id) { | ||
|
|
||
| for (Map.Entry<String,Collection<Object>> entry : metadata.entrySet()) { | ||
| CharSequence key = entry.getKey(); | ||
| for (Object value : entry.getValue()) { | ||
| if (value == null) | ||
| continue; | ||
|
|
||
| if (helper.getUuids().contains(key)) { | ||
| event.getAltIds().add(String.valueOf(value)); | ||
| } | ||
| if (this.helper.getSecurityMarkingFieldDomainMap().containsKey(key)) { | ||
| addSecurityMetadataFromParms(key, value, event); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Multimap<String,String> newMetadata = HashMultimap.create(); | ||
| Multimap<String,MetadataIdParser> fieldParsers = helper.getMetadataFieldParsers(); | ||
| for (String field : fieldParsers.keySet()) { | ||
| if (metadata.containsKey(field) && metadata.get(field) != null) { | ||
| for (MetadataIdParser parser : fieldParsers.get(field)) { | ||
| for (Object v : metadata.get(field)) { | ||
| if (v == null) | ||
| continue; | ||
| try { | ||
| parser.addMetadata(event, newMetadata, v.toString()); | ||
| } catch (Exception e) { | ||
| log.error("Unable to apply " + parser + " to " + field, e); | ||
| event.addError(RawDataErrorNames.FIELD_EXTRACTION_ERROR); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If the ID is a UUID (i.e., contains no date), try to get | ||
| // event metadata from the parameters | ||
| if ((id != null) && (id.length() >= UUID_LENGTH) && id.matches(UUID_PATTERN)) { | ||
| fieldParsers = helper.getMetadataFieldUuidParsers(); | ||
| for (String field : fieldParsers.keySet()) { | ||
| if (metadata.containsKey(field) && metadata.get(field) != null) { | ||
| for (MetadataIdParser parser : fieldParsers.get(field)) { | ||
| for (Object v : metadata.get(field)) { | ||
| if (v == null) | ||
| continue; | ||
| try { | ||
| parser.addMetadata(event, newMetadata, v.toString()); | ||
| } catch (Exception e) { | ||
| log.error("Unable to apply " + parser + " to " + field, e); | ||
| event.addError(RawDataErrorNames.FIELD_EXTRACTION_ERROR); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected void addSecurityMetadataFromParms(CharSequence key, Object value, RawRecordContainer event) { | ||
| // If fieldName is a security marking field (as configured by EVENT_SECURITY_MARKING_FIELD_NAMES), | ||
| // then put the marking value into this.securityMarkings, where 'key' maps to the domain for the marking | ||
| // (as configured by EVENT_SECURITY_MARKING_FIELD_DOMAINS) | ||
| if (!StringUtils.isEmpty(key.toString()) && !StringUtils.isEmpty(value.toString())) { | ||
| event.addSecurityMarking(this.helper.getSecurityMarkingFieldDomainMap().get(key.toString()), value.toString()); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't think this is used anywhere but please doublecheck. There are other references to EVENT_SECURITY_MARKING_FIELD_NAMES and EVENT_SECURITY_MARKING_FIELD_DOMAINS that can be cleaned up once confirmed
| @Override | ||
| public void setMarkings(Markings<?> markings) { | ||
| this.markings = markings; | ||
| this.setSecurityMarkings(markings.get("security")); |
There was a problem hiding this comment.
what is the key "security" used for?
No description provided.