Skip to content

Commit

Permalink
adding style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasundharmadasa committed Apr 10, 2019
1 parent be06b39 commit 853f5e1
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 63 deletions.
87 changes: 53 additions & 34 deletions internal/scan-manager/webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,67 @@
<version>1.0-SNAPSHOT</version>
<name>scan manager webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.10.RELEASE</version>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<version>${javax.servlet.jstl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
<version>${org.json.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.24</version>
<version>${org.yaml.sankeyaml.version}</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>2.26.1</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.1.RELEASE</version>
<version>${com.nimbusds.jose.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.3.0</version>
<version>${com.fasterxml.jackson.dataformat.yaml.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<version>${org.apache.httpcomponents.httpclient.version}</version>
</dependency>
<!-- Apache HttpClient Mime -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
<version>${org.apache.httpcomponents.httpclient.version}</version>
</dependency>
</dependencies>

Expand All @@ -112,6 +94,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${org.springframework.version}</version>
<configuration>
<mainClass>org.wso2.security.tools.scanmanager.webapp.Application</mainClass>
</configuration>
Expand All @@ -123,14 +106,50 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.verson}</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>
https://raw.githubusercontent.com/wso2/code-quality-tools/v1.2/checkstyle/checkstyle.xml
</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.verson}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<org.json.version>20131018</org.json.version>
<org.yaml.sankeyaml.version>1.24</org.yaml.sankeyaml.version>
<com.nimbusds.jose.version>2.26.1</com.nimbusds.jose.version>
<org.springframework.version>1.5.6.RELEASE</org.springframework.version>
<com.fasterxml.jackson.dataformat.yaml.version>2.3.0</com.fasterxml.jackson.dataformat.yaml.version>
<com.fasterxml.jackson.core.version>2.7.3</com.fasterxml.jackson.core.version>
<org.apache.httpcomponents.httpclient.version>4.5.3</org.apache.httpcomponents.httpclient.version>
<tomcat.version>8.5.16</tomcat.version>
<javax.servlet.jstl.version>1.2</javax.servlet.jstl.version>
<maven.compiler.plugin.verson>3.8.0</maven.compiler.plugin.verson>
<maven.checkstyle.plugin.verson>2.16</maven.checkstyle.plugin.verson>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* The main class that starts the spring boot application.
*/
@SpringBootApplication
public class Application {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.wso2.security.tools.scanmanager.webapp.config;

import org.apache.http.client.utils.URIBuilder;
import org.wso2.security.tools.scanmanager.webapp.util.Constants;
import org.wso2.security.tools.scanmanager.webapp.exception.ScanManagerWebappException;
import org.wso2.security.tools.scanmanager.webapp.util.Constants;

import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -29,14 +29,19 @@
import static org.wso2.security.tools.scanmanager.webapp.util.Constants.SCANS_URI;

/**
* Scan Manager webapp configuration model class
* Scan Manager webapp configuration model class.
*/
public class ScanManagerWebappConfiguration {

private char[] clientId;
private char[] clientSecret;
private String scanManagerHost;
private String scanManagerPort;
private Integer scanManagerPort;

private static final String CLIENT_ID_KEY = "clientId";
private static final String CLIENT_SECRET_KEY = "clientSecret";
private static final String SCAN_MANAGER_HOST_KEY = "scanManagerHost";
private static final String SCAN_MANAGER_PORT_KEY = "scanManagerPort";

private static final ScanManagerWebappConfiguration scanManagerWebappConfiguration =
new ScanManagerWebappConfiguration();
Expand All @@ -45,10 +50,10 @@ private ScanManagerWebappConfiguration() {
}

public void init(Map<String, Object> configObjectMap) {
this.clientId = (char[]) configObjectMap.get("clientId");
this.clientSecret = (char[]) configObjectMap.get("clientSecret");
this.scanManagerHost = (String) configObjectMap.get("scanManagerHost");
this.scanManagerPort = (String) configObjectMap.get("scanManagerPort");
this.clientId = (char[]) configObjectMap.get(CLIENT_ID_KEY);
this.clientSecret = (char[]) configObjectMap.get(CLIENT_SECRET_KEY);
this.scanManagerHost = (String) configObjectMap.get(SCAN_MANAGER_HOST_KEY);
this.scanManagerPort = (Integer) configObjectMap.get(SCAN_MANAGER_PORT_KEY);
}

public static ScanManagerWebappConfiguration getInstance() {
Expand All @@ -68,30 +73,41 @@ public String getScanManagerHost() {
}

public int getScanManagerPort() throws NumberFormatException {
return Integer.parseInt(scanManagerPort);
return scanManagerPort;
}

/**
* Building the scans URL.
*
* @return
* @throws ScanManagerWebappException
*/
public URI getScanURL() throws ScanManagerWebappException {
URI uri = null;
try {
uri = (new URIBuilder())
.setHost(scanManagerHost)
.setPort(Integer.parseInt(scanManagerPort))
.setPort(scanManagerPort)
.setScheme(Constants.SCHEME).setPath(SCANS_URI)
.build();
} catch (URISyntaxException e) {
throw new ScanManagerWebappException("Unable to build the start scan URL", e);
throw new ScanManagerWebappException("Unable to build the scanS URL", e);
}
return uri;
}


/**
* Building the scanners URL.
*
* @return
* @throws ScanManagerWebappException
*/
public URI getScannersURL() throws ScanManagerWebappException {
URI uri = null;
try {
uri = (new URIBuilder())
.setHost(scanManagerHost)
.setPort(Integer.parseInt(scanManagerPort))
.setPort(scanManagerPort)
.setScheme(Constants.SCHEME).setPath(SCANNERS_URI)
.build();
} catch (URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private ScanManagerWebappConfigurationBuilder() {
}

/**
* Reading the scan manager webapp configuration from scan-manager-webapp-config.yaml
* Reading the scan manager webapp configuration from scan-manager-webapp-config.yaml.
*
* @return
* @throws ScanManagerWebappException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

/**
* Spring boot servlet initializer class.
*/
public class ServletInitializer extends SpringBootServletInitializer {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.annotation.PostConstruct;

/**
* This class defines start up methods of the application
* This class defines start up methods of the application.
*/
@Component
public class StartUpInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import javax.servlet.ServletContext;

/**
* Controller methods to resolve views
* Controller methods to resolve views.
*/
@Controller
@RequestMapping("scanManager")
Expand Down Expand Up @@ -87,8 +87,7 @@ public ModelAndView startScan(MultipartHttpServletRequest multipartHttpServletRe
if (status == HttpStatus.SC_OK) {
return successView;
} else {
failureView.addObject(MESSAGE_ATTRIBUTE, "An error occurred while " +
"initiating the scan.");
failureView.addObject(MESSAGE_ATTRIBUTE, "An error occurred while initiating the scan.");
return failureView;
}
}
Expand Down Expand Up @@ -132,7 +131,7 @@ public String stopScan(@RequestParam String id) {
}

@PostMapping(value = "/scanConfiguration")
public ModelAndView upload(@RequestParam("scannerID") String scannerID) {
public ModelAndView upload(@RequestParam("scannerId") String scannerId) {
List<Scanner> scannerList = null;
Scanner selectedScanner = new Scanner();

Expand All @@ -145,7 +144,7 @@ public ModelAndView upload(@RequestParam("scannerID") String scannerID) {
context.setAttribute(SCANNERS_CONTEXT_ATTRIBUTE, scannerList);
}
for (Scanner scanner : scannerList) {
if (scanner.getId().equals(scannerID)) {
if (scanner.getId().equals(scannerId)) {
selectedScanner.setId(scanner.getId());
selectedScanner.setName(scanner.getName());
selectedScanner.setType(scanner.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class HttpRequestHandler {

/**
* Send a POST Request
* Send a POST Request.
* @param url
* @param requestHeaders
* @param requestParams
Expand All @@ -47,7 +47,7 @@ public ResponseEntity<String> sendPOST(String url, MultiValueMap<String, String>
}

/**
* Send a GET request
* Send a GET request.
* @param url
* @param requestHeaders
* @param requestParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ScanService {
private static final String CONTENT_TYPE_HEADER_VALUE = "application/json";

/**
* Start a scan
* Start a scan.
*
* @param multipartFileMultiValueMap
* @param parameterMap
Expand Down Expand Up @@ -104,7 +104,7 @@ public int startScan(Map<String, MultipartFile> multipartFileMultiValueMap, Map<
}

/**
* Get the list of scanners
* Get the list of scanners.
*
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package org.wso2.security.tools.scanmanager.webapp.util;

/**
* Constants class for scan manager webapp.
*/
public class Constants {

private Constants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.ArrayList;
import java.util.List;

/**
* Utility class for scan manager webapp.
*/
public class Utils {

private Utils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
clientId:
clientSecret:

scanManagerHost:
scanManagerPort:
scanManagerHost: localhost
scanManagerPort: 8080
Loading

0 comments on commit 853f5e1

Please sign in to comment.