Commit 8674cbeb authored by Paff's avatar Paff
Browse files

analysis: derived roles for ports

parent 6469c4c5
/**
* Generated on Tue Oct 07 10:34:17 CEST 2014
* Generated on Wed Oct 08 10:07:44 CEST 2014
*/
config {
Require-Model:
......
/**
* Generated on Tue Oct 07 10:34:35 CEST 2014
* Generated on Wed Oct 08 10:08:12 CEST 2014
*/
config {
Require-Model:
......
......@@ -88,6 +88,11 @@ public enum MontiSecArcAnalysisErrorCodes implements IErrorCode {
/**
* Trustlevel of encrypted path is higher than the environment
*/
TrustlevelPathHigherThanEnvironment
TrustlevelPathHigherThanEnvironment,
/**
* Derives all roles for ports
*/
DerivedRolesPort,
}
package secarc.ets.analysis.role;
import java.util.ArrayList;
import java.util.List;
import interfaces2.resolvers.AmbigousException;
import mc.IErrorCode;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
import secarc.error.MontiSecArcAnalysisErrorCodes;
import secarc.ets.analysis.checker.Analysis;
import secarc.ets.analysis.checker.ISecAnalysisPortChecker;
import secarc.ets.check.MontiSecArcAnalysisConstants;
import secarc.ets.entries.RoleEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.SecPortEntry;
import secarc.ets.graph.ArchitectureGraph;
public class DerivedRolesPort extends Analysis implements
ISecAnalysisPortChecker {
public DerivedRolesPort() {
super(MontiSecArcAnalysisConstants.DERIVE_ROLES_PORT);
}
@Override
public void check(ASTArcPort node, SecPortEntry entry,
ArchitectureGraph graph) throws AmbigousException {
List<RoleEntry> roles = new ArrayList<RoleEntry>();
SecComponentEntry componentEntry = (SecComponentEntry) resolver.resolve(node.getMainParent().getName(), ComponentEntry.KIND, getNameSpaceFor(node.getMainParent()));
//Add all roles of the component
roles.addAll(componentEntry.getRoles());
//Delete all roles of other ports
List<PortEntry> ports = componentEntry.getAllPorts(loader, deserializers);
for(PortEntry port : ports) {
if(!port.equals(entry)) {
roles.removeAll(((SecPortEntry) port).getRoles());
}
}
StringBuilder sBuilder = new StringBuilder("The port " + entry.getName() + " has the following roles: ");
if(roles.size() > 0) {
sBuilder.append(roles.get(0).getName());
roles.remove(0);
} else {
return;
}
for(RoleEntry role : roles) {
sBuilder.append(", ");
sBuilder.append(role.getName());
}
addReport(sBuilder.toString(), node.get_SourcePositionStart());
}
@Override
public IErrorCode getErrorCode() {
return MontiSecArcAnalysisErrorCodes.DerivedRolesPort;
}
}
......@@ -58,6 +58,8 @@ public final class MontiSecArcAnalysisConstants {
public static final String DERIVED_ROLES_COMPONENT = "Derives all roles for components.";
public static final String DERIVE_ROLES_PORT = "Derives all roles for ports.";
public static final String ALL_IDENTITY = "Checks all analysis related to identity links.";
public static final String IDENTITY_WITH_ENCRYPTION = "Checks if the communication between two components is encrypted when an identity link is used.";
......
......@@ -20,6 +20,7 @@ import secarc.ets.analysis.port.ListCriticalPorts;
import secarc.ets.analysis.port.ListSystemIncomingPorts;
import secarc.ets.analysis.port.ListSystemOutgoingPorts;
import secarc.ets.analysis.role.DerivedRolesComponent;
import secarc.ets.analysis.role.DerivedRolesPort;
import secarc.ets.analysis.role.DerivedRolesThirdParty;
......@@ -154,6 +155,9 @@ public final class MontiSecArcAnalysisCreator {
//Derives roles for "normal " components
roleAnalysis.addChild(new DerivedRolesComponent());
//Derives roles for ports
roleAnalysis.addChild(new DerivedRolesPort());
//Analysis for identity
CompositeContextCondition identityAnalysis = new CompositeContextCondition(MontiSecArcAnalysisConstants.ALL_IDENTITY);
......
......@@ -117,8 +117,9 @@ public class MontiSecArcAnalysisTest extends TestWithSymtabAnalysis<MontiSecArcA
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedRolesComponent);
errorCodes.add(MontiSecArcAnalysisErrorCodes.TaintPropergation);
errorCodes.add(MontiSecArcAnalysisErrorCodes.IdentityWithEncryption);
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedRolesPort);
assertEquals(7, handler.getWarnings().size());
assertEquals(8, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -157,9 +158,10 @@ public class MontiSecArcAnalysisTest extends TestWithSymtabAnalysis<MontiSecArcA
List<MontiSecArcAnalysisErrorCodes> errorCodes = new ArrayList<MontiSecArcAnalysisErrorCodes>();
errorCodes.add(MontiSecArcAnalysisErrorCodes.IdentityWithEncryption);
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedRolesComponent);
errorCodes.add(MontiSecArcAnalysisErrorCodes.DerivedRolesPort);
errorCodes.add(MontiSecArcAnalysisErrorCodes.TaintPropergation);
assertEquals(8, handler.getWarnings().size());
assertEquals(10, handler.getWarnings().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment