use of org.eclipse.winery.model.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class ThreatModelingUtilsWithGitBackendRepositoryTest method checkThreatCatalog.
@Test
public void checkThreatCatalog() throws Exception {
this.setRevisionTo("origin/plain");
ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
assertTrue(tmu.getThreatCatalogue().isEmpty());
PolicyTemplateId threatAID = new PolicyTemplateId("http://example.com", "MyThreat", false);
TPolicyTemplate threatA = new TPolicyTemplate.Builder("myThreat", QName.valueOf(ThreatModelingConstants.THREAT_POLICY_ID)).setName("MyThreat").build();
repository.setElement(threatAID, threatA);
tmu = new ThreatModelingUtils(repository);
assertFalse(tmu.getThreatCatalogue().isEmpty());
assertEquals("MyThreat", tmu.getThreatCatalogue().get(0).getTemplateName());
}
use of org.eclipse.winery.model.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added<
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
List<TPolicy> policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
if (topology != null) {
if (Objects.nonNull(topology.getPolicies())) {
topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
QName type = p.getPolicyType();
PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
ids.add(policyTypeIdId);
});
}
for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through policies
List<TPolicy> policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
// Crawl RequirementTypes and Capabilities for their references
getReferencedRequirementTypeIds(ids, n);
getCapabilitiesReferences(ids, n);
// TODO: this information is collected differently for YAML and XML modes
// crawl through deployment artifacts
List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
if (da.getArtifactType() != null) {
// This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
// expects an empty artifactType and thus it may be null.
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
if (da.getArtifactRef() != null) {
ids.add(new ArtifactTemplateId(da.getArtifactRef()));
}
}
}
// Store all referenced artifact types
List<TArtifact> artifacts = n.getArtifacts();
if (Objects.nonNull(artifacts)) {
artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
}
TNodeType nodeType = this.getElement(new NodeTypeId(qname));
if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
if (Objects.nonNull(iDef.getType())) {
ids.add(new InterfaceTypeId(iDef.getType()));
}
});
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class VersionSupport method getDefinitionInTheGivenVersion.
public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
if (childId.getVersion().compareTo(otherVersion) == 0) {
return childId;
}
String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
if (childId instanceof RelationshipTypeImplementationId) {
return new RelationshipTypeImplementationId(qName);
} else if (childId instanceof NodeTypeImplementationId) {
return new NodeTypeImplementationId(qName);
} else if (childId instanceof RequirementTypeId) {
return new RequirementTypeId(qName);
} else if (childId instanceof NodeTypeId) {
return new NodeTypeId(qName);
} else if (childId instanceof RelationshipTypeId) {
return new RelationshipTypeId(qName);
} else if (childId instanceof CapabilityTypeId) {
return new CapabilityTypeId(qName);
} else if (childId instanceof ArtifactTypeId) {
return new ArtifactTypeId(qName);
} else if (childId instanceof PolicyTypeId) {
return new PolicyTypeId(qName);
} else if (childId instanceof PolicyTemplateId) {
return new PolicyTemplateId(qName);
} else if (childId instanceof ServiceTemplateId) {
return new ServiceTemplateId(qName);
} else if (childId instanceof ArtifactTemplateId) {
return new ArtifactTemplateId(qName);
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
}
use of org.eclipse.winery.model.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class ThreatModeling method findAbstractMitigationsForPresentThreats.
/**
* find abstract SVNF group Node Types for appropriate mitigations based on the present threats of the current
* Service Template
*/
private void findAbstractMitigationsForPresentThreats() {
List<TServiceTemplate> mitigationCandidates = getServiceTemplateSubstitutionCandidates();
mitigationCandidates.forEach((TServiceTemplate template) -> {
QName substitutableNodeType = template.getSubstitutableNodeType();
QName abstractMitigationType;
try {
abstractMitigationType = utils.findFirstAbstractType(substitutableNodeType);
} catch (Exception e) {
return;
}
List<TPolicy> mitigationPolicies = utils.getBoundaryDefinitionMitigationPolicies(template);
mitigationPolicies.forEach((TPolicy mitigation) -> {
PolicyTemplateId mitigationTemplateId = new PolicyTemplateId(mitigation.getPolicyRef());
TPolicyTemplate mitigationTemplate = repository.getElement(mitigationTemplateId);
if (Objects.nonNull(mitigationTemplate.getProperties())) {
LinkedHashMap<String, String> properties = ModelUtilities.getPropertiesKV(mitigationTemplate);
// FIXME Assumption that we're dealing with simple KV Properties
String threatReferenceString = (String) properties.get("ThreatReference");
QName threatReference = QName.valueOf(threatReferenceString);
// check if the threat, the mitigation references is present.
if (Objects.nonNull(abstractThreatMitigations.get(threatReference))) {
// add abstract SVNF to list of effective mitigations to present threat
Threat threat = abstractThreatMitigations.get(threatReference);
threat.addMitigations(abstractMitigationType);
abstractThreatMitigations.put(threatReference, threat);
}
}
});
});
}
use of org.eclipse.winery.model.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class ThreatModeling method getPresentThreats.
/**
* Collect all threats present in the current Service Template
*/
private void getPresentThreats() {
nodeTemplates.forEach((TNodeTemplate nt) -> {
if (nt.getPolicies() != null) {
nt.getPolicies().forEach((TPolicy policy) -> {
String policyTypeName = policy.getPolicyType().toString();
if (policyTypeName.equals(ThreatModelingConstants.THREAT_POLICY_ID)) {
QName threatQName = policy.getPolicyRef();
PolicyTemplateId threatId = new PolicyTemplateId(threatQName);
TPolicyTemplate threatTemplate = repository.getElement(threatId);
Threat threat = new Threat();
// set target of current threat.
threat.addTarget(nt.getName(), nt.getTypeAsQName());
if (Objects.nonNull(threatTemplate.getProperties())) {
threat.setProperties(ModelUtilities.getPropertiesKV(threatTemplate));
}
threat.setTemplateName(threatQName.getLocalPart());
threat.setNamespace(threatQName.getNamespaceURI());
abstractThreatMitigations.putIfAbsent(threatQName, threat);
}
});
}
});
}
Aggregations