Skip to content

Commit 81b5439

Browse files
authored
Merge branch 'master' into ScanManager_Update
2 parents b7e1b56 + 8e383f5 commit 81b5439

File tree

12 files changed

+81
-34
lines changed

12 files changed

+81
-34
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# appscan-sdk
2+
SDK for interacting with Application Security on Cloud
3+
4+
# License
5+
6+
All files found in this project are licensed under the [Apache License 2.0](LICENSE).

pom.xml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@
1212
</licenses>
1313

1414
<build>
15-
<resources>
16-
<resource>
17-
<directory>src/main/java</directory>
18-
<includes>
19-
<include>**/*.properties</include>
20-
</includes>
21-
<excludes>
22-
<exclude>**/*.java</exclude>
23-
</excludes>
24-
</resource>
25-
</resources>
26-
<plugins>
27-
<plugin>
28-
<artifactId>maven-compiler-plugin</artifactId>
29-
<version>3.5.1</version>
30-
<configuration>
31-
<source>1.7</source>
32-
<target>1.7</target>
33-
</configuration>
34-
</plugin>
35-
</plugins>
15+
<resources>
16+
<resource>
17+
<directory>src/main/java</directory>
18+
<includes>
19+
<include>**/*.properties</include>
20+
</includes>
21+
<excludes>
22+
<exclude>**/*.java</exclude>
23+
</excludes>
24+
</resource>
25+
<resource>
26+
<directory>src/main/resources</directory>
27+
<includes>
28+
<include>META-INF/**</include>
29+
</includes>
30+
</resource>
31+
</resources>
32+
<plugins>
33+
<plugin>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
<version>3.5.1</version>
36+
<configuration>
37+
<source>1.7</source>
38+
<target>1.7</target>
39+
</configuration>
40+
</plugin>
41+
</plugins>
3642
</build>
3743

3844
<dependencies>

src/main/java/com/hcl/appscan/sdk/auth/AuthenticationHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.apache.wink.json4j.JSONObject;
1717

1818
import com.hcl.appscan.sdk.CoreConstants;
19+
import com.hcl.appscan.sdk.Messages;
20+
import com.hcl.appscan.sdk.error.HttpException;
1921
import com.hcl.appscan.sdk.http.HttpClient;
2022
import com.hcl.appscan.sdk.http.HttpResponse;
2123

@@ -86,7 +88,10 @@ else if(type == LoginType.ASoC) {
8688
}
8789
return true;
8890
}
89-
return false;
91+
else {
92+
String reason = response.getResponseBodyAsString() == null ? Messages.getMessage("message.unknown") : response.getResponseBodyAsString(); //$NON-NLS-1$
93+
throw new HttpException(response.getResponseCode(), reason);
94+
}
9095
}
9196

9297
public boolean isTokenExpired() {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.hcl.appscan.sdk.error;
2+
3+
import java.io.IOException;
4+
5+
import com.hcl.appscan.sdk.Messages;
6+
7+
public class HttpException extends IOException {
8+
9+
private static final long serialVersionUID = 1L;
10+
11+
public HttpException(int responseCode, String message) {
12+
super(Messages.getMessage("error.http", responseCode, message)); //$NON-NLS-1$
13+
}
14+
15+
public HttpException(String message, Throwable throwable) {
16+
super(message, throwable);
17+
}
18+
}

src/main/java/com/hcl/appscan/sdk/messages.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# © Copyright IBM Corporation 2016.
3-
# © Copyright HCL Technologies Ltd. 2017.
2+
# © Copyright IBM Corporation 2016.
3+
# © Copyright HCL Technologies Ltd. 2017.
44
# LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
55
#
66
# NLS_MESSAGEFORMAT_VAR
@@ -18,6 +18,7 @@ message.download.complete=Download complete.
1818
message.preparing.irx=Preparing the IRX file using SAClientUtil version {0}...
1919
message.saclient.old=A newer version of the SAClientUtil package is available:\nCurrent Version: {0}\nAvailable Version: {1}
2020
message.results.unavailable=Scan results are not available.
21+
message.unknown=Unknown
2122

2223
error.authenticating=An error occurred authenticating with the service.
2324
error.download.client=An error occurred downloading the SAClientUtil package. {0}
@@ -42,6 +43,7 @@ error.target.invalid=The scan target {0} is invalid.
4243
error.creating.scan=An error occurred initiating the scan.
4344
error.delete=Failed to delete {0}.
4445
error.dom.state=Bad DOM state.
46+
error.http=Response Code: {0}\nReason: {1}
4547

4648
#Presence
4749
error.getting.presence.details=An error occurred retrieving details for Presence with id {0}.

src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ private void loadResults() {
150150
m_hasResults = true;
151151
}
152152
} catch (IOException | JSONException | NullPointerException e) {
153-
m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_GETTING_DETAILS)), e);
153+
m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_GETTING_DETAILS, e.getMessage())), e);
154+
m_status = FAILED;
154155
}
155156
}
156157

src/main/java/com/hcl/appscan/sdk/scanners/ASoCScan.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ protected IScanServiceProvider getServiceProvider() {
7979
protected Map<String, String> getProperties() {
8080
if(!m_properties.containsKey(CoreConstants.LOCALE))
8181
m_properties.put(CoreConstants.LOCALE, SystemUtil.getLocale());
82-
if(!m_properties.containsKey(CoreConstants.EMAIL_NOTIFICATION))
82+
if(!m_properties.containsKey(CoreConstants.EMAIL_NOTIFICATION) ||
83+
!Boolean.parseBoolean(m_properties.get(CoreConstants.EMAIL_NOTIFICATION)))
8384
m_properties.put(CoreConstants.EMAIL_NOTIFICATION, Boolean.toString(false));
8485
return m_properties;
8586
}

src/main/java/com/hcl/appscan/sdk/scanners/sast/SAClient.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private int runClient(String workingDir, List<String> args) throws IOException,
7272
arguments.addAll(args);
7373
m_builder = new ProcessBuilder(arguments);
7474
m_builder.directory(new File(workingDir));
75+
m_builder.redirectErrorStream(true);
7576

7677
m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(PREPARING_IRX, getLocalClientVersion())));
7778
final Process proc = m_builder.start();
@@ -107,7 +108,14 @@ public void run() {
107108
return proc.exitValue();
108109
}
109110

110-
private String getClientScript() throws IOException, ScannerException {
111+
/**
112+
* Gets the absolute path to the "appscan" script for running the IRGen process, downloading the package if it's
113+
* not found or if the current version is out of date.
114+
* @return The absolute path to the "appscan" script.
115+
* @throws IOException
116+
* @throws ScannerException
117+
*/
118+
public String getClientScript() throws IOException, ScannerException {
111119
//See if we already have the client package.
112120
String scriptPath = "bin" + File.separator + getScriptName(); //$NON-NLS-1$
113121
File install = findClientInstall();

src/main/java/com/hcl/appscan/sdk/scanners/sast/SASTScan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private File getScanLogs() {
106106
return new File("logs"); //$NON-NLS-1$
107107
}
108108
String logsFile = m_irx.getName();
109-
logsFile = logsFile.substring(0, logsFile.lastIndexOf(".") - 1); //$NON-NLS-1$
109+
logsFile = logsFile.substring(0, logsFile.lastIndexOf(".")); //$NON-NLS-1$
110110
logsFile += "_logs.zip"; //$NON-NLS-1$
111111
return new File(m_irx.getParentFile(), logsFile);
112112
}

src/main/java/com/hcl/appscan/sdk/scanners/sast/SASTScanManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ private void run(IProgress progress,Map<String, String> properties, IScanServic
8383
}
8484
}
8585

86-
private String createConfig() throws AppScanException {
86+
private void createConfig() throws AppScanException {
87+
if(m_targets.isEmpty())
88+
return;
8789
try {
8890
ModelWriter writer = new XmlWriter();
8991
writer.initWriters(new File(m_workingDirectory));
9092
writer.visit(m_targets);
9193
writer.write();
92-
return writer.getOutputLocation();
9394
} catch (IOException | TransformerException e) {
9495
throw new AppScanException(e.getLocalizedMessage(), e);
9596
}

0 commit comments

Comments
 (0)