Skip to content

Commit de8389a

Browse files
authored
Merge pull request #10 from secure-software-engineering/qwel-xml-export
Export QWEL XML file
2 parents 4544959 + ff1f049 commit de8389a

File tree

14 files changed

+529
-330
lines changed

14 files changed

+529
-330
lines changed

swan_assist/README.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,51 @@ The tool helps users that write static analyses to create list of SWAN for their
1313
Moreover, users can manually inspect the proper usage of the methods detected by SWAN.
1414

1515

16-
## Setting Up the Plugin
16+
## Downloading the Project
1717

18-
The project can be downloaded using any of the methods below. the project using either of the following methods:
19-
##### Method 1: Cloning Project
20-
1) Select the **File>Project from Version Control>Git** option, enter the repository’s URL and then select **Clone** to import the project.
21-
2) Go to **File>Project Structure** to edit the project settings.
22-
3) For **Project SDK**, select the most recent Java SDK version.
23-
4) Select **Modules** from the left panel/
24-
1) Click the **Add** button and then **Import Module**.
25-
2) In the window that appears, open the ``/swan_assist`` directory of the project.
18+
The project can be downloaded using either of the following methods:
2619

27-
##### Method 2: Downloading Project
28-
1) Download the project from Github and then use the **File>Project from Existing Resources** from the menu to import the project.
29-
2) Select the ``/swan_assist`` directory in the downloaded project's root folder and select **Open**.
20+
##### Method 1: Cloning the Project
21+
1) Select the **File>Project from Version Control>Git** option, enter the repository’s URL and then select **Clone** to import the project. The project will contain the following directories: ``swan_core`` (SWAN core application), ``swan_assist`` (IntelliJ Plugin) and ``swan_datasets`` (datasets for the research paper).
22+
2) To configure the project settings and modules, go to **File>Project Structure**.
23+
3) For **Project SDK**, select the corresponding Java SDK version.
24+
4) Select **Modules** from the left panel and remove the existing module that was automatically created.
25+
5) Click the **Add** button and then **Import Module** to create the SWAN Core module. Follow the steps in the [Setting up the Project Modules](https://github.com/secure-software-engineering/swan/tree/master/swan_assist#setting-up-the-project-modules) section to finish configuring the core module as well as the plugin module.
3026

31-
##### Importing Project Module
32-
After following the steps of either Method 1 or 2, the **Import Module** dialog will appear. Follow the steps below to setup the project module.
33-
1) Select **Import module from external module** and then the **Gradle** option.
34-
2) Select the **Use auto-import** option.
35-
3) If the correct Gradle JVM isn’t selected, you can change it.
27+
28+
##### Method 2: Downloading Project ZIP
29+
1) Download and extract the project resources from GitHub.
30+
2) In Intellij, use the **File>Project from Existing Resources** to import the project modules. This can also be done from the IntelliJ start screen.
31+
3) Follow the steps in the [Setting up the Project Modules](https://github.com/secure-software-engineering/swan/tree/master/swan_assist#setting-up-the-project-modules) section to finish configuring the core module as well as the plugin module.
3632

37-
The module should then be built.
33+
## Setting up the Project Modules
3834

35+
##### SWAN Core
36+
1) In the window that appears, open the ``/swan_core`` directory of the project.
37+
2) Select the **Import module from external Model** radio button and also select **Maven**.
38+
3) The default settings in the dialogs that appear can be used.
39+
4) Close the **Project Settings** dialog so that IntelliJ will index the new project module.
40+
41+
##### SWAN Assist
42+
1) Return to the **Project Structure** dialog and Select **Modules** from the left panel.
43+
2) Click the **Add** button and then **Import Module**.
44+
3) In the window that appears, open the ``/swan_assist`` directory. Select the **Import module from external Model** radio button and also select **Gradle**.
45+
4) The default settings in the dialogs that appear can be used. The plugin module should now be indexed.
46+
47+
The core and plugin modules should now be imported.
3948

4049
## Running the Plugin
41-
To run the plugin:
4250

43-
1) Select the **Run Configuration** drop down menu and select **Edit Configurations** or from the **Run** menu select **Edit Configurations**.
51+
The plugin uses ``swan_core`` dependency from [Maven Central](https://mvnrepository.com/artifact/de.upb.cs.swt/swan_core). If the version in the plugin's ``build.gradle`` file is not available on Maven Central, perform the following steps:
52+
1) Run the Maven ``install`` command of the ``swan_core`` project from the console or using the Maven Plugin.
53+
2) Add ``mavenLocal()`` in the ``repositories`` section of the ``build.gradle`` file. The locally installed library can now be use by the plugin.
54+
55+
##### To run the plugin:
56+
57+
1) Select the **Run Configuration** drop down menu and select **Edit Configurations** or from the **Run** menu, select **Edit Configurations**.
4458
2) Click the **Add** button and select **Gradle**.
45-
3) Select the **swan_assist** Gradle module that was just created and enter ``:runIde`` as the value for **Tasks** - this tasks will run the plugin in a new instance of IntelliJ.
46-
4) When the new instance of IntelliJ launches, use the open option to select the project found in ``/test-project`` directory. You may need to set a project SDK, if one isn’t automatically configured.
59+
3) Select the **swan_assist** Gradle module that was just created and enter ``:runIde`` as the value for **Tasks** - this task will run the plugin in a new instance of IntelliJ. The plugin can also be executed using the Gradle Plugin in IntelliJ: Open the Gradle Tool Window, expand the ``intellij`` task and double click on ``runIde``. The other tasks can be used as necessary.
60+
4) When the new instance of IntelliJ launches, use the open option to select the project found in ``/test-project`` directory. You may need to set a project SDK, if one isn’t automatically configured for the project.
4761

4862
Logs for the plugin will appear in the initial instance of IntelliJ.
4963

swan_assist/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
plugins {
2-
id 'java'
32
id 'org.jetbrains.intellij' version '0.4.8'
3+
id 'java'
44
}
55

66
group 'de.fraunhofer'
7-
version '1.0-SNAPSHOT'
7+
version '1.1'
88

99
sourceCompatibility = 1.8
1010

1111
repositories {
1212
mavenCentral()
13+
mavenLocal()
1314
}
1415

1516
dependencies {
1617
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
17-
compile group:'de.upb.cs.swt', name: 'swan_core', version: '1.3.0'
18+
compile group:'de.upb.cs.swt', name: 'swan_core', version: '1.4.0'
1819
compile group: 'ca.mcgill.sable', name: 'soot', version: '3.3.0'
1920
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5'
2021
compile group: 'org.slf4j', name: 'slf4j-simple', version : '1.7.5'
21-
testCompile group: 'junit', name: 'junit', version: '4.12'
2222
}
2323

2424
intellij {
2525
version '2018.3.6'
26-
intellij.updateSinceUntilBuild false
2726
}
2827

2928
patchPluginXml {
30-
changeNotes """
31-
Add change notes here.<br>
32-
<em>most HTML tags may be used</em>"""
29+
changeNotes "Initial release of the SWAN_Assist plugin: <br>add, delete and update methods of interest list" +
30+
"<br>- suggest methods" +
31+
"<br>- filter list" +
32+
"<br>- import and export configuration file"
3333
}

swan_assist/src/main/resources/META-INF/plugin.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
<idea-plugin>
2-
<id>de.fraunhofer.swan_assist</id>
2+
<id>de.fraunhofer.iem.swan_assist</id>
33
<name>SWAN_Assist</name>
44
<vendor email="support@iem.fraunhofer.de" url="https://www.iem.fraunhofer.de/">Fraunhofer IEM</vendor>
55

6-
<description>IDE support for the identification of configured methods for static analyses</description>
6+
<description> SWAN_Assist provides a GUI support for SWAN -a machine-learning approach for detection of
7+
methods of interest for security in Java libraries. The user is able to interact with the learning
8+
process by giving feedback on the methods of interest. The tool helps users that write static analyses
9+
to create list of security methods for weakness detection for their specific Java libraries.
10+
Users can manually inspect the proper usage of the methods detected by SWAN.
11+
</description>
712

813
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
914
on how to target different products -->
10-
<!-- uncomment to enable plugin in all products
15+
<!-- uncomment to enable plugin in all products-->
1116
<depends>com.intellij.modules.lang</depends>
12-
-->
17+
<depends>com.intellij.modules.java</depends>
18+
1319

1420
<idea-version since-build="181"/>
1521

1622
<extensions defaultExtensionNs="com.intellij">
1723
<codeInsight.lineMarkerProvider language="JAVA"
1824
implementationClass="de.fraunhofer.iem.swan.assist.ui.markers.ErrorLineMarker"/>
1925
<toolWindow id="SWAN_Assist" anchor="right" factoryClass="de.fraunhofer.iem.swan.assist.ui.SummaryToolWindow" icon="PluginIcons.SWAN_ASSIST"/>
26+
<applicationService serviceInterface="de.fraunhofer.iem.swan.assist.ui.LoggerService"
27+
serviceImplementation="de.fraunhofer.iem.swan.assist.ui.impl.LoggerServiceImpl"/>
2028
</extensions>
2129

2230
<actions>
@@ -59,7 +67,7 @@
5967
</action>
6068
</group>
6169

62-
<group id="SWAN_Assist.MethodActionGroup" class="de.fraunhofer.iem.swan.assist.actions.method.MethodActionGroup" text="Method"
70+
<group id="SWAN_Assist.MethodActionGroup" class="de.fraunhofer.iem.swan.assist.actions.method.MethodActionGroup" text="Method Options"
6371
popup="true" icon="PluginIcons.FILTER_ACTION">
6472

6573
</group>
@@ -88,7 +96,7 @@
8896
</action>
8997

9098
<action id="SWAN_Assist.MethodListAction" class="de.fraunhofer.iem.swan.assist.actions.method.MethodListAction"
91-
text="View Methods List" >
99+
text="View Methods List">
92100
</action>
93101
<separator/>
94102
<action id="SWAN_Assist.Editor.ImportAction" class="de.fraunhofer.iem.swan.assist.actions.ImportAction"

swan_assist/src/main/resources/config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
log_suffix = _swanassist_log.txt
22
output_dir_name = swan-assist
3-
output_json_suffix = output.json
3+
output_json_suffix = swan_results.json
44
input_json_suffix = config_input.json
55
train_config_file = trainingmethods.json
66
swan_default_param_value = internal
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
output_train_arff_data = false
1+
output_train_arff_data = false
2+
output_file_name = swan_results

swan_assist/test-project/scheduler-methods.json

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
{
22
"methods":[
3-
{
4-
"securityLevel":"none",
5-
"cwe":[
6-
],
7-
"dataOut":{
8-
"parameters":[
9-
10-
],
11-
"return":false
12-
},
13-
"framework":"",
14-
"discovery":"",
15-
"name":"com.example.scheduler.testproject.Utils.hashPassword",
16-
"link":"",
17-
"comment":"",
18-
"type":[
19-
"sanitizer"
20-
],
21-
"parameters":[
22-
"java.lang.String"
23-
],
24-
"return":"java.lang.String",
25-
"dataIn":{
26-
"parameters":[
27-
28-
],
29-
"return":false
30-
}
31-
},
323
{
334
"securityLevel":"none",
345
"cwe":[
@@ -716,7 +687,7 @@
716687
},
717688
"framework":"",
718689
"discovery":"",
719-
"name":"com.example.scheduler.testproject.ExampleSQLiOpenRedirect.encodeforSQL",
690+
"name":"com.example.scheduler.testproject.Utils.encodeForSQL",
720691
"link":"",
721692
"comment":"",
722693
"type":[

swan_core/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>de.upb.cs.swt</groupId>
77
<artifactId>swan_core</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.3.0</version>
9+
<version>1.4.0</version>
1010

1111
<name>SWAN Weakness Detector</name>
1212
<description>SWAN is a machine-learning approach for detection of methods of interest for security in Java libraries.</description>
@@ -72,7 +72,12 @@
7272
<artifactId>json-simple</artifactId>
7373
<version>1.1.1</version>
7474
</dependency>
75-
</dependencies>
75+
<dependency>
76+
<groupId>org.jdom</groupId>
77+
<artifactId>jdom2</artifactId>
78+
<version>2.0.6</version>
79+
</dependency>
80+
</dependencies>
7681

7782
<distributionManagement>
7883
<snapshotRepository>

swan_core/src/main/java/de/fraunhofer/iem/swan/Learner.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import de.fraunhofer.iem.swan.data.Category;
1818
import de.fraunhofer.iem.swan.data.Method;
19+
import de.fraunhofer.iem.swan.util.SwanConfig;
1920
import weka.classifiers.Evaluation;
2021
import weka.classifiers.bayes.BayesNet;
2122
import weka.classifiers.bayes.NaiveBayes;
@@ -214,22 +215,8 @@ else if (WEKA_LEARNER_ALL.equals("Logistic"))
214215
throw new Exception("Wrong WEKA learner!");
215216
// System.out.println("Classifier created: " + WEKA_LEARNER_ALL);
216217

217-
Properties config = new Properties();
218-
InputStream input = getClass().getClassLoader().getResourceAsStream("swan_core_config.properties");;
219-
220-
try {
221-
config.load(input);
222-
} catch (IOException e) {
223-
e.printStackTrace();
224-
} finally {
225-
if (input != null) {
226-
try {
227-
input.close();
228-
} catch (IOException e) {
229-
e.printStackTrace();
230-
}
231-
}
232-
}
218+
SwanConfig swanConfig = new SwanConfig();
219+
Properties config = swanConfig.getConfig();
233220

234221
if (Boolean.parseBoolean(config.getProperty("output_train_arff_data"))) {
235222
// Save arff data.
@@ -242,7 +229,6 @@ else if (WEKA_LEARNER_ALL.equals("Logistic"))
242229
fileName = fileName.replace(", ", "_");
243230
saver.setFile(new File("Train_" + fileName + ".arff"));
244231
saver.writeBatch();
245-
246232
}
247233

248234
//System.out.println( "Arff data saved at: " + saver.retrieveFile().getCanonicalPath());

0 commit comments

Comments
 (0)