Search in sources :

Example 6 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class ServiceTemplateResource method cullElementReferences.

private void cullElementReferences() {
    final TTopologyTemplate topology = this.getServiceTemplate().getTopologyTemplate();
    TBoundaryDefinitions boundaryDefs = this.getServiceTemplate().getBoundaryDefinitions();
    if (topology == null || boundaryDefs == null) {
        return;
    }
    if (boundaryDefs.getProperties() != null && boundaryDefs.getProperties().getPropertyMappings() != null) {
        for (Iterator<TPropertyMapping> it = boundaryDefs.getProperties().getPropertyMappings().iterator(); it.hasNext(); ) {
            TPropertyMapping propMapping = it.next();
            HasId targetObject = propMapping.getTargetObjectRef();
            if (!containsTarget(topology, targetObject)) {
                // cull the property mapping pointing towards a no-longer existing element
                it.remove();
            }
        }
    }
    if (boundaryDefs.getCapabilities() != null) {
        for (Iterator<TCapabilityRef> it = boundaryDefs.getCapabilities().iterator(); it.hasNext(); ) {
            TCapabilityRef ref = it.next();
            TCapability target = ref.getRef();
            if (!containsCapability(topology, target)) {
                // cull the capability referencing a no longer existing capability in the topology
                it.remove();
            }
        }
    }
    if (boundaryDefs.getRequirements() != null) {
        for (Iterator<TRequirementRef> it = boundaryDefs.getRequirements().iterator(); it.hasNext(); ) {
            TRequirementRef ref = it.next();
            TRequirement target = ref.getRef();
            if (!containsRequirement(topology, target)) {
                // cull the requirement referencing a no longer existing requirement in the topology
                it.remove();
            }
        }
    }
}
Also used : HasId(org.eclipse.winery.model.tosca.HasId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TCapability(org.eclipse.winery.model.tosca.TCapability) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 7 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class ThreatModelingUtils method getBoundaryDefinitionMitigationPolicies.

/**
 * Get all policies of a Service Template's boundary definitions that are of type "S-VNF.Mitigation"
 *
 * @param serviceTemplate to obtain policies of
 * @return a list of mitigation policies
 */
public List<TPolicy> getBoundaryDefinitionMitigationPolicies(TServiceTemplate serviceTemplate) {
    TBoundaryDefinitions boundaryDefinitions = serviceTemplate.getBoundaryDefinitions();
    List<TPolicy> mitigationPolicies = new ArrayList<>();
    // check if boundary definitions are not empty
    if (Objects.nonNull(boundaryDefinitions)) {
        // get all policies
        List<TPolicy> serviceTemplatePolicies = boundaryDefinitions.getPolicies();
        if (Objects.nonNull(serviceTemplatePolicies)) {
            mitigationPolicies = serviceTemplatePolicies.stream().filter((TPolicy policy) -> policy.getPolicyType().toString().equals(ThreatModelingConstants.MITIGATION_POLICY_ID)).collect(Collectors.toList());
        }
    }
    return mitigationPolicies;
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) ArrayList(java.util.ArrayList) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions)

Example 8 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions 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 9 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class ToCanonical method resolveReferences.

private TDefinitions resolveReferences(TDefinitions preliminary) {
    preliminary.getServiceTemplates().forEach(st -> {
        TTopologyTemplate topology = st.getTopologyTemplate();
        // if there's no topology, we can't have requirementRefs, capabilityRefs or relationshipTemplates
        if (topology == null) {
            return;
        }
        topology.getRelationshipTemplates().forEach(rt -> {
            rt.setTargetElement(resolveReference(rt.getTargetElement(), topology));
            rt.setSourceElement(resolveReference(rt.getSourceElement(), topology));
        });
        // iterate TBoundaryDefinitions for the Capability and Requirement refs
        TBoundaryDefinitions boundaries = st.getBoundaryDefinitions();
        if (boundaries == null) {
            return;
        }
        if (boundaries.getRequirements() != null) {
            boundaries.getRequirements().forEach(req -> req.setRef(resolveRequirement(req.getRef(), topology)));
        }
        if (boundaries.getCapabilities() != null) {
            boundaries.getCapabilities().forEach(cap -> cap.setRef(resolveCapability(cap.getRef(), topology)));
        }
    });
    return preliminary;
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) XTTopologyTemplate(org.eclipse.winery.model.tosca.xml.XTTopologyTemplate) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) XTBoundaryDefinitions(org.eclipse.winery.model.tosca.xml.XTBoundaryDefinitions)

Aggregations

TBoundaryDefinitions (org.eclipse.winery.model.tosca.TBoundaryDefinitions)9 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 TPolicy (org.eclipse.winery.model.tosca.TPolicy)5 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 QName (javax.xml.namespace.QName)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 HashSet (java.util.HashSet)2 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)2 TCapability (org.eclipse.winery.model.tosca.TCapability)2 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)2 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 ArrayList (java.util.ArrayList)1 Path (javax.ws.rs.Path)1 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)1 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1