Skip to content

Commit 3bc26f9

Browse files
committed
MLSecTop10: MLTop10Util extended; abstract check introduced; Output Integrity Check updated.
1 parent 506cd99 commit 3bc26f9

File tree

3 files changed

+247
-193
lines changed

3 files changed

+247
-193
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package carisma.check.mltop10checks.common;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.emf.ecore.resource.Resource;
6+
import org.eclipse.uml2.uml.Model;
7+
import org.eclipse.uml2.uml.Package;
8+
9+
import carisma.core.analysis.AnalysisHost;
10+
import carisma.core.analysis.DummyHost;
11+
import carisma.core.analysis.result.AnalysisResultMessage;
12+
import carisma.core.analysis.result.StatusType;
13+
import carisma.core.checks.CarismaCheckWithID;
14+
import carisma.core.checks.CheckParameter;
15+
16+
/**
17+
* Abstract super class for the ML Security Top 10 checks.
18+
*
19+
* @author Julian Flake
20+
* @author Alexaner Peikert
21+
*/
22+
public abstract class AbstractMLTop10Check implements CarismaCheckWithID {
23+
24+
public static String CHECK_ID;
25+
public static String CHECK_NAME;
26+
27+
/**
28+
* AnalysisHost for report.
29+
*/
30+
protected AnalysisHost analysisHost;
31+
32+
/**
33+
* The model to check.
34+
*/
35+
protected Model modelEl = null;
36+
37+
/**
38+
* A flag to store, whether at least one error has been detected.
39+
*/
40+
protected boolean errorDetected = false;
41+
42+
protected void addInfo(String message) {
43+
this.analysisHost.addResultMessage(new AnalysisResultMessage(StatusType.INFO, message));
44+
}
45+
46+
protected void addWarning(String message) {
47+
this.analysisHost.addResultMessage(new AnalysisResultMessage(StatusType.WARNING, message));
48+
}
49+
50+
protected void addError(String message) {
51+
this.analysisHost.addResultMessage(new AnalysisResultMessage(StatusType.ERROR, message));
52+
this.errorDetected = true;
53+
}
54+
55+
@Override
56+
public String getCheckID() {
57+
return CHECK_ID;
58+
}
59+
60+
@Override
61+
public String getName() {
62+
return CHECK_NAME;
63+
}
64+
65+
@Override
66+
public final boolean perform(final Map<String, CheckParameter> parameters, final AnalysisHost newHost) {
67+
if (newHost != null) {
68+
this.analysisHost = newHost;
69+
} else {
70+
this.analysisHost = new DummyHost(true);
71+
}
72+
Resource currentModel = this.analysisHost.getAnalyzedModel();
73+
if (currentModel.getContents().isEmpty()) {
74+
this.addError("Empty model");
75+
this.analysisHost.appendLineToReport("Empty model");
76+
return false;
77+
}
78+
if (!(currentModel.getContents().get(0) instanceof Package)) {
79+
this.addError("Content is not a model!");
80+
this.analysisHost.appendLineToReport("Content is not a model!");
81+
return false;
82+
}
83+
this.modelEl = (Model) currentModel.getContents().get(0);
84+
return runCheck();
85+
}
86+
87+
public abstract boolean runCheck();
88+
89+
}

0 commit comments

Comments
 (0)