use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ThreatModelingUtils method checkPrerequisites.
/**
* Checks the prequisites for threat modeling. These include the base types (S-VNF.Threat and S-VNF.Mitigtion) and
* an empty SVNF Node Type
*
* @return boolean
*/
public boolean checkPrerequisites() {
PolicyTypeId threatId = new PolicyTypeId(QName.valueOf(ThreatModelingConstants.THREAT_POLICY_ID));
PolicyTypeId mitigationId = new PolicyTypeId(QName.valueOf(ThreatModelingConstants.MITIGATION_POLICY_ID));
NodeTypeId svnfId = new NodeTypeId(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE));
return repository.exists(threatId) && repository.exists(mitigationId) && repository.exists(svnfId);
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ThreatModelingUtils method isOfTypeOrInheritsFromSVNF.
/**
* Check if a NodeType is of type "S-VNF.Security" or inherits from a Node Type that is. Searches in the inheritance
* path for the first occurence of the desired Node Type
*
* @param nodeTypeName to check
* @return boolean
*/
public Boolean isOfTypeOrInheritsFromSVNF(QName nodeTypeName) {
NodeTypeId id = new NodeTypeId(nodeTypeName);
TNodeType nodeType = repository.getElement(id);
// check for target type
if (nodeTypeName.toString().equals(ThreatModelingConstants.SVNF_NODE_TYPE) || nodeTypeName.toString().equals(SNS_NODE_TYPE)) {
return true;
// check for target type in inheritance
} else if (Objects.nonNull(nodeType.getDerivedFrom())) {
return isOfTypeOrInheritsFromSVNF(nodeType.getDerivedFrom().getTypeAsQName());
}
return false;
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ThreatModelingUtils method findFirstAbstractType.
/**
* Find the first abstract Type of a Node Type. Either the Node Type is abstract or its inheritance path is walked
* recursively to find one.
*
* @param nodeTypeName to check
* @return QName of first abstract Node Type
* @throws Exception if no abstract Node Type can be found in the inheritance path.
*/
public QName findFirstAbstractType(QName nodeTypeName) throws Exception {
NodeTypeId id = new NodeTypeId(nodeTypeName);
TNodeType nodeType = repository.getElement(id);
// check if node type is abstract
if (nodeType.getAbstract()) {
return nodeTypeName;
} else if (Objects.nonNull(nodeType.getDerivedFrom())) {
// check if node type inherits from other node type
return findFirstAbstractType(nodeType.getDerivedFrom().getTypeAsQName());
} else {
throw new Exception("No abstract Node Type found");
}
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ThreatModelingTestWithGitBackedRepository method testForPresentSVNFinServiceTemplate.
@Test
public void testForPresentSVNFinServiceTemplate() throws Exception {
this.setRevisionTo("origin/plain");
ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
try {
tmu.setupThreatModelingTypes();
ThreatCreationApiData newThreat = new ThreatCreationApiData();
newThreat.setName("MyThreat");
newThreat.setDescription("My Description");
newThreat.setStride("Spoofing");
newThreat.setSeverity("Low");
tmu.createThreatAndMitigationTemplates(newThreat);
} catch (Exception e) {
return;
}
TNodeType svnfGroupA = new TNodeType.Builder("MyGroupA").setTargetNamespace(demoNamespace).setAbstract(true).setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).build();
TNodeType svnfGroupB = new TNodeType.Builder("MyGroupB").setTargetNamespace(demoNamespace).setAbstract(true).setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).build();
TTopologyTemplate emptyTopology = new TTopologyTemplate.Builder().build();
TPolicy boundaryThreat = new TPolicy.Builder(QName.valueOf(ThreatModelingConstants.MITIGATION_POLICY_ID)).setPolicyRef(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MITIGATE_MyThreat")).setName("MITIGATE_MyThreat").build();
TBoundaryDefinitions boundaryDefinitions = new TBoundaryDefinitions.Builder().addPolicy(boundaryThreat).build();
TServiceTemplate networkServiceA = new TServiceTemplate.Builder("NetworkServiceA", emptyTopology).setTargetNamespace(demoNamespace).setBoundaryDefinitions(boundaryDefinitions).setSubstitutableNodeType(new QName(demoNamespace, "MyGroupA")).build();
TServiceTemplate networkServiceB = new TServiceTemplate.Builder("NetworkServiceB", emptyTopology).setTargetNamespace(demoNamespace).setBoundaryDefinitions(boundaryDefinitions).setSubstitutableNodeType(new QName(demoNamespace, "MyGroupB")).build();
TNodeType myNodeType = new TNodeType.Builder("MyNode").setTargetNamespace(demoNamespace).build();
TPolicy nodeTemplateThreat = new TPolicy.Builder(QName.valueOf(ThreatModelingConstants.THREAT_POLICY_ID)).setPolicyRef(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MyThreat")).setName("MyThreat").build();
TNodeTemplate myNodeTemplate = new TNodeTemplate.Builder("myNodeTemplate", new QName(demoNamespace, "MyNode")).addPolicy(nodeTemplateThreat).build();
TTopologyTemplate myTopology = new TTopologyTemplate.Builder().addNodeTemplate(myNodeTemplate).build();
TServiceTemplate myService = new TServiceTemplate.Builder("MyService", myTopology).setTargetNamespace(demoNamespace).build();
repository.setElement(new ServiceTemplateId(demoNamespace, "NetworkServiceA", false), networkServiceA);
repository.setElement(new ServiceTemplateId(demoNamespace, "NetworkServiceB", false), networkServiceB);
repository.setElement(new NodeTypeId(demoNamespace, "MyGroupA", false), svnfGroupA);
repository.setElement(new NodeTypeId(demoNamespace, "MyGroupB", false), svnfGroupB);
repository.setElement(new NodeTypeId(demoNamespace, "MyNode", false), myNodeType);
repository.setElement(new ServiceTemplateId(demoNamespace, "MyService", false), myService);
ThreatModeling tm = new ThreatModeling(new ServiceTemplateId(demoNamespace, "MyService", false), repository);
ThreatAssessment assessment = tm.getServiceTemplateThreats();
Threat asessedThreat = assessment.getThreats().get(new QName(ThreatModelingConstants.THREATMODELING_NAMESPACE, "MyThreat"));
assertEquals("MyThreat", asessedThreat.getTemplateName());
assertTrue(asessedThreat.getMitigations().contains(new QName(demoNamespace, "MyGroupA")));
assertTrue(asessedThreat.getMitigations().contains(new QName(demoNamespace, "MyGroupB")));
assertTrue(assessment.getSVNFs().isEmpty());
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ThreatModelingUtilsWithGitBackendRepositoryTest method checkIsOfTypeOrInheritsFromSVNF.
@Test
public void checkIsOfTypeOrInheritsFromSVNF() throws Exception {
this.setRevisionTo("origin/plain");
String namespace = "http://example.com";
QName base = new QName(namespace, "BASE");
QName otherBase = new QName(namespace, "OTHER_BASE");
QName childA = new QName(namespace, "CHILD_A");
QName childB = new QName(namespace, "CHILD_B");
TNodeType baseType = new TNodeType.Builder("BASE").setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).build();
TNodeType otherBaseType = new TNodeType.Builder("BASE").build();
TNodeType childAType = new TNodeType.Builder("CHILD_A").setAbstract(true).setDerivedFrom(base).build();
TNodeType childBType = new TNodeType.Builder("CHILD_B").setAbstract(true).setDerivedFrom(otherBase).build();
repository.setElement(new NodeTypeId(base), baseType);
repository.setElement(new NodeTypeId(otherBase), otherBaseType);
repository.setElement(new NodeTypeId(childA), childAType);
repository.setElement(new NodeTypeId(childB), childBType);
ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
assertTrue(tmu.isOfTypeOrInheritsFromSVNF(base));
assertTrue(tmu.isOfTypeOrInheritsFromSVNF(childA));
assertFalse(tmu.isOfTypeOrInheritsFromSVNF(otherBase));
assertFalse(tmu.isOfTypeOrInheritsFromSVNF(childB));
}
Aggregations