Search in sources :

Example 46 with NodeTypeId

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);
}
Also used : PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 47 with NodeTypeId

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;
}
Also used : NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 48 with NodeTypeId

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");
    }
}
Also used : NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 49 with NodeTypeId

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());
}
Also used : QName(javax.xml.namespace.QName) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 50 with NodeTypeId

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));
}
Also used : QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.jupiter.api.Test)

Aggregations

NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)67 TNodeType (org.eclipse.winery.model.tosca.TNodeType)36 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 Test (org.junit.jupiter.api.Test)27 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)23 QName (javax.xml.namespace.QName)21 IRepository (org.eclipse.winery.repository.backend.IRepository)20 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)15 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)15 WineryVersion (org.eclipse.winery.common.version.WineryVersion)14 Response (javax.ws.rs.core.Response)13 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 ArrayList (java.util.ArrayList)9 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9