File tree Expand file tree Collapse file tree 2 files changed +37
-12
lines changed
src/main/java/io/securecodebox/persistence/defectdojo Expand file tree Collapse file tree 2 files changed +37
-12
lines changed Original file line number Diff line number Diff line change 1+ package io .securecodebox .persistence .defectdojo .http ;
2+
3+ import io .securecodebox .persistence .defectdojo .config .Config ;
4+ import lombok .NonNull ;
5+ import org .springframework .http .HttpHeaders ;
6+
7+ import java .nio .charset .StandardCharsets ;
8+ import java .util .Base64 ;
9+
10+ /**
11+ * Placeholder to move duplicated code, will be named better later
12+ */
13+ public final class Foo {
14+ private final Config config ;
15+
16+ public Foo (@ NonNull final Config config ) {
17+ super ();
18+ this .config = config ;
19+ }
20+
21+ public HttpHeaders getDefectDojoAuthorizationHeaders () {
22+ HttpHeaders headers = new HttpHeaders ();
23+ headers .set ("Authorization" , "Token " + this .config .getApiKey ());
24+
25+ String username = System .getProperty ("http.proxyUser" , "" );
26+ String password = System .getProperty ("http.proxyPassword" , "" );
27+
28+ if (!username .isEmpty () || !password .isEmpty ()) {
29+ System .out .println ("Setting Proxy Auth Header..." );
30+ headers .set (HttpHeaders .PROXY_AUTHORIZATION , "Basic " + Base64 .getEncoder ().encodeToString ((username + ':' + password ).getBytes (StandardCharsets .UTF_8 )));
31+ }
32+
33+ return headers ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1212import com .fasterxml .jackson .databind .cfg .CoercionInputShape ;
1313import io .securecodebox .persistence .defectdojo .config .Config ;
1414import io .securecodebox .persistence .defectdojo .exception .LoopException ;
15+ import io .securecodebox .persistence .defectdojo .http .Foo ;
1516import io .securecodebox .persistence .defectdojo .model .BaseModel ;
1617import io .securecodebox .persistence .defectdojo .model .Response ;
1718import io .securecodebox .persistence .defectdojo .model .Engagement ;
@@ -75,18 +76,7 @@ public GenericDefectDojoService(Config config) {
7576 * @return The DefectDojo Authentication Header
7677 */
7778 private HttpHeaders getDefectDojoAuthorizationHeaders () {
78- HttpHeaders headers = new HttpHeaders ();
79- headers .set ("Authorization" , "Token " + this .config .getApiKey ());
80-
81- String username = System .getProperty ("http.proxyUser" , "" );
82- String password = System .getProperty ("http.proxyPassword" , "" );
83-
84- if (!username .isEmpty () || !password .isEmpty ()) {
85- System .out .println ("Setting Proxy Auth Header..." );
86- headers .set (HttpHeaders .PROXY_AUTHORIZATION , "Basic " + Base64 .getEncoder ().encodeToString ((username + ':' + password ).getBytes (StandardCharsets .UTF_8 )));
87- }
88-
89- return headers ;
79+ return new Foo (config ).getDefectDojoAuthorizationHeaders ();
9080 }
9181
9282 private RestTemplate setupRestTemplate () {
You can’t perform that action at this time.
0 commit comments