Commit 4e0c8a39 authored by Paff's avatar Paff
Browse files

running example in montisecarc

parent 999e9d6a
......@@ -5,6 +5,7 @@ import java.util.Map;
import secarc._ast.ASTSecArcFilterComponent;
import secarc._ast.ASTSecArcPort;
import secarc._ast.ASTSecArcRole;
import mc.ast.ASTCNode;
import mc.types._ast.ASTTypeParameters;
......@@ -110,19 +111,19 @@ public final class MontiSecArcConstants extends Interfaces2Constants {
* List of MontiSecArc AST nodes that have public visibility in the symbol table.
*/
public static final List<Class<? extends ASTCNode>> MONTI_SEC_ARC_PUBLIC_NODES = ImmutableList.of(ASTArcComponent.class, ASTArcPort.class,
ASTMCCompilationUnit.class, ASTTypeParameters.class, ASTArcParameter.class, ASTSecArcFilterComponent.class, ASTSecArcPort.class);
ASTMCCompilationUnit.class, ASTTypeParameters.class, ASTArcParameter.class, ASTSecArcFilterComponent.class, ASTSecArcPort.class, ASTSecArcRole.class);
/**
* Holds abbreviations mapped to AST-node names.
*/
protected static final Map<String, String> GENERATOR_CONSTANTS = ImmutableMap.of("montiarccomponent", ASTMCCompilationUnit.class.getName());
protected static final Map<String, String> GENERATOR_CONSTANTS = ImmutableMap.of("montisecarccomponent", ASTMCCompilationUnit.class.getName());
/**
* Nodes that build up name spaces.
*/
static final Class<?>[] NODES_WITH_NAMESPACE = {ASTArcComponent.class, ASTMCCompilationUnit.class,
ASTArcComponentImplementation.class, ASTMontiArcInvariant.class, ASTSecArcPort.class, ASTSecArcFilterComponent.class,
ASTArcPort.class,
ASTArcPort.class,
};
/**
......
......@@ -234,7 +234,7 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
cc.check(node, entry);
}
}
} catch (AmbigousException e) {
} catch (AmbigousException | EntryLoadingErrorException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
......
package secarc.ets.cocos.checkers;
import interfaces2.helper.EntryLoadingErrorException;
import interfaces2.resolvers.AmbigousException;
import secarc._ast.ASTSecArcPEP;
import secarc.ets.entries.PEPEntry;
......@@ -25,6 +26,6 @@ public interface ISecPepChecker {
* @param entry entry related pep to be checked
* @throws AmbigousException
*/
void check(ASTSecArcPEP node, PEPEntry entry) throws AmbigousException;
void check(ASTSecArcPEP node, PEPEntry entry) throws AmbigousException, EntryLoadingErrorException;
}
......@@ -44,40 +44,42 @@ public class UniqueDefinitionWithFullQualifiedNames extends ComponentExistence {
}
SecComponentEntry sourceComponent = (SecComponentEntry) sourceSubComoponent.getComponentType().getBestKnownVersion();
sourceComponent.loadFullVersion(loader, deserializers);
SecComponentEntry targetComponent = (SecComponentEntry) targetSubComoponent.getComponentType().getBestKnownVersion();
//Number of identities
int count = 0;
//The definitions are in the source, target or in a supercomponent
count = countNumberIdentities(sourceComponent, sourceSubComoponent, targetSubComoponent, count);
count = countNumberIdentities(targetComponent, sourceSubComoponent, targetSubComoponent, count);
//For source
ASTArcComponent sourceNode = (ASTArcComponent) sourceComponent.getNode();
//If component is imported
if(sourceNode == null) {
sourceNode = node.getMainParent();
}
List<ComponentEntry> alreadyCheckedComponents = new ArrayList<ComponentEntry>();
while(sourceNode.getMainParent() != null) {
sourceNode = sourceNode.getMainParent();
while(sourceNode != null) {
sourceComponent = (SecComponentEntry) resolver.resolve(sourceNode.getName(), ComponentEntry.KIND, getNameSpaceFor(sourceNode));
alreadyCheckedComponents.add(sourceComponent);
count = countNumberIdentities(sourceComponent, sourceSubComoponent, targetSubComoponent, count);
sourceNode = sourceNode.getMainParent();
}
//For target
ASTArcComponent targetNode = (ASTArcComponent) targetComponent.getNode();
//If component is imported
if(targetNode == null) {
targetNode = node.getMainParent();
}
while(targetNode.getMainParent() != null) {
targetNode = targetNode.getMainParent();
while(targetNode != null) {
targetComponent = (SecComponentEntry) resolver.resolve(targetNode.getName(), ComponentEntry.KIND, getNameSpaceFor(targetNode));
if(alreadyCheckedComponents.contains(targetComponent)) {
break;
}
count = countNumberIdentities(targetComponent, sourceSubComoponent, targetSubComoponent, count);
targetNode = targetNode.getMainParent();
}
if(count > 1) {
......
package secarc.ets.cocos.pep;
import java.util.List;
import java.util.Set;
import mc.IErrorCode;
import mc.umlp.arcd.ArcdConstants;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.SubComponentEntry;
import interfaces2.ISTEntry;
import interfaces2.coco.ContextCondition;
import interfaces2.helper.EntryLoadingErrorException;
import interfaces2.loaders.InterfaceLoader;
import interfaces2.resolvers.AmbigousException;
import secarc._ast.ASTSecArcPEP;
import secarc.error.MontiSecArcErrorCodes;
......@@ -40,7 +45,7 @@ public class RoleDefintionInSubcomponents extends ContextCondition implements
* @see secarc.ets.cocos.checkers.ISecPepChecker#check(secarc._ast.ASTSecArcPEP, secarc.ets.entries.PEPEntry)
*/
@Override
public void check(ASTSecArcPEP node, PEPEntry entry) throws AmbigousException {
public void check(ASTSecArcPEP node, PEPEntry entry) throws AmbigousException, EntryLoadingErrorException {
//This check is not needed if accesscontrol is off
if(entry.isOff()) {
return;
......@@ -85,13 +90,17 @@ public class RoleDefintionInSubcomponents extends ContextCondition implements
*
* @param subComponentEntries
* @return boolean
* @throws EntryLoadingErrorException
*/
private boolean checkForRoles(List<SubComponentEntry> subComponentEntries) {
private boolean checkForRoles(List<SubComponentEntry> subComponentEntries) throws EntryLoadingErrorException {
if(subComponentEntries == null || subComponentEntries.isEmpty()) {
return false;
}
for(SubComponentEntry subComponentEntry : subComponentEntries) {
SecComponentEntry compType = (SecComponentEntry) subComponentEntry.getComponentType();
Set<ISTEntry> manuallyLoaded = InterfaceLoader.loadExported(getLoader(), compType.getName(), ArcdConstants.ST_KIND_PROTECTED, getDeserializers(),
compType.getExportedInterfaceKindToBeLoaded());
if(compType == null) {
return false;
}
......
......@@ -58,10 +58,12 @@ public class TrustlevelEntryDeserializer extends STEntryDeserializer {
TrustlevelEntry trustlevel = ((SecEntryFactory) arcdFactory).createTrustlevel();
Optional<Integer> value = object.<Integer> getAttributeValue("value");
Optional<Boolean> isPositiv = object.<Boolean> getAttributeValue("isPostiv");
String reason = object.<String> getAttributeValue("reason").get();
Optional<Boolean> isPositiv = object.<Boolean> getAttributeValue("isPositiv");
Optional<String> reason = object.<String> getAttributeValue("reason");
trustlevel.setReason(reason);
if(reason.isPresent()) {
trustlevel.setReason(reason.get());
}
checkArgument(isPositiv.isPresent());
trustlevel.setRelative(isPositiv.get());
checkArgument(value.isPresent());
......
......@@ -21,7 +21,7 @@ public class RoleEntry extends AbstractSTEntry<FilterEntry>{
/**
* Entry kind of component role
*/
public static final String KIND = "SecArcComponentRole";
public static final String KIND = "SecArcRole";
/**
* role for component
......
......@@ -126,6 +126,10 @@ public class SecComponentEntry extends MAComponentEntry {
* @param pep PEP for component
*/
public void setPEP(PEPEntry pep) {
SecComponentEntry bestKnown = (SecComponentEntry) getBestKnownVersion();
if (!bestKnown.equals(this)) {
bestKnown.setPEP(pep);
}
this.pep = pep;
}
......
package secarc.ets.entries;
import static com.google.common.base.Preconditions.checkArgument;
import interfaces2.ISTEntry;
import interfaces2.STEntryState;
import interfaces2.helper.EntryLoadingErrorException;
import interfaces2.loaders.InterfaceLoader;
import interfaces2.loaders.STEntryDeserializer;
import java.util.Collection;
import java.util.Set;
import mc.IModelloader;
import mc.umlp.arc.ets.entries.MASubComponentEntry;
import mc.umlp.arcd.ets.entries.ComponentEntry;
......@@ -33,5 +43,38 @@ public class SecSubComponentEntry extends MASubComponentEntry {
checkArgument(componentType instanceof SecComponentEntry);
super.setComponentType(componentType);
}
/* (non-Javadoc)
* @see interfaces2.STEntry#loadFullVersion(mc.IModelloader, java.util.Collection)
*/
@Override
public void loadFullVersion(IModelloader loader, Collection<STEntryDeserializer> deserializers) throws EntryLoadingErrorException {
// qualifies the component type
if (getComponentType().getEntryState() == STEntryState.FULL) {
return;
}
if (getComponentType().getEntryState() == STEntryState.UNQUALIFIED) {
throw new IllegalStateException();
}
String componentTypeName = getComponentType().getName();
Set<ISTEntry> entries = InterfaceLoader.loadExported(loader, componentTypeName, symtabKindToBeLoaded, deserializers,
getExportedInterfaceKindToBeLoaded());
if (entries != null) {
for (ISTEntry e : entries) {
if (e instanceof ComponentEntry) {
ComponentEntry te = (SecComponentEntry) e;
if (te.getName().equals(componentTypeName)) {
getComponentType().setEntryState(STEntryState.FULL, te);
setEntryState(STEntryState.FULL, this);
break;
}
}
}
}
if (getComponentType().getEntryState() != STEntryState.FULL) {
throw new EntryLoadingErrorException(this);
}
}
}
......@@ -18,27 +18,27 @@ public class MontiSecArcRunningExampleTest extends TestWithSymbolTableSec<MontiS
* @throws AmbigousException
* @throws CircluarDependencyException
*/
// @Test
// public void testRunningExample() throws CircluarDependencyException, AmbigousException {
// MontiSecArcTool tool = createTestToolWithAdditionalParameters(new String[] {"src/test/resources/secarc/cds/CashDeskSystem.secarc"}, new String[] {"src/test/resources"});
// tool.init();
//
// assertTrue(tool.run());
//
// }
@Test
public void testRunningExample() throws CircluarDependencyException, AmbigousException {
MontiSecArcTool tool = createTestToolWithAdditionalParameters(new String[] {"src/test/resources/secarc/cds/CashDeskSystem.secarc"}, new String[] {"src/test/resources"});
tool.init();
assertTrue(tool.run());
}
/**
* Test for Running Example in MontiSecArc
* @throws AmbigousException
* @throws CircluarDependencyException
*/
// @Test
// public void testSecRunningExample() throws CircluarDependencyException, AmbigousException {
// MontiSecArcTool tool = createTestToolWithAdditionalParameters(new String[] {"src/test/resources/secarc/seccds/CashDeskSystem.secarc"}, new String[] {"src/test/resources"});
// tool.init();
//
// assertTrue(tool.run());
//
// }
@Test
public void testSecRunningExample() throws CircluarDependencyException, AmbigousException {
MontiSecArcTool tool = createTestToolWithAdditionalParameters(new String[] {"src/test/resources/secarc/seccds/CashDeskSystem.secarc"}, new String[] {"src/test/resources"});
tool.init();
assertTrue(tool.run());
}
}
package secarc.seccds;
// import message types
import secarc.seccds.msg.*;
import java.awt.Image;
// import components
import secarc.seccds.fe.CashDesk;
import secarc.seccds.be.Bank;
import secarc.seccds.fe.Store;
component CashDeskSystem {
trustlevel -1;
autoconnect port;
autoinstantiate on;
accesscontrol on;
port
in Event newSale,
in Image barcode,
in String identifier,
in Event endSale,
out ProductData;
port
in Event cardPay,
in CardData,
in Integer pin,
out Boolean validation;
port
out Bill;
component IDP {
}
component CashDesk cashDesk
[encrypted bdOut -> bank.bankData; saleInformation -> store.saleInformation];
component Bank;
component Store;
connect encrypted bank.paymentAck -> cashDesk.paIn;
connect cashDesk -> store;
connect cashDesk.productData -> productData;
identity weak bank -> iDP;
identity weak iDP -> store;
}
\ No newline at end of file
package secarc.seccds.be;
// import message types
import secarc.seccds.msg.*;
component Bank {
trustlevel +3;
port
critical in BankData,
out PaymentAck;
access customer;
}
\ No newline at end of file
package secarc.seccds.fe;
// import message types
import secarc.seccds.msg.*;
import java.awt.Image;
component CashDesk {
trustlevel +1;
access cashier;
port
in Event newSale,
in Image barcode,
in String identifier,
out String identifier,
in Event endSale,
in ProductData,
in PaymentAck,
out ProductData;
port
in Event cardPay,
critical in CardData,
critical in Integer pin,
critical out BankData bdOut,
in PaymentAck paIn,
out Boolean validation;
port
out SaleInformation,
out Bill;
}
\ No newline at end of file
package secarc.seccds.fe;
// import message types
import secarc.seccds.msg.*;
component Store {
trustlevel +2;
access stockManager, storeManager, cashier;
connect store -> storeServer, data;
port
in String identifier,
out ProductData,
out PaymentAck;
port
in SaleInformation;
component (filter fString) StoreServer {
configuration confName;
cpe "cpeName";
port
in String identifier,
out Identifier;
}
component Data {
port
out ProductData,
out PaymentAck,
(filter fInformation) in SaleInformation filterInfo;
}
}
\ No newline at end of file
package secarc.seccds.msg;
public class BankData {
}
\ No newline at end of file
package secarc.seccds.msg;
public class Bill {
}
package secarc.seccds.msg;
public class CardData {
}
\ No newline at end of file
package secarc.seccds.msg;
public class Event {
}
\ No newline at end of file
package secarc.seccds.msg;
public class Identifier {
}
package secarc.seccds.msg;
public class PaymentAck {
}
\ No newline at end of file
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