Class FlowComm.Matcher
- All Implemented Interfaces:
org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<FlowComm.Match>
- Enclosing class:
FlowComm
Use the pattern matcher on a given model via on(ViatraQueryEngine),
e.g. in conjunction with ViatraQueryEngine.on(QueryScope).
Matches of the pattern will be represented as FlowComm.Match.
Original source:
////////////////////////////////////////////////////////////////////////////////////////////////////
// SPARTA DFD threat-elicitation pattern catalog
//
// This file is the built-in catalog of VIATRA patterns used for threat elicitation. The generated
// matcher classes of every public Comm pattern are referenced BY NAME from Java
// (Engine.getPatternMatchers in be.kuleuven.cs.distrinet.sparta.core), so do not rename patterns or
// change their signatures without updating those call sites.
//
// == Pattern families ==
//
// <X>To<Y>Comm (e.g. processToDataStoreComm)
// Matches a directed communication over a DataFlow `df` between an element of type X and an
// element of type Y. The `location` parameter is the DFD element the elicited threat is
// attached to.
//
// <X>Through<Y>Comm (e.g. processThroughDataStoreComm)
// Same as the To variant, but additionally requires the flow to cross a trust boundary: some
// TrustBoundaryContainer (transitively) contains one endpoint but not the other
// (see flowContainerDiff below).
//
// flowComm / flowThroughComm
// Generic variants that attach the threat to the DataFlow itself (`location : DataFlow`)
// instead of to one of its endpoints.
//
// == Applicability strings ==
//
// Every pattern body guards itself with
// find threatApplicable(location, t, "<key>");
// The <key> string is compared literally — by plain map-key equality, the `` is part of the key,
// NOT a wildcard — against the keys of the AbstractThreatType.patterns map (EStringToEBooleanMap)
// of the threat type or of one of its CompositeThreatType ancestors. A threat catalog enables a
// body by mapping that key to true, and vetoes it by mapping it to false (see the cascade below).
//
// Key naming conventions (Through keys behave identically, with the added boundary-crossing
// requirement):
//
// - "XToY" (no asterisk): forward-direction body. The threat is attached to the flow's SENDER:
// `location` (of type X) sends `df` to `p2` (of type Y) — find communication(location, df, p2).
// The key equals the name of the pattern hosting the body (e.g. "ProcessToDataStore" in
// processToDataStoreComm).
//
// - "XToY" (trailing asterisk): inverse-direction body. The flow still runs X -> Y, but the
// threat is attached to the flow's RECIPIENT (the Y endpoint). Such a body therefore lives in
// the pattern whose `location` type is Y: e.g. "DataStoreToProcess" is the second body of
// processToDataStoreComm — `p2` (DataStore) sends `df` to `location` (Process).
//
// - "XToY" (asterisk in the middle): used only by the generic flowComm / flowThroughComm
// patterns. The `` marks the position of the threat: it is attached to the DataFlow itself,
// flowing from an X sender to a Y recipient. Direction matters (e.g. "ProcessToDataStore" and
// "DataStoreToProcess" are distinct keys), and only pairs involving a Process are provided.
// The fully generic keys "DataFlow" (flowComm) and "DataFlowThrough" (flowThroughComm) match a
// flow regardless of its endpoint types.
//
// == Enable/disable cascade (threatApplicable) ==
//
// A body matches threat type `t` for key `k` if and only if ALL of the following hold:
// 1. `t` itself is enabled (ThreatType.enabled == true);
// 2. `t` or one of its ancestors maps `k` to true in its patterns map (threatPattern). The
// ancestor chain is `t` itself plus every CompositeThreatType that (transitively) contains it
// via subThreatTypes (threatTypeParent / threatTypeAncestor), so enablement is inherited;
// 3. no ancestor in that chain is disabled (neg threatTypeParentDisabled);
// 4. no enabled ancestor maps `k` to false (neg threatPatternDisabled) — an explicit false
// anywhere in the hierarchy vetoes a true inherited from elsewhere;
// 5. no ThreatSpecification whose `threat` targets `t` or an ancestor
// - disables the threat outright (enabled == false, threatSpecDisable),
// - maps `k` to false in its own patterns map (threatSpecPatternDisable), or
// - disables the element type of `location` — "Process" / "DataStore" / "ExternalEntity" /
// "DataFlow" mapped to false in its types map (threatSpecTypeDisable).
// ThreatSpecifications are per-model overrides: a model can switch off catalog threats,
// individual pattern keys, or whole element types without editing the catalog itself.
//
// == Supporting helper patterns ==
//
// - communication(sender, flow, recipient): resolves the logical endpoints of a DataFlow through
// chains of SenderSpecification / RecipientSpecification indirections
// (sendSpecReachable / receiveSpecReachable).
// - flowContainerDiff(sender, recipient): the two entities communicate (in either direction) and
// some TrustBoundaryContainer contains exactly one of them, i.e. the flow crosses that trust
// boundary. Containment is resolved transitively (contains / containment).
////////////////////////////////////////////////////////////////////////////////////////////////////
pattern flowComm(location : DataFlow, p : DataFlowEntity, p2 : DataFlowEntity,
t : ThreatType) {
DataFlow(location);DataFlowEntity(p);DataFlowEntity(p2);
find threatApplicable(location,t,"DataFlow");
find communication(p,location,p2);
} or {
Process(p);
Process(p2);
find threatApplicable(location,t,"ProcessToProcess");
find communication(p,location,p2);
} or {
Process(p);
DataStore(p2);
find threatApplicable(location,t,"ProcessToDataStore");
find communication(p,location,p2);
} or {
DataStore(p);
Process(p2);
find threatApplicable(location,t,"DataStoreToProcess");
find communication(p,location,p2);
} or {
Process(p);
ExternalEntity(p2);
find threatApplicable(location,t,"ProcessToExternalEntity");
find communication(p,location,p2);
} or {
ExternalEntity(p);
Process(p2);
find threatApplicable(location,t,"ExternalEntityToProcess");
find communication(p,location,p2);
}
- See Also:
-
Field Summary
Fields inherited from class org.eclipse.viatra.query.runtime.api.impl.BaseMatcher
engine, querySpecificationFields inherited from class org.eclipse.viatra.query.runtime.internal.apiimpl.QueryResultWrapper
backend -
Method Summary
Modifier and TypeMethodDescriptionprotected FlowComm.MatcharrayToMatch(Object[] match) protected FlowComm.MatcharrayToMatchMutable(Object[] match) intcountMatches(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.static FlowComm.Matchercreate()booleanforOneArbitraryMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT, Consumer<? super FlowComm.Match> processor) Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.getAllMatches(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.Retrieve the set of values that occur in matches for location.getAllValuesOflocation(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for location.getAllValuesOflocation(DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for location.Retrieve the set of values that occur in matches for p.getAllValuesOfp(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for p.getAllValuesOfp(DataFlow pLocation, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for p.Retrieve the set of values that occur in matches for p2.getAllValuesOfp2(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for p2.getAllValuesOfp2(DataFlow pLocation, DataFlowEntity pP, ThreatType pT) Retrieve the set of values that occur in matches for p2.Retrieve the set of values that occur in matches for t.getAllValuesOft(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for t.getAllValuesOft(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2) Retrieve the set of values that occur in matches for t.getOneArbitraryMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.booleanhasMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters (if any).newMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns a new (partial) match.static FlowComm.Matcheron(org.eclipse.viatra.query.runtime.api.ViatraQueryEngine engine) Initializes the pattern matcher within an existing VIATRA Query engine.static org.eclipse.viatra.query.runtime.api.IQuerySpecification<FlowComm.Matcher> rawStreamAllValuesOflocation(Object[] parameters) Retrieve the set of values that occur in matches for location.protected Stream<DataFlowEntity> rawStreamAllValuesOfp(Object[] parameters) Retrieve the set of values that occur in matches for p.protected Stream<DataFlowEntity> rawStreamAllValuesOfp2(Object[] parameters) Retrieve the set of values that occur in matches for p2.protected Stream<ThreatType> rawStreamAllValuesOft(Object[] parameters) Retrieve the set of values that occur in matches for t.streamAllMatches(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.Retrieve the set of values that occur in matches for location.streamAllValuesOflocation(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for location.streamAllValuesOflocation(DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for location.Retrieve the set of values that occur in matches for p.streamAllValuesOfp(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for p.streamAllValuesOfp(DataFlow pLocation, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for p.Retrieve the set of values that occur in matches for p2.streamAllValuesOfp2(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for p2.streamAllValuesOfp2(DataFlow pLocation, DataFlowEntity pP, ThreatType pT) Retrieve the set of values that occur in matches for p2.Retrieve the set of values that occur in matches for t.streamAllValuesOft(FlowComm.Match partialMatch) Retrieve the set of values that occur in matches for t.streamAllValuesOft(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2) Retrieve the set of values that occur in matches for t.protected FlowComm.MatchtupleToMatch(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple t) Methods inherited from class org.eclipse.viatra.query.runtime.api.impl.BaseMatcher
countMatches, countMatches, emptyArray, forEachMatch, forEachMatch, forOneArbitraryMatch, forOneArbitraryMatch, getAllMatches, getAllMatches, getAllValues, getAllValues, getCapabilities, getEngine, getOneArbitraryMatch, getOneArbitraryMatch, getParameterNames, getPatternName, getPositionOfParameter, getSpecification, hasMatch, hasMatch, matchToArray, newEmptyMatch, newMatch, rawAccumulateAllValues, rawCountMatches, rawForEachMatch, rawForOneArbitraryMatch, rawGetOneArbitraryMatch, rawHasMatch, rawStreamAllMatches, rawStreamAllValues, setBackend, streamAllMatches, streamAllMatches
-
Method Details
-
on
Initializes the pattern matcher within an existing VIATRA Query engine. If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.- Parameters:
engine- the existing VIATRA Query engine in which this matcher will be created.
-
create
- Returns:
- an initialized matcher
-
getAllMatches
public Collection<FlowComm.Match> getAllMatches(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- matches represented as a Match object.
-
streamAllMatches
public Stream<FlowComm.Match> streamAllMatches(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- a stream of matches represented as a Match object.
-
getOneArbitraryMatch
public Optional<FlowComm.Match> getOneArbitraryMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- a match represented as a Match object, or null if no match is found.
-
hasMatch
Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, under any possible substitution of the unspecified parameters (if any).- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- true if the input is a valid (partial) match of the pattern.
-
countMatches
Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- the number of pattern matches found.
-
forOneArbitraryMatch
public boolean forOneArbitraryMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT, Consumer<? super FlowComm.Match> processor) Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.processor- the action that will process the selected match.- Returns:
- true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
-
newMatch
public FlowComm.Match newMatch(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Returns a new (partial) match. This can be used e.g. to call the matcher with a partial match.The returned match will be immutable. Use
BaseMatcher.newEmptyMatch()to obtain a mutable match object.- Parameters:
pLocation- the fixed value of pattern parameter location, or null if not bound.pP- the fixed value of pattern parameter p, or null if not bound.pP2- the fixed value of pattern parameter p2, or null if not bound.pT- the fixed value of pattern parameter t, or null if not bound.- Returns:
- the (partial) match object.
-
rawStreamAllValuesOflocation
Retrieve the set of values that occur in matches for location.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOflocation
Retrieve the set of values that occur in matches for location.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOflocation
Retrieve the set of values that occur in matches for location.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOflocation
Retrieve the set of values that occur in matches for location. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
streamAllValuesOflocation
public Stream<DataFlow> streamAllValuesOflocation(DataFlowEntity pP, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for location. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
getAllValuesOflocation
Retrieve the set of values that occur in matches for location.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOflocation
Retrieve the set of values that occur in matches for location.- Returns:
- the Set of all values or empty set if there are no matches
-
rawStreamAllValuesOfp
Retrieve the set of values that occur in matches for p.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOfp
Retrieve the set of values that occur in matches for p.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOfp
Retrieve the set of values that occur in matches for p.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOfp
Retrieve the set of values that occur in matches for p. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
streamAllValuesOfp
public Stream<DataFlowEntity> streamAllValuesOfp(DataFlow pLocation, DataFlowEntity pP2, ThreatType pT) Retrieve the set of values that occur in matches for p. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
getAllValuesOfp
Retrieve the set of values that occur in matches for p.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOfp
Retrieve the set of values that occur in matches for p.- Returns:
- the Set of all values or empty set if there are no matches
-
rawStreamAllValuesOfp2
Retrieve the set of values that occur in matches for p2.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOfp2
Retrieve the set of values that occur in matches for p2.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOfp2
Retrieve the set of values that occur in matches for p2.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOfp2
Retrieve the set of values that occur in matches for p2. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
streamAllValuesOfp2
public Stream<DataFlowEntity> streamAllValuesOfp2(DataFlow pLocation, DataFlowEntity pP, ThreatType pT) Retrieve the set of values that occur in matches for p2. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
getAllValuesOfp2
Retrieve the set of values that occur in matches for p2.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOfp2
Retrieve the set of values that occur in matches for p2.- Returns:
- the Set of all values or empty set if there are no matches
-
rawStreamAllValuesOft
Retrieve the set of values that occur in matches for t.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOft
Retrieve the set of values that occur in matches for t.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOft
Retrieve the set of values that occur in matches for t.- Returns:
- the Set of all values or empty set if there are no matches
-
streamAllValuesOft
Retrieve the set of values that occur in matches for t. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
streamAllValuesOft
public Stream<ThreatType> streamAllValuesOft(DataFlow pLocation, DataFlowEntity pP, DataFlowEntity pP2) Retrieve the set of values that occur in matches for t. NOTE: It is important not to modify the source model while the stream is being processed. If the match set of the pattern changes during processing, the contents of the stream is undefined. In such cases, either rely onBaseMatcher.getAllMatches()or collect the results of the stream in end-user code.- Returns:
- the Stream of all values or empty set if there are no matches
-
getAllValuesOft
Retrieve the set of values that occur in matches for t.- Returns:
- the Set of all values or empty set if there are no matches
-
getAllValuesOft
Retrieve the set of values that occur in matches for t.- Returns:
- the Set of all values or empty set if there are no matches
-
tupleToMatch
- Specified by:
tupleToMatchin classorg.eclipse.viatra.query.runtime.api.impl.BaseMatcher<FlowComm.Match>
-
arrayToMatch
- Specified by:
arrayToMatchin classorg.eclipse.viatra.query.runtime.api.impl.BaseMatcher<FlowComm.Match>
-
arrayToMatchMutable
- Specified by:
arrayToMatchMutablein classorg.eclipse.viatra.query.runtime.api.impl.BaseMatcher<FlowComm.Match>
-
querySpecification
public static org.eclipse.viatra.query.runtime.api.IQuerySpecification<FlowComm.Matcher> querySpecification()- Returns:
- the singleton instance of the query specification of this pattern
-