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();
}
}
}
}
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;
}
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());
}
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;
}
Aggregations