@@ -48,49 +48,36 @@ final class DefaultImportScanService implements ImportScanService {
4848 this .defectDojoApiKey = config .getApiKey ();
4949 }
5050
51- /**
52- * The DefectDojo Authentication Header
53- *
54- * @return never {@code null}
55- */
56- HttpHeaders createDefectDojoAuthorizationHeaders () {
57- final var authorizationHeader = new HttpHeaders ();
58- authorizationHeader .set (HttpHeaders .AUTHORIZATION , String .format ("Token %s" , defectDojoApiKey ));
59- return authorizationHeader ;
60- }
61-
62- private RestTemplate createRestTemplate () {
63- final var template = new RestTemplate ();
64-
65- if (shouldConfigureProxySettings ()) {
66- template .setRequestFactory (createRequestFactoryWithProxyAuthConfig ());
67- }
51+ @ Override
52+ public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType ) {
53+ final var options = new LinkedMultiValueMap <String , String >();
54+ options .add ("engagement" , Long .toString (engagementId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
6855
69- return template ;
56+ return this . importScan ( scanFile , engagementId , lead , currentDate , scanType , testType , options ) ;
7057 }
7158
72- private static boolean shouldConfigureProxySettings () {
73- return System .getProperty ("http.proxyUser" ) != null && System .getProperty ("http.proxyPassword" ) != null ;
59+ @ Override
60+ public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
61+ options .add ("engagement" , Long .toString (engagementId ));
62+
63+ // FIXME: Why is engagementId hardcoded overwritten with "import-scan"
64+ return this .createFindings (scanFile , "import-scan" , lead , currentDate , scanType , testType , options );
7465 }
7566
76- private static HttpComponentsClientHttpRequestFactory createRequestFactoryWithProxyAuthConfig () {
77- // Configuring Proxy Authentication explicitly as it isn't done by default for spring rest templates :(
78- final var credentials = new BasicCredentialsProvider ();
79- credentials .setCredentials (
80- new AuthScope (System .getProperty ("http.proxyHost" ), Integer .parseInt (System .getProperty ("http.proxyPort" ))),
81- new UsernamePasswordCredentials (System .getProperty ("http.proxyUser" ), System .getProperty ("http.proxyPassword" ))
82- );
67+ @ Override
68+ public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType ) {
69+ final var options = new LinkedMultiValueMap <String , String >();
70+ options .add ("test" , Long .toString (testId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
8371
84- final var clientBuilder = HttpClientBuilder .create ();
72+ return this .reimportScan (scanFile , testId , lead , currentDate , scanType , testType , options );
73+ }
8574
86- clientBuilder .useSystemProperties ();
87- clientBuilder .setProxy (new HttpHost (System .getProperty ("http.proxyHost" ), Integer .parseInt (System .getProperty ("http.proxyPort" ))));
88- clientBuilder .setDefaultCredentialsProvider (credentials );
89- clientBuilder .setProxyAuthenticationStrategy (new ProxyAuthenticationStrategy ());
75+ @ Override
76+ public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
77+ options .add ("test" , Long .toString (testId ));
9078
91- final var factory = new HttpComponentsClientHttpRequestFactory ();
92- factory .setHttpClient (clientBuilder .build ());
93- return factory ;
79+ // FIXME: Why is engagementId hardcoded overwritten with "reimport-scan"
80+ return this .createFindings (scanFile , "reimport-scan" , lead , currentDate , scanType , testType , options );
9481 }
9582
9683 /*
@@ -143,36 +130,51 @@ public String getFilename() {
143130 throw new DefectDojoPersistenceException ("Failed to attach findings to engagement." );
144131 }
145132 }
133+
134+ /**
135+ * The DefectDojo Authentication Header
136+ *
137+ * @return never {@code null}
138+ */
139+ HttpHeaders createDefectDojoAuthorizationHeaders () {
140+ final var authorizationHeader = new HttpHeaders ();
141+ authorizationHeader .set (HttpHeaders .AUTHORIZATION , String .format ("Token %s" , defectDojoApiKey ));
142+ return authorizationHeader ;
143+ }
146144
147- @ Override
148- public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType ) {
149- final var options = new LinkedMultiValueMap <String , String >();
150- options .add ("engagement" , Long .toString (engagementId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
145+ private RestTemplate createRestTemplate () {
146+ final var template = new RestTemplate ();
151147
152- return this .importScan (scanFile , engagementId , lead , currentDate , scanType , testType , options );
153- }
148+ if (shouldConfigureProxySettings ()) {
149+ template .setRequestFactory (createRequestFactoryWithProxyAuthConfig ());
150+ }
154151
155- @ Override
156- public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
157- options .add ("engagement" , Long .toString (engagementId ));
152+ return template ;
153+ }
158154
159- // FIXME: Why is engagementId hardcoded overwritten with "import-scan"
160- return this . createFindings ( scanFile , "import-scan" , lead , currentDate , scanType , testType , options ) ;
155+ private static boolean shouldConfigureProxySettings () {
156+ return System . getProperty ( "http.proxyUser" ) != null && System . getProperty ( "http.proxyPassword" ) != null ;
161157 }
162158
163- @ Override
164- public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType ) {
165- final var options = new LinkedMultiValueMap <String , String >();
166- options .add ("test" , Long .toString (testId )); // FIXME Seems to be duplicated bc it is done again in the overloaded method.
159+ private static HttpComponentsClientHttpRequestFactory createRequestFactoryWithProxyAuthConfig () {
160+ // Configuring Proxy Authentication explicitly as it isn't done by default for spring rest templates :(
161+ final var credentials = new BasicCredentialsProvider ();
162+ credentials .setCredentials (
163+ new AuthScope (System .getProperty ("http.proxyHost" ), Integer .parseInt (System .getProperty ("http.proxyPort" ))),
164+ new UsernamePasswordCredentials (System .getProperty ("http.proxyUser" ), System .getProperty ("http.proxyPassword" ))
165+ );
167166
168- return this .reimportScan (scanFile , testId , lead , currentDate , scanType , testType , options );
169- }
167+ final var clientBuilder = HttpClientBuilder .create ();
170168
171- @ Override
172- public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType , MultiValueMap <String , String > options ) {
173- options .add ("test" , Long .toString (testId ));
169+ clientBuilder .useSystemProperties ();
170+ clientBuilder .setProxy (new HttpHost (System .getProperty ("http.proxyHost" ), Integer .parseInt (System .getProperty ("http.proxyPort" ))));
171+ clientBuilder .setDefaultCredentialsProvider (credentials );
172+ clientBuilder .setProxyAuthenticationStrategy (new ProxyAuthenticationStrategy ());
174173
175- // FIXME: Why is engagementId hardcoded overwritten with "reimport-scan"
176- return this .createFindings (scanFile , "reimport-scan" , lead , currentDate , scanType , testType , options );
174+ final var factory = new HttpComponentsClientHttpRequestFactory ();
175+ factory .setHttpClient (clientBuilder .build ());
176+ return factory ;
177177 }
178+
179+
178180}
0 commit comments