Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
MontiSecArc
Commits
4480d060
Commit
4480d060
authored
Nov 12, 2014
by
Paff
Browse files
transformation and analysis in a workflow in order to work with the ast
parent
ec65e538
Changes
11
Hide whitespace changes
Inline
Side-by-side
montiSecArcAnalysis/src/main/java/secarc/MontiSecArcAnalysis.java
View file @
4480d060
...
...
@@ -42,15 +42,15 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
/**
* Factory method for {@link MontiSecArcAnalysis}.l
*/
public
static
MontiSecArcAnalysis
newLanguage
(
ILanguage
component
,
List
<
String
>
analysisParameter
,
boolean
critical
,
String
analysisConfPath
)
{
return
new
MontiSecArcAnalysis
(
component
,
analysisParameter
,
critical
,
analysisConfPath
);
public
static
MontiSecArcAnalysis
newLanguage
(
ILanguage
component
,
List
<
String
>
analysisParameter
,
String
analysisConfPath
)
{
return
new
MontiSecArcAnalysis
(
component
,
analysisParameter
,
analysisConfPath
);
}
/**
* Constructor for secarc.MontiSecArcAnalysis
*/
@Inject
public
MontiSecArcAnalysis
(
final
ILanguage
component
,
List
<
String
>
analysisParameter
,
boolean
critical
,
String
analysisConfPath
)
{
public
MontiSecArcAnalysis
(
final
ILanguage
component
,
List
<
String
>
analysisParameter
,
String
analysisConfPath
)
{
super
(
component
);
// PARSING-SETUP
...
...
@@ -86,7 +86,6 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
MontiSecArcAnalysisVisitor
analysisVisitor
=
new
MontiSecArcAnalysisVisitor
();
analysisVisitor
.
setAdvanced
(
false
);
analysisVisitor
.
setAnalysisParameter
(
analysisParameter
);
analysisVisitor
.
setCiritical
(
critical
);
analysisWorkflow
.
setClient
(
analysisVisitor
);
//Add Workflow for Analysis for beginners
...
...
@@ -97,64 +96,31 @@ public final class MontiSecArcAnalysis extends MontiSecArc {
analysisWorkflow
.
setClient
(
analysisVisitor
);
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_ADVANCED
,
analysisWorkflow
);
this
.
addTrustlevelWhatIfWorkflow
(
analysisParameter
,
analysisConfPath
,
critical
);
this
.
addTrustlevelWhatIfWorkflow
(
analysisParameter
,
analysisConfPath
);
this
.
addCriticalPortWhatIfWorkflow
(
analysisParameter
,
analysisConfPath
,
critical
);
this
.
addCriticalPortWhatIfWorkflow
(
analysisParameter
,
analysisConfPath
);
}
private
void
addCriticalPortWhatIfWorkflow
(
List
<
String
>
analysisParameter
,
String
analysisConfPath
,
boolean
critical
)
{
private
void
addCriticalPortWhatIfWorkflow
(
List
<
String
>
analysisParameter
,
String
analysisConfPath
)
{
AnalysisCriticalPortTransformationWorkflow
<
MontiSecArcRoot
>
criticalPortTransformationWorkflow
=
new
AnalysisCriticalPortTransformationWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
);
addExecutionUnit
(
"transformCriticalPort"
,
criticalPortTransformationWorkflow
);
criticalPortTransformationWorkflow
.
setAdvanced
(
false
);
criticalPortTransformationWorkflow
.
setAnalysisConfPath
(
analysisConfPath
);
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_CRITICAL_PORT
,
criticalPortTransformationWorkflow
);
//Workflow for Analysis
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>
analysisTransformWorkflow
=
new
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>(
LANGUAGE_ROOT
);
//AnalysisCreator
analysisTransformWorkflow
.
setAnalysis
(
MontiSecArcAnalysisCreator
.
createAnalysis
(
analysisConfPath
));
//AnalysisConfiguratin
analysisTransformWorkflow
.
setAnalysisConfiguration
(
MontiSecArcAnalysisCreator
.
createConfig
());
//Visitor for Analysis
MontiSecArcAnalysisVisitor
analysisTransfromVisitor
=
new
MontiSecArcAnalysisVisitor
();
analysisTransfromVisitor
.
setAdvanced
(
false
);
analysisTransfromVisitor
.
setAnalysisParameter
(
analysisParameter
);
analysisTransfromVisitor
.
setCiritical
(
critical
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
//Add Workflow for Analysis for beginners: what if
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_CRITICAL_PORT
,
analysisTransformWorkflow
);
//Add Workflow for Analysis for advanced users
analysisTransfromVisitor
.
setAdvanced
(
true
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
//Add Workflow for Analysis for advanced users: what if
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF_CRITICAL_PORT
,
analysisTransformWorkflow
);
criticalPortTransformationWorkflow
.
setAdvanced
(
true
);
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_CRITICAL_PORT
,
criticalPortTransformationWorkflow
);
}
private
void
addTrustlevelWhatIfWorkflow
(
List
<
String
>
analysisParameter
,
String
analysisConfPath
,
boolean
critical
)
{
private
void
addTrustlevelWhatIfWorkflow
(
List
<
String
>
analysisParameter
,
String
analysisConfPath
)
{
AnalysisTrustlevelTransformationWorkflow
<
MontiSecArcRoot
>
trustlevelTransformationWorkflow
=
new
AnalysisTrustlevelTransformationWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
);
trustlevelTransformationWorkflow
.
setAnalysisParameter
(
analysisParameter
);
addExecutionUnit
(
"transformTrustlevel"
,
trustlevelTransformationWorkflow
);
//Workflow for Analysis
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>
analysisTransformWorkflow
=
new
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>(
LANGUAGE_ROOT
);
//AnalysisCreator
analysisTransformWorkflow
.
setAnalysis
(
MontiSecArcAnalysisCreator
.
createAnalysis
(
analysisConfPath
));
//AnalysisConfiguratin
analysisTransformWorkflow
.
setAnalysisConfiguration
(
MontiSecArcAnalysisCreator
.
createConfig
());
//Visitor for Analysis
MontiSecArcAnalysisVisitor
analysisTransfromVisitor
=
new
MontiSecArcAnalysisVisitor
();
analysisTransfromVisitor
.
setAdvanced
(
false
);
analysisTransfromVisitor
.
setAnalysisParameter
(
analysisParameter
);
analysisTransfromVisitor
.
setCiritical
(
critical
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
//Add Workflow for Analysis for beginners: what if
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_TRUSTLEVEL
,
analysisTransformWorkflow
);
trustlevelTransformationWorkflow
.
setAdvanced
(
false
);
trustlevelTransformationWorkflow
.
setAnalysisConfPath
(
analysisConfPath
);
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_TRUSTLEVEL
,
trustlevelTransformationWorkflow
);
//Add Workflow for Analysis for advanced users
analysisTransfromVisitor
.
setAdvanced
(
true
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
//Add Workflow for Analysis for advanced users: what if
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF_TRUSTLEVEL
,
analysisTransformWorkflow
);
trustlevelTransformationWorkflow
.
setAdvanced
(
true
);
addExecutionUnit
(
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_ADVANCED_WHAT_IF_TRUSTLEVEL
,
trustlevelTransformationWorkflow
);
}
/**
...
...
montiSecArcAnalysis/src/main/java/secarc/MontiSecArcAnalysisTool.java
View file @
4480d060
...
...
@@ -33,30 +33,14 @@ public class MontiSecArcAnalysisTool extends ETSTool {
public
static
void
main
(
String
[]
arguments
)
{
MCG
.
initMonticoreGlobals
();
List
<
String
>
analysisParameter
=
getAnalysisParameter
(
arguments
);
boolean
critical
=
isAnalysisCritical
(
arguments
);
String
analysisConfPath
=
getAnalysisConfPath
(
arguments
);
MontiSecArcAnalysisTool
tool
=
new
MontiSecArcAnalysisTool
(
cleanArgumentList
(
arguments
),
analysisParameter
,
critical
,
analysisConfPath
);
MontiSecArcAnalysisTool
tool
=
new
MontiSecArcAnalysisTool
(
cleanArgumentList
(
arguments
),
analysisParameter
,
analysisConfPath
);
tool
.
init
();
tool
.
run
();
}
/**
* Checks if the analysis shall be used for critical ports
*
* @param arguments
* @return true if analysis parameter -crictical is used
*/
protected
static
boolean
isAnalysisCritical
(
String
[]
arguments
)
{
for
(
String
argument
:
arguments
)
{
if
(
argument
.
equals
(
MontiSecArcConstants
.
ANALYSIS_CIRITICAL_PORTS
))
{
return
true
;
}
}
return
false
;
}
/**
* Path to config file
*
...
...
@@ -159,14 +143,14 @@ public class MontiSecArcAnalysisTool extends ETSTool {
*
* @param arguments
*/
public
MontiSecArcAnalysisTool
(
String
[]
arguments
,
List
<
String
>
analysisParameter
,
boolean
critical
,
String
analysisConfPath
)
{
public
MontiSecArcAnalysisTool
(
String
[]
arguments
,
List
<
String
>
analysisParameter
,
String
analysisConfPath
)
{
super
(
arguments
);
Injector
injector
=
Guice
.
createInjector
(
new
MontiSecArcDefaultModule
());
InjectorProvider
.
setInjector
(
injector
);
LanguageFamily
languageFamily
=
new
LanguageFamily
();
languageFamily
.
addLanguage
(
MontiSecArcAnalysis
.
newLanguage
(
injector
.
getInstance
(
MontiSecArcComponent
.
class
),
analysisParameter
,
critical
,
analysisConfPath
));
languageFamily
.
addLanguage
(
MontiSecArcAnalysis
.
newLanguage
(
injector
.
getInstance
(
MontiSecArcComponent
.
class
),
analysisParameter
,
analysisConfPath
));
setLanguages
(
languageFamily
);
// set default CoCos
...
...
montiSecArcAnalysis/src/main/java/secarc/ets/check/MontiSecArcAnalysisVisitor.java
View file @
4480d060
...
...
@@ -126,11 +126,6 @@ public class MontiSecArcAnalysisVisitor extends CheckWorkflowClient {
*/
private
List
<
String
>
analysisParameter
;
/**
* Analysis only for critical ports
*/
private
boolean
critical
=
false
;
private
int
factorSum
=
0
;
...
...
@@ -154,10 +149,6 @@ public class MontiSecArcAnalysisVisitor extends CheckWorkflowClient {
this
.
analysisParameter
=
analysisParameter
;
}
public
void
setCiritical
(
boolean
critical
)
{
this
.
critical
=
critical
;
}
public
int
getFactorSum
()
{
return
factorSum
;
}
...
...
@@ -236,7 +227,7 @@ public class MontiSecArcAnalysisVisitor extends CheckWorkflowClient {
}
}
catch
(
AmbigousException
e
)
{
// not checked here
e
.
printStackTrac
e
();
MCG
.
getLogger
().
info
(
e
.
getMessag
e
()
)
;
}
}
...
...
montiSecArcAnalysis/src/main/java/secarc/ets/transform/criticalport/AnalysisCriticalPortTransformationWorkflow.java
View file @
4480d060
...
...
@@ -7,12 +7,20 @@ import interfaces2.resolvers.Resolver;
import
java.util.Map
;
import
secarc._ast.ASTMCCompilationUnit
;
import
secarc._tool.MontiSecArcRoot
;
import
secarc.ets.check.MontiSecArcAnalysisCreator
;
import
secarc.ets.check.MontiSecArcAnalysisVisitor
;
import
secarc.ets.check.MontiSecArcAnalysisWorkflow
;
import
mc.DSLWorkflow
;
import
mc.ast.ASTNode
;
import
mc.ast.InheritanceVisitor
;
public
class
AnalysisCriticalPortTransformationWorkflow
<
T
extends
MontiSecArcRoot
>
extends
DSLWorkflow
<
T
>
{
boolean
advanced
=
false
;
String
analysisConfPath
=
""
;
/**
* @param responsibleClass class of the dsl root
...
...
@@ -47,20 +55,49 @@ public class AnalysisCriticalPortTransformationWorkflow<T extends MontiSecArcRoo
return
;
}
PreAnalysisCriticalPortTransformationVisitor
preVisitor
=
new
PreAnalysisCriticalPortTransformationVisitor
(
dslroot
);
//Elements which are needed for analysis
PreAnalysisCriticalPortTransformationVisitor
preVisitor
=
new
PreAnalysisCriticalPortTransformationVisitor
(
dslroot
);
preVisitor
.
setResolver
(
resolver
);
preVisitor
.
setNodesToNameSpaces
(
nodesToNameSpaces
);
//Copy AST for this workflow
ASTMCCompilationUnit
astCopy
=
dslroot
.
getAst
().
deepClone
();
InheritanceVisitor
.
run
(
preVisitor
,
dslroot
.
getAst
());
//Delete Elements which are not needed
AnalysisCriticalPortTransformationVisitor
visitorTransform
=
new
AnalysisCriticalPortTransformationVisitor
(
dslroot
);
visitorTransform
.
setResolver
(
resolver
);
visitorTransform
.
setNodesToNameSpaces
(
nodesToNameSpaces
);
visitorTransform
.
setEntries
(
preVisitor
.
getEntries
());
InheritanceVisitor
.
run
(
visitorTransform
,
dslroot
.
getAst
());
//Analysis for transformed Entries
//Workflow for Analysis
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>
analysisTransformWorkflow
=
new
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
);
//AnalysisCreator
analysisTransformWorkflow
.
setAnalysis
(
MontiSecArcAnalysisCreator
.
createAnalysis
(
analysisConfPath
));
//AnalysisConfiguratin
analysisTransformWorkflow
.
setAnalysisConfiguration
(
MontiSecArcAnalysisCreator
.
createConfig
());
//Visitor for Analysis
MontiSecArcAnalysisVisitor
analysisTransfromVisitor
=
new
MontiSecArcAnalysisVisitor
();
analysisTransfromVisitor
.
setAdvanced
(
advanced
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
analysisTransformWorkflow
.
run
(
dslroot
);
//Set original AST
dslroot
.
setAst
(
astCopy
);
}
public
void
setAdvanced
(
boolean
advanced
)
{
this
.
advanced
=
advanced
;
}
public
void
setAnalysisConfPath
(
String
analysisConfPath
)
{
this
.
analysisConfPath
=
analysisConfPath
;
}
}
montiSecArcAnalysis/src/main/java/secarc/ets/transform/trustlevel/AnalysisTrustlevelTransformationVisitor.java
View file @
4480d060
...
...
@@ -4,6 +4,7 @@ import interfaces2.namespaces.NameSpace;
import
interfaces2.resolvers.AmbigousException
;
import
interfaces2.resolvers.Resolver
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -11,13 +12,11 @@ import com.google.common.base.Optional;
import
secarc._ast.ASTSecArcFilterComponent
;
import
secarc._ast.ASTSecArcTrustLevel
;
import
secarc._tool.MontiSecArcRoot
;
import
secarc.ets.entries.SecComponentEntry
;
import
secarc.ets.entries.TrustlevelEntry
;
import
mc.ast.ASTNode
;
import
mc.ast.ConcreteVisitor
;
import
mc.literals._ast.ASTIntLiteral
;
import
mc.umlp.arcd.ets.entries.ComponentEntry
;
public
class
AnalysisTrustlevelTransformationVisitor
extends
ConcreteVisitor
{
...
...
@@ -28,6 +27,10 @@ public class AnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
protected
Map
<
ASTNode
,
NameSpace
>
nodesToNameSpaces
;
protected
Map
<
String
,
TrustlevelEntry
>
actualTrustlevels
=
new
HashMap
<
String
,
TrustlevelEntry
>();
protected
boolean
reverse
=
false
;
/**
*
* @param dslroot dsl root to use
...
...
@@ -40,6 +43,18 @@ public class AnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
this
.
analysisParameter
=
analysisParameter
;
}
public
void
setActualTrustlevel
(
Map
<
String
,
TrustlevelEntry
>
actualTrustlevels
)
{
this
.
actualTrustlevels
=
actualTrustlevels
;
}
public
Map
<
String
,
TrustlevelEntry
>
getActualTrustlevel
()
{
return
this
.
actualTrustlevels
;
}
public
void
isReverse
(
boolean
reverse
)
{
this
.
reverse
=
reverse
;
}
public
void
visit
(
ASTSecArcFilterComponent
node
)
{
ComponentEntry
compEntry
=
null
;
try
{
...
...
@@ -55,14 +70,24 @@ public class AnalysisTrustlevelTransformationVisitor extends ConcreteVisitor {
if
(
analysisParameter
.
contains
(
compEntry
.
getName
()))
{
Optional
<
TrustlevelEntry
>
trustlevel
=
((
SecComponentEntry
)
compEntry
).
getTrustlevel
();
TrustlevelEntry
value
=
null
;
if
(
trustlevel
.
isPresent
())
{
value
=
trustlevel
.
get
();
if
(
reverse
)
{
if
(
trustlevel
.
isPresent
())
{
value
=
trustlevel
.
get
();
value
.
setValue
(
actualTrustlevels
.
get
(
compEntry
.
getName
()).
getValue
());
value
.
setRelative
(
actualTrustlevels
.
get
(
compEntry
.
getName
()).
isPositive
());
}
else
{
((
SecComponentEntry
)
compEntry
).
setTrustlevel
(
null
);
}
}
else
{
value
=
new
TrustlevelEntry
();
if
(
trustlevel
.
isPresent
())
{
value
=
trustlevel
.
get
();
actualTrustlevels
.
put
(
compEntry
.
getName
(),
new
TrustlevelEntry
(
value
.
getValue
(),
value
.
isPositive
()));
}
else
{
value
=
new
TrustlevelEntry
();
}
value
.
setValue
(
1
);
value
.
setRelative
(
false
);
}
value
.
setValue
(
1
);
value
.
setRelative
(
false
);
((
SecComponentEntry
)
compEntry
).
setTrustlevel
(
value
);
}
}
...
...
montiSecArcAnalysis/src/main/java/secarc/ets/transform/trustlevel/AnalysisTrustlevelTransformationWorkflow.java
View file @
4480d060
...
...
@@ -12,11 +12,19 @@ import mc.DSLWorkflow;
import
mc.ast.ASTNode
;
import
mc.ast.InheritanceVisitor
;
import
secarc._tool.MontiSecArcRoot
;
import
secarc.ets.check.MontiSecArcAnalysisCreator
;
import
secarc.ets.check.MontiSecArcAnalysisVisitor
;
import
secarc.ets.check.MontiSecArcAnalysisWorkflow
;
import
secarc.ets.entries.TrustlevelEntry
;
public
class
AnalysisTrustlevelTransformationWorkflow
<
T
extends
MontiSecArcRoot
>
extends
DSLWorkflow
<
T
>
{
private
List
<
String
>
analysisParameter
;
boolean
advanced
=
false
;
String
analysisConfPath
=
""
;
/**
* @param responsibleClass class of the dsl root
*/
...
...
@@ -50,17 +58,48 @@ public class AnalysisTrustlevelTransformationWorkflow<T extends MontiSecArcRoot>
return
;
}
AnalysisTrustlevelTransformationVisitor
visitor
=
new
AnalysisTrustlevelTransformationVisitor
(
dslroot
);
//Transform entries
AnalysisTrustlevelTransformationVisitor
visitor
=
new
AnalysisTrustlevelTransformationVisitor
(
dslroot
);
visitor
.
setAnalysisParameter
(
analysisParameter
);
visitor
.
setResolver
(
resolver
);
visitor
.
setNodesToNameSpaces
(
nodesToNameSpaces
);
visitor
.
isReverse
(
false
);
InheritanceVisitor
.
run
(
visitor
,
dslroot
.
getAst
());
Map
<
String
,
TrustlevelEntry
>
actualTrustlevels
=
visitor
.
getActualTrustlevel
();
//Analysis for transformed Entries
//Workflow for Analysis
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>
analysisTransformWorkflow
=
new
MontiSecArcAnalysisWorkflow
<
MontiSecArcRoot
>(
MontiSecArcRoot
.
class
);
//AnalysisCreator
analysisTransformWorkflow
.
setAnalysis
(
MontiSecArcAnalysisCreator
.
createAnalysis
(
analysisConfPath
));
//AnalysisConfiguratin
analysisTransformWorkflow
.
setAnalysisConfiguration
(
MontiSecArcAnalysisCreator
.
createConfig
());
//Visitor for Analysis
MontiSecArcAnalysisVisitor
analysisTransfromVisitor
=
new
MontiSecArcAnalysisVisitor
();
analysisTransfromVisitor
.
setAdvanced
(
advanced
);
analysisTransfromVisitor
.
setAnalysisParameter
(
analysisParameter
);
analysisTransformWorkflow
.
setClient
(
analysisTransfromVisitor
);
analysisTransformWorkflow
.
run
(
dslroot
);
//Reverse
visitor
.
isReverse
(
true
);
visitor
.
setActualTrustlevel
(
actualTrustlevels
);
InheritanceVisitor
.
run
(
visitor
,
dslroot
.
getAst
());
}
public
void
setAnalysisParameter
(
List
<
String
>
analysisParameter
)
{
this
.
analysisParameter
=
analysisParameter
;
}
public
void
setAdvanced
(
boolean
advanced
)
{
this
.
advanced
=
advanced
;
}
public
void
setAnalysisConfPath
(
String
analysisConfPath
)
{
this
.
analysisConfPath
=
analysisConfPath
;
}
}
montiSecArcAnalysis/src/test/java/secarc/MontiSecArcAnalysisTestTool.java
View file @
4480d060
...
...
@@ -16,7 +16,7 @@ public class MontiSecArcAnalysisTestTool extends MontiSecArcAnalysisTool {
*
*/
public
MontiSecArcAnalysisTestTool
(
String
[]
args
)
{
super
(
cleanArgumentList
(
args
),
getAnalysisParameter
(
args
),
isAnalysisCritical
(
args
),
getAnalysisConfPath
(
args
));
super
(
cleanArgumentList
(
args
),
getAnalysisParameter
(
args
),
getAnalysisConfPath
(
args
));
this
.
init
();
}
...
...
montiSecArcAnalysis/src/test/java/secarc/MontiSecArcAnalysisTransformationCriticalPortTest.java
0 → 100644
View file @
4480d060
package
secarc
;
public
class
MontiSecArcAnalysisTransformationCriticalPortTest
extends
TestWithSymtabAnalysis
<
MontiSecArcAnalysisTestTool
>
{
/**
*
*/
public
MontiSecArcAnalysisTransformationCriticalPortTest
()
{
super
(
MontiSecArcAnalysisTestTool
.
class
,
new
String
[]
{
"gen/conv"
});
}
/**
* Test if the transformation for critical ports is correct
*/
public
void
testCriticalPortTransformation
()
{
}
}
montiSecArcAnalysis/src/test/java/secarc/MontiSecArcAnalysisTransformationTrustlevelTest.java
0 → 100644
View file @
4480d060
package
secarc
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
interfaces2.namespaces.NameSpace
;
import
interfaces2.resolvers.AmbigousException
;
import
mc.MCG
;
import
mc.ast.ASTNode
;
import
mc.umlp.arcd._ast.ASTArcComponent
;
import
mc.umlp.arcd.ets.entries.ComponentEntry
;
import
org.junit.Test
;
import
secarc._tool.MontiSecArcRoot
;
import
secarc.ets.entries.SecComponentEntry
;
public
class
MontiSecArcAnalysisTransformationTrustlevelTest
extends
TestWithSymtabAnalysis
<
MontiSecArcAnalysisTestTool
>
{
/**
*
*/
public
MontiSecArcAnalysisTransformationTrustlevelTest
()
{
super
(
MontiSecArcAnalysisTestTool
.
class
,
new
String
[]
{
"gen/conv"
});
}
/**
* Test if parameter exists
*/
@Test
public
void
testParameterExistence
()
{
//First file
System
.
out
.
println
(
"EncryptedPathEndInLowTrustlevel.secarc"
);
String
parameter
=
"secarc.analysis.connector.EncryptedPathEndInLowTrustlevel.TargetHelp"
;
MontiSecArcAnalysisTestTool
tool
=
createTestToolWithoutJavaWhatIfTrustlevel
(
new
String
[]
{
"src/test/resources/secarc/analysis/connector/EncryptedPathEndInLowTrustlevel.secarc"
},
parameter
);
tool
.
init
();
assertTrue
(
tool
.
run
());
MontiSecArcRoot
root
=
(
MontiSecArcRoot
)
initSymtabForRoot
(
tool
,
"secarc.analysis.connector.EncryptedPathEndInLowTrustlevel"
);
ComponentEntry
entry
=
null
;
for
(
ASTNode
child
:
root
.
getAst
().
get_Children
())
{
if
(
child
instanceof
ASTArcComponent
)
{
try
{
entry
=
existComponent
(
parameter
,
getNameSpaceFor
(
child
));
break
;
}
catch
(
AmbigousException
e
)
{
// not checked here
MCG
.
getLogger
().
info
(
e
.
getMessage
());
}
}
}
if
(
entry
!=
null
)
{
assertEquals
(
true
,
((
SecComponentEntry
)
entry
).
getTrustlevel
().
isPresent
());
assertEquals
(
1
,
((
SecComponentEntry
)
entry
).
getTrustlevel
().
get
().
getValue
());
assertEquals
(
true
,
((
SecComponentEntry
)
entry
).
getTrustlevel
().
get
().
isPositive
());
}
assertEquals
(
9
,
handler
.
getWarnings
().
size
());
}
/**
* Test if parameter do not exist
*/
@Test
public
void
testWrongParameterExistence
()
{
//First file
System
.
out
.
println
(
"EncryptedPathEndInLowTrustlevel.secarc"
);
String
parameter
=
"secarc.analysis.connector.EncryptedPathEndInLowTrustlevel.TargetHel"
;
MontiSecArcAnalysisTestTool
tool
=
createTestToolWithoutJavaWhatIfTrustlevel
(
new
String
[]
{
"src/test/resources/secarc/analysis/connector/EncryptedPathEndInLowTrustlevel.secarc"
},
parameter
);
tool
.
init
();
assertTrue
(
tool
.
run
());
MontiSecArcRoot
root
=
(
MontiSecArcRoot
)
initSymtabForRoot
(
tool
,
"secarc.analysis.connector.EncryptedPathEndInLowTrustlevel"
);
ComponentEntry
entry
=
null
;
for
(
ASTNode
child
:
root
.
getAst
().
get_Children
())
{
if
(
child
instanceof
ASTArcComponent
)
{
try
{
entry
=
existComponent
(
parameter
,
getNameSpaceFor
(
child
));
break
;
}
catch
(
AmbigousException
e
)
{
// not checked here
MCG
.
getLogger
().
info
(
e
.
getMessage
());
}
}
}
assertEquals
(
null
,
entry
);
assertEquals
(
10
,
handler
.
getWarnings
().
size
());
}
protected
ComponentEntry
existComponent
(
String
parameter
,
NameSpace
np
)
throws
AmbigousException
{
ComponentEntry
entry
=
(
ComponentEntry
)
resolver
.
resolve
(
parameter
,
ComponentEntry
.
KIND
,
np
);
if
(
entry
!=
null
)
{
return
entry
;
}
else
{
for
(
NameSpace
npChild
:
np
.
getChildren
())
{
if
(
existComponent
(
parameter
,
npChild
)
!=
null
)
{
return
entry
;
}
}
}
return
null
;
}
}
montiSecArcAnalysis/src/test/java/secarc/TestWithSymtabAnalysis.java
View file @
4480d060
...
...
@@ -101,7 +101,6 @@ public class TestWithSymtabAnalysis<T extends ETSTool> extends
//Uses analysis workflow
ARG_SYNTHESIS
,
"secarc"
,
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS
,
whatIfElement
,
MontiSecArcConstants
.
ARG_ANALYSISCONFPATH
,
"/home/user/workspace/MA-Paff/03.Implementierung/montiSecArcAnalysis/src/main/conf/Analysis_Conf.txt"
,
ARG_SYNTHESIS
,
"secarc"
,
"transformTrustlevel"
,
ARG_SYNTHESIS
,
"secarc"
,
MontiSecArcConstants
.
ANALYSIS_WORKFLOW_BEGINNERS_WHAT_IF_TRUSTLEVEL
};
List
<
String
>
argsAsList
=
new
LinkedList
<
String
>();
argsAsList
.
addAll
(
Arrays
.
asList
(
args
));
...
...
@@ -126,6 +125,44 @@ public class TestWithSymtabAnalysis<T extends ETSTool> extends
return
tool
;
}
protected
T
createTestToolWithoutJavaTransformationCiritcalPort
(
String
[]
files
,
String
...
additionalModelPath
)
{