diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/deploymenttest/DspaceDepositService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/deploymenttest/DspaceDepositService.java index 012ae932..8f7a14b1 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/deploymenttest/DspaceDepositService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/deploymenttest/DspaceDepositService.java @@ -99,7 +99,7 @@ AuthContext authenticate() { ResponseEntity csrfResponse = restClient.get() .uri("/security/csrf") .exchange((request, response) -> new ResponseEntity<>(null, response.getHeaders(), HttpStatus.OK)); - String xsrfToken = csrfResponse.getHeaders().get("DSPACE-XSRF-TOKEN").get(0); + String xsrfToken = getAuthHeaderValue(csrfResponse, "DSPACE-XSRF-TOKEN"); MultiValueMap bodyPair = new LinkedMultiValueMap<>(); bodyPair.add("user", dspaceUsername); @@ -112,7 +112,7 @@ AuthContext authenticate() { .body(bodyPair) .retrieve() .toBodilessEntity(); - String authToken = authResponse.getHeaders().get("Authorization").get(0); + String authToken = getAuthHeaderValue(authResponse, "Authorization"); return new AuthContext(xsrfToken, authToken); } @@ -144,6 +144,14 @@ void deleteDeposit(Deposit deposit, AuthContext authContext) { } } + private String getAuthHeaderValue(ResponseEntity response, String header) { + List values = response.getHeaders().get(header); + if (Objects.isNull(values) || values.isEmpty()) { + throw new RuntimeException("Auth Header not found: " + header); + } + return values.get(0); + } + private String parseHandleFilter(URI accessUrl) { String handleDelim = dspaceApiProtocol + "://" + dspaceServer + "/handle/"; String[] handleTokens = accessUrl.toString().split(handleDelim); @@ -163,7 +171,6 @@ private String findItemUuid(String handleValue, AuthContext authContext, String .body(String.class); List> searchArray = JsonPath.parse(searchResponse).read("$..indexableObject[?(@.handle)]"); if (searchArray.size() == 1) { - @SuppressWarnings("unchecked") Map itemMap = searchArray.get(0); String itemName = itemMap.get("name").toString(); String itemHandle = itemMap.get("handle").toString();