Commit 12987085 authored by Paff's avatar Paff
Browse files

project for code generation montiSecArcBE

parent aad04029
......@@ -30,6 +30,7 @@
<modules>
<module>../lang-example</module>
<module>../montiSecArcAnalysis</module>
<module>../montiSecArcBE</module>
</modules>
<scm>
......
/**
* Generated on Thu Oct 23 17:24:18 CEST 2014
* Generated on Sun Oct 26 13:17:07 CET 2014
*/
config {
Require-Model:
......
......@@ -58,7 +58,7 @@ public enum MontiSecArcErrorCodes implements IErrorCode {
/**
* Unique definition of the Target
*/
UniqueIdentityDefintion,
UniqueDefinitionWithFullQualifiedName,
/**
* If accesscontrol is on, the roles must be defined in
......
......@@ -297,7 +297,7 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
IdentityEntry entry = (IdentityEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(name.getParts()), IdentityEntry.KIND, getNameSpaceFor(node.getMainParent()));
if (entry != null) {
for (ISecIdentityChecker cc : secIdentityChecker) {
cc.check(node, entry);
cc.check(node, entry, graph);
}
}
} catch (AmbigousException e) {
......
......@@ -60,7 +60,7 @@ public final class MontiSecArcContextConditionConstants {
public static final String UNIQUE_COMPONENT_ROLE = "Checks if for a component exists a unique role definition.";
public static final String IDENTITY_UNIQUE_DEFINITION = "Checks if the defintion of an identity link is unique.";
public static final String UNIQUE_DEFINITION_WITH_FULL_QUALIFIED_NAME = "Checks if the defintion of an identity link is unique.";
public static final String IDENTITY_CYCLE_CHECK = "Checks if the identity links build a cycle.";
......
......@@ -7,9 +7,10 @@ import java.util.Map;
import secarc.ets.cocos.common.ComponentExistence;
import secarc.ets.cocos.common.DifferentSourceAndTarget;
import secarc.ets.cocos.common.NamingConventions;
import secarc.ets.cocos.common.UniqueDefinitionWithFullQualifiedNames;
import secarc.ets.cocos.component.CompletenessThirdPartyComponent;
import secarc.ets.cocos.configuration.UniqueConfiguration;
import secarc.ets.cocos.identity.UniqueIdentityTarget;
import secarc.ets.cocos.identity.IdentityCycleCheck;
import secarc.ets.cocos.pep.AccessControlCoCo;
import secarc.ets.cocos.pep.RoleDefintionInSubcomponents;
import secarc.ets.cocos.pep.UniquePEP;
......@@ -147,15 +148,15 @@ public final class MontiSecArcContextConditionCreator {
//Unique ComponentRole defintion in AST
uniqueCoCo.addChild(new UniqueComponentRole());
//Identities links must be unique
uniqueCoCo.addChild(new UniqueIdentityTarget());
CompositeContextCondition identityCoCos = new CompositeContextCondition(MontiSecArcContextConditionConstants.ALL_IDENTITY);
identityCoCos.setLevel(Type.ERROR);
//Roles must be authenticated
identityCoCos.addChild(new RoleWithIdentity());
//No cycles allowed
identityCoCos.addChild(new IdentityCycleCheck());
CompositeContextCondition roleCoCos = new CompositeContextCondition(MontiSecArcContextConditionConstants.ALL_ROLES);
roleCoCos.setLevel(Type.ERROR);
......@@ -189,6 +190,9 @@ public final class MontiSecArcContextConditionCreator {
//Checks if the source and target of identity/trustlevelrelation are different
commonCoCos.addChild(new DifferentSourceAndTarget());
//Identity link and trustlevel relation must be unique
commonCoCos.addChild(new UniqueDefinitionWithFullQualifiedNames());
//CoCos for trustlevel relation
CompositeContextCondition trustlevelRelationCoCos = new CompositeContextCondition(MontiSecArcContextConditionConstants.ALL_TRUSTLEVEL_RELATION);
trustlevelRelationCoCos.setLevel(Type.ERROR);
......
......@@ -3,6 +3,7 @@ package secarc.ets.cocos.checkers;
import interfaces2.resolvers.AmbigousException;
import secarc._ast.ASTSecArcIdentity;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* Context condition checker interface for checking identity
......@@ -25,6 +26,6 @@ public interface ISecIdentityChecker {
* @param entry entry related identity entry to be checked
* @throws AmbigousException
*/
void check(ASTSecArcIdentity node, IdentityEntry entry) throws AmbigousException;
void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph) throws AmbigousException;
}
......@@ -16,6 +16,7 @@ import secarc.ets.cocos.checkers.ISecTrustlevelRelationChecker;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* Checks if the components exist for identity link and trustlevel relation
......@@ -45,7 +46,7 @@ public class ComponentExistence extends ContextCondition implements
* @see secarc.ets.cocos.checkers.ISecIdentityChecker#check(secarc._ast.ASTSecArcIdentity, secarc.ets.entries.IdentityEntry)
*/
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry)
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph)
throws AmbigousException {
String refSource = entry.getSource();
String refTarget = entry.getTarget();
......
......@@ -12,6 +12,7 @@ import secarc.ets.cocos.checkers.ISecIdentityChecker;
import secarc.ets.cocos.checkers.ISecTrustlevelRelationChecker;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* Checks if the source and target are different
......@@ -38,7 +39,7 @@ public class DifferentSourceAndTarget extends ContextCondition implements
* @see secarc.ets.cocos.checkers.ISecIdentityChecker#check(secarc._ast.ASTSecArcIdentity, secarc.ets.entries.IdentityEntry)
*/
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry)
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph)
throws AmbigousException {
innerCheck(entry.getSource(), entry.getTarget(), node);
}
......
package secarc.ets.cocos.common;
import java.util.ArrayList;
import java.util.List;
import interfaces2.resolvers.AmbigousException;
import mc.IErrorCode;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.SubComponentEntry;
import secarc._ast.ASTSecArcIdentity;
import secarc._ast.ASTSecArcTrustlevelRelation;
import secarc.error.MontiSecArcErrorCodes;
import secarc.ets.check.MontiSecArcContextConditionConstants;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
public class UniqueDefinitionWithFullQualifiedNames extends ComponentExistence {
public UniqueDefinitionWithFullQualifiedNames() {
super(MontiSecArcContextConditionConstants.UNIQUE_DEFINITION_WITH_FULL_QUALIFIED_NAME);
}
/*
* (non-Javadoc)
* @see secarc.ets.cocos.checkers.ISecIdentityChecker#check(secarc._ast.ASTSecArcIdentity, secarc.ets.entries.IdentityEntry)
*/
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph) throws AmbigousException {
String refSource = entry.getSource();
String refTarget = entry.getTarget();
SubComponentEntry sourceSubComoponent = innerCheck(node, node.getMainParent(), refSource);
SubComponentEntry sourceSubComponentCompare = null;
SubComponentEntry targetSubComoponent = innerCheck(node, node.getMainParent(), refTarget);
SubComponentEntry targetSubComponentCompare = null;
//Checked in another coco
if(sourceSubComoponent == null || targetSubComoponent == null) {
return;
}
SecComponentEntry sourceComponent = (SecComponentEntry) sourceSubComoponent.getComponentType().getBestKnownVersion();
SecComponentEntry targetComponent = (SecComponentEntry) targetSubComoponent.getComponentType().getBestKnownVersion();
//Number of identities
int count = 0;
//The definitions are in the source, target or in a supercomponent
for(IdentityEntry identityEntrySource : sourceComponent.getIdentities()) {
sourceSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getSource());
targetSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getTarget());
if(sourceSubComoponent.equals(sourceSubComponentCompare) && targetSubComoponent.equals(targetSubComponentCompare)) {
count++;
}
}
for(IdentityEntry identityEntrySource : targetComponent.getIdentities()) {
sourceSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getSource());
targetSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getTarget());
if(sourceSubComoponent.equals(sourceSubComponentCompare) && targetSubComoponent.equals(targetSubComponentCompare)) {
count++;
}
}
//For source
ASTArcComponent sourceNode = (ASTArcComponent) sourceComponent.getNode();
List<ComponentEntry> alreadyCheckedComponents = new ArrayList<ComponentEntry>();
while(sourceNode.getMainParent() != null) {
sourceNode = sourceNode.getMainParent();
sourceComponent = (SecComponentEntry) resolver.resolve(sourceNode.getName(), ComponentEntry.KIND, getNameSpaceFor(sourceNode));
alreadyCheckedComponents.add(sourceComponent);
for(IdentityEntry identityEntrySource : sourceComponent.getIdentities()) {
sourceSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getSource());
targetSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getTarget());
if(sourceSubComoponent.equals(sourceSubComponentCompare) && targetSubComoponent.equals(targetSubComponentCompare)) {
count++;
}
}
}
//For target
ASTArcComponent targetNode = (ASTArcComponent) targetComponent.getNode();
while(targetNode.getMainParent() != null) {
targetNode = targetNode.getMainParent();
targetComponent = (SecComponentEntry) resolver.resolve(targetNode.getName(), ComponentEntry.KIND, getNameSpaceFor(targetNode));
if(alreadyCheckedComponents.contains(targetComponent)) {
break;
}
for(IdentityEntry identityEntrySource : targetComponent.getIdentities()) {
sourceSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getSource());
targetSubComponentCompare = innerCheck(identityEntrySource.getNode(), ((ASTSecArcIdentity) identityEntrySource.getNode()).getMainParent(), identityEntrySource.getTarget());
if(sourceSubComoponent.equals(sourceSubComponentCompare) && targetSubComoponent.equals(targetSubComponentCompare)) {
count++;
}
}
}
if(count > 1) {
addReport("There is more than one identity link of the form: identity " + entry.getSource() + " -> " + entry.getTarget(), node.get_SourcePositionStart());
}
}
/*
* (non-Javadoc)
* @see secarc.ets.cocos.checkers.ISecTrustlevelRelationChecker#check(secarc._ast.ASTSecArcTrustlevelRelation, secarc.ets.entries.TrustlevelRelationEntry)
*/
@Override
public void check(ASTSecArcTrustlevelRelation node,
TrustlevelRelationEntry entry) throws AmbigousException {
String refLowerTrustlevelComponent = entry.getComponentWithLowerTrustlevel();
String refHigherTrustlevelComponent = entry.getComponentWithHigherTrustlevel();
SubComponentEntry lowerTrustlevelComoponent = innerCheck(node, node.getMainParent(), refLowerTrustlevelComponent);
SubComponentEntry higherTrustlevelComoponent = innerCheck(node, node.getMainParent(), refHigherTrustlevelComponent);
//Checked in other coco
if(lowerTrustlevelComoponent != null | higherTrustlevelComoponent != null) {
return;
}
}
/*
* (non-Javadoc)
* @see interfaces2.coco.ContextCondition#getErrorCode()
*/
@Override
public IErrorCode getErrorCode() {
return MontiSecArcErrorCodes.UniqueDefinitionWithFullQualifiedName;
}
}
package secarc.ets.cocos.identity;
import java.util.Set;
import org.jgrapht.alg.CycleDetector;
import mc.IErrorCode;
import interfaces2.STEntry;
import interfaces2.coco.ContextCondition;
import interfaces2.resolvers.AmbigousException;
import secarc._ast.ASTSecArcIdentity;
import secarc.error.MontiSecArcErrorCodes;
import secarc.ets.check.MontiSecArcContextConditionConstants;
import secarc.ets.cocos.checkers.ISecIdentityChecker;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.graph.ArchitectureGraph;
import secarc.ets.graph.Edge;
import secarc.ets.graph.Vertex;
public class IdentityCycleCheck extends ContextCondition implements ISecIdentityChecker {
public IdentityCycleCheck() {
super(MontiSecArcContextConditionConstants.IDENTITY_CYCLE_CHECK);
}
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph)
throws AmbigousException {
CycleDetector<Vertex<? extends STEntry>, Edge> cycleDetector = new CycleDetector<Vertex<? extends STEntry>, Edge>(graph.getRawGraph());
Set<Vertex<? extends STEntry>> setCycle = cycleDetector.findCyclesContainingVertex(Vertex.of(entry));
if(setCycle != null && !setCycle.isEmpty()) {
addReport("There is a cycle of identity links starting in " + entry, node.get_SourcePositionStart());
}
}
@Override
public IErrorCode getErrorCode() {
return MontiSecArcErrorCodes.IdentityCycleCheck;
}
}
package secarc.ets.cocos.identity;
import java.util.List;
import secarc.error.MontiSecArcErrorCodes;
import secarc.ets.check.MontiSecArcContextConditionConstants;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import interfaces2.coco.ContextCondition;
import mc.IErrorCode;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd.ets.check.coco.checker.IComponentChecker;
import mc.umlp.arcd.ets.entries.ComponentEntry;
/**
* Check if the identity link is unique
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public class UniqueIdentityTarget extends ContextCondition implements
IComponentChecker {
public UniqueIdentityTarget() {
super(MontiSecArcContextConditionConstants.IDENTITY_UNIQUE_DEFINITION);
}
/*
* (non-Javadoc)
* @see mc.umlp.arcd.ets.check.coco.checker.IComponentChecker#check(mc.umlp.arcd._ast.ASTArcComponent, mc.umlp.arcd.ets.entries.ComponentEntry)
*/
@Override
public void check(ASTArcComponent node, ComponentEntry entry) {
List<IdentityEntry> identityEntries = ((SecComponentEntry) entry).getIdentities();
//Check if Identities exist
if(identityEntries == null || identityEntries.isEmpty()) {
return;
}
for(int i = 0; i < identityEntries.size()-1; i++) {
for(int j = i+1; j < identityEntries.size(); j++) {
if(identityEntries.get(i).getName().equals(identityEntries.get(j).getName())) {
addReport("There is more than one identity link definition with the target " + identityEntries.get(i).getName() + ".", identityEntries.get(j).getSourcePosition());
break;
}
}
}
}
/*
* (non-Javadoc)
* @see interfaces2.coco.ContextCondition#getErrorCode()
*/
@Override
public IErrorCode getErrorCode() {
return MontiSecArcErrorCodes.UniqueIdentityDefintion;
}
}
......@@ -17,6 +17,7 @@ import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.TrustlevelEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* Checks if the relation between the two components is correct defined
......@@ -38,7 +39,7 @@ public class CorrectRelationBetweenTrustlevel extends ComponentExistence {
}
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry)
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph)
throws AmbigousException {
}
......
......@@ -64,14 +64,7 @@ public class ArchitectureGraphBuilder {
* The actual graph that we are building.
*/
private DirectedGraph<Vertex<? extends STEntry>, Edge> graph;
/**
* This message is thrown wrapped in an {@link IllegalStateException} if the
* given architecture model has (obvious) errors that permit the creation of
* the graph.
*/
private static final String INCONSISTENT_MODEL_ERROR = "Could not build graph due to inconsistency in the architecture model.";
/**
* Constructor for cc.clarc.lang.architecture.graph.ArchitectureGraphBuilder
*/
......@@ -461,6 +454,12 @@ public class ArchitectureGraphBuilder {
}
}
/**
* Find the full qualified component which is referenced in a identity link
* @param root
* @param fullQualifiedName
* @return reference component
*/
private ComponentEntry findFullQualifiedComponent(ComponentEntry root, String fullQualifiedName) {
int firstdot = fullQualifiedName.indexOf(".");
......@@ -484,6 +483,13 @@ public class ArchitectureGraphBuilder {
return findSubComponentFromRootFullQualifiedName(rootFullQualifiedName, fullQualifiedName);
}
/**
* Find root element of the full qualified name
* -> first part of the full qualified name
* @param current
* @param fullQualifiedName
* @return root of full qualified name
*/
private ComponentEntry findRootFromFullQualifiedName(ComponentEntry root, String name) {
for(SubComponentEntry subComponent : root.getSubComponents()) {
if(subComponent.getName().equals(name)) {
......@@ -498,6 +504,13 @@ public class ArchitectureGraphBuilder {
return null;
}
/**
* Find the full qualified component
*
* @param current
* @param fullQualifiedName
* @return refrenced component
*/
private ComponentEntry findSubComponentFromRootFullQualifiedName(ComponentEntry current, String fullQualifiedName) {
int firstdot = fullQualifiedName.indexOf(".");
String nameSubcomponent = "";
......
......@@ -85,10 +85,10 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
List<MontiSecArcErrorCodes> errorCodes = new ArrayList<MontiSecArcErrorCodes>();
errorCodes.add(MontiSecArcErrorCodes.ComponentExistence);
errorCodes.add(MontiSecArcErrorCodes.UniqueIdentityDefintion);
errorCodes.add(MontiSecArcErrorCodes.UniqueDefinitionWithFullQualifiedName);
errorCodes.add(MontiSecArcErrorCodes.DifferentSourceTarget);
assertEquals(3, handler.getErrors().size());
assertEquals(4, handler.getErrors().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......
......@@ -6,12 +6,12 @@ component IdentityLinkTwice {
trustlevel +1;
identity weak client -> server;
identity weak client -> server;
component Client client {
trustlevel +1;
identity weak client -> server;
}
component Server server {
......
/**
* Generated on Thu Oct 23 17:24:37 CEST 2014
* Generated on Sun Oct 26 13:18:26 CET 2014
*/
config {
Require-Model:
......
package secarc.ets.analysis.identity;
import interfaces2.resolvers.AmbigousException;
import mc.IErrorCode;
import secarc._ast.ASTSecArcIdentity;
import secarc.ets.analysis.checker.Analysis;
import secarc.ets.analysis.checker.ISecAnalysisIdentityChecker;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.graph.ArchitectureGraph;
public class IdentityWithoutRoles extends Analysis implements
ISecAnalysisIdentityChecker {
public IdentityWithoutRoles(String checkedProperty) {
super(checkedProperty);
}
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry,
ArchitectureGraph graph) throws AmbigousException {
}
@Override
public IErrorCode getErrorCode() {
// TODO Auto-generated method stub
return null;
}
}
......@@ -11,6 +11,7 @@ import secarc.ets.check.MontiSecArcAnalysisConstants;
import secarc.ets.cocos.checkers.ISecIdentityChecker;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.graph.ArchitectureGraph;
/**
* Check if the trustlevel for the client is lower then the trustlevel for the server
......@@ -35,7 +36,7 @@ public class TrustlevelClientServer extends ContextCondition implements ISecIden
* @see secarc.ets.cocos.checkers.ISecIdentityChecker#check(secarc._ast.ASTSecArcIdentity, secarc.ets.entries.IdentityEntry)
*/
@Override
public void check(ASTSecArcIdentity node, IdentityEntry entry) throws AmbigousException {
public void check(ASTSecArcIdentity node, IdentityEntry entry, ArchitectureGraph graph) throws AmbigousException {
String refSource = entry.getSource();
String refTarget = entry.getTarget();
SecComponentEntry sourceComp = null;
......
......@@ -11,6 +11,7 @@ import secarc.ets.cocos.common.ComponentExistence;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.graph.ArchitectureGraph;
public class TrustlevelForTrustlevelRelation extends ComponentExistence {
......@@ -19,7 +20,7 @@ public class TrustlevelForTrustlevelRelation extends ComponentExistence {
}
@Override
public void check(ASTSecArcIdentity node,