11package com .example .GitHubActionsQWas .service ;
22
3+ import ch .qos .logback .core .util .StringUtil ;
34import com .example .GitHubActionsQWas .WASAuth .WASAuth ;
45import com .example .GitHubActionsQWas .WASClient .QualysWASResponse ;
56import com .example .GitHubActionsQWas .WASClient .WASClient ;
67import com .example .GitHubActionsQWas .constants .Constants ;
8+ import com .example .GitHubActionsQWas .util .ApiGatewayUrl ;
9+ import com .example .GitHubActionsQWas .util .ApiServerUrl ;
710import com .example .GitHubActionsQWas .util .Helper ;
11+ import com .example .GitHubActionsQWas .util .PortalUrl ;
812import com .fasterxml .jackson .core .JsonProcessingException ;
913import com .fasterxml .jackson .databind .JsonNode ;
1014import com .fasterxml .jackson .databind .ObjectMapper ;
2125import org .slf4j .LoggerFactory ;
2226import org .springframework .core .env .Environment ;
2327
28+ import java .io .IOException ;
29+ import java .net .MalformedURLException ;
30+ import java .security .KeyManagementException ;
31+ import java .security .NoSuchAlgorithmException ;
2432import java .util .ArrayList ;
2533import java .util .List ;
2634import java .util .concurrent .TimeUnit ;
@@ -36,6 +44,8 @@ public class QualysWASScanBuilder {
3644 private Environment environment ;
3745 private String apiServer ;
3846 private String portalServer ;
47+ private String gatewayServer ;
48+ private String platform ;
3949 private String qualysUsername ;
4050 private String qualysPasssword ;
4151 private boolean useProxy = false ;
@@ -76,11 +86,14 @@ public class QualysWASScanBuilder {
7686 private boolean waitForResult ;
7787 private WASClient client ;
7888 private String fileType ;
89+ private String authType ;
90+ private String clientId ;
91+ private String clientSecret ;
92+ private String qualysIdentificationUrl ;
7993
8094 public QualysWASScanBuilder (Environment environment ) {
8195 try {
8296 this .environment = environment ;
83- this .apiServer = environment .getProperty ("API_SERVER" , "" );
8497 this .qualysUsername = environment .getProperty ("QUALYS_USERNAME" , "" );
8598 this .qualysPasssword = environment .getProperty ("QUALYS_PASSWORD" , "" );
8699 this .useProxy = environment .getProperty ("USE_PROXY" , Boolean .class , false );
@@ -107,6 +120,21 @@ public QualysWASScanBuilder(Environment environment) {
107120 this .interval = environment .getProperty ("INTERVAL" , Integer .class , 1 );
108121 this .timeout = environment .getProperty ("TIMEOUT" , Integer .class , (60 * 5 ) + 50 );
109122 this .fileType = environment .getProperty ("FILE_TYPE" , "PDF" );
123+ this .authType = environment .getProperty ("AUTH_TYPE" , "" );
124+ this .clientId = environment .getProperty ("CLIENT_ID" , "" );
125+ this .clientSecret = environment .getProperty ("CLIENT_SECRET" , "" );
126+ this .platform = environment .getProperty ("PLATFORM" , "" );
127+ this .qualysIdentificationUrl = "https://www.qualys.com/platform-identification" ;
128+
129+ if (StringUtil .notNullNorEmpty (platform )) {
130+ this .apiServer = ApiServerUrl .getByKey (platform ).getUrl ();
131+ this .portalServer = PortalUrl .getByKey (platform ).getUrl ();
132+ this .gatewayServer = ApiGatewayUrl .getByKey (platform ).getUrl ();
133+ } else {
134+ throw new Exception ("PLATFORM not specified, Please configure it and try again. Please visit following url to identify correct platform: " +
135+ qualysIdentificationUrl );
136+ }
137+
110138 this .severity1Limit = 0 ;
111139 this .severity2Limit = 0 ;
112140 this .severity3Limit = 0 ;
@@ -120,7 +148,7 @@ public QualysWASScanBuilder(Environment environment) {
120148 assignSeverities ();
121149 }
122150 } catch (Exception ex ) {
123- logger .error ("Something went wrong. Reason: " + ex .getCause ());
151+ logger .error ("Something went wrong. Reason: " + ex .getMessage ());
124152 System .exit (1 );
125153 }
126154 }
@@ -173,10 +201,14 @@ protected void assignSeverities() {
173201 }
174202 }
175203
176- protected void initWASClient () {
177- WASAuth auth = new WASAuth ();
178- auth .setWasCredentials (apiServer , qualysUsername , qualysPasssword );
179-
204+ protected void initWASClient () throws NoSuchAlgorithmException , KeyManagementException , IOException {
205+ WASAuth auth = new WASAuth ();;
206+ if (authType .equals (Constants .BASIC )) {
207+ auth .setWasCredentials (apiServer , qualysUsername , qualysPasssword , Constants .BASIC );
208+ } else {
209+ auth .setWasOAuthCredentials (gatewayServer , clientId , clientSecret , Constants .OAUTH );
210+ auth .setOAuthKey ();
211+ }
180212// if (useProxy) {
181213// auth.setProxyCredentials(proxyServer, proxyPort, proxyUsername, proxyPassword);
182214// }
@@ -226,8 +258,6 @@ protected JsonObject getCriteriaAsJsonObject() {
226258 *
227259 */
228260 public void launchWebApplicationScan () {
229- portalServer = apiServer .replace ("api" , "guard" );
230-
231261 logger .info ("Using Qualys API Server: " + apiServer );
232262
233263 try {
@@ -410,7 +440,16 @@ private JsonElement getEvaluationResult(JsonObject result) {
410440 }
411441
412442 public boolean isMandatoryParametersSet () {
413- return !(this .apiServer == null || this .apiServer .isEmpty () || this .qualysUsername == null || this .qualysUsername .isEmpty () || this .qualysPasssword == null || this .qualysPasssword .isEmpty () || webAppId == null || webAppId .isEmpty () || scanName == null || scanName .isEmpty () || scanType == null || scanType .isEmpty ());
443+ return !(this .apiServer == null || this .apiServer .isEmpty () ||
444+ this .qualysUsername == null || this .qualysUsername .isEmpty () ||
445+ this .qualysPasssword == null || this .qualysPasssword .isEmpty () ||
446+ this .webAppId == null || this .webAppId .isEmpty () ||
447+ this .scanName == null || this .scanName .isEmpty () ||
448+ this .scanType == null || this .scanType .isEmpty () ||
449+ this .platform == null || this .platform .isEmpty ()) ||
450+ this .gatewayServer == null || this .gatewayServer .isEmpty () ||
451+ this .portalServer == null || this .portalServer .isEmpty () ||
452+ this .authType == null || this .authType .isEmpty ();
414453 }
415454
416455 protected boolean testConnection () {
0 commit comments