Skip to content

Commit

Permalink
Merge pull request #16 from eu-digital-green-certificates/fix/missing…
Browse files Browse the repository at this point in the history
…fields

refactoring
  • Loading branch information
epicsoft-llc authored Sep 22, 2021
2 parents aa14ef5 + 708cf3b commit 13da374
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class RejectController {
@ApiResponse(responseCode = "401", description = "Unauthorized, if no access token are provided"),
@ApiResponse(responseCode = "500", description = "Internal Server Error"),
})
@GetMapping(value = "/reject")
@GetMapping(value = PATH)
public ResponseEntity reject(@RequestHeader("Authorization") final String token) {
log.debug("Incoming GET request to '{}' with token '{}'", PATH, token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,18 @@ public AccessTokenPayload getAccessTockenForValidationService(
}

final String nonce = buildNonce();
ValidationServiceInitializeResponse initialize;
try {
initialize = this.validationServiceRepository.initialize(service, dccToken, subject, nonce);
} catch (HttpClientErrorException e) {
log.error(e.getMessage(), e);
throw new RepositoryException("Validation service http client error", e);
}

final ServiceTokenContentResponse tokenContent;
try {
tokenContent = this.backendRepository.tokenContent(subject, service);
} catch (HttpClientErrorException e) {
log.error(e.getMessage(), e);
throw new RepositoryException("Backend service http client error", e);
}
final ValidationServiceInitializeResponse initialize = this.getValidationServiceInitialize(
dccToken, subject, service, nonce);

final ServiceTokenContentResponse tokenContent = this.getBackendServiceTokenContent(subject, service);
if (tokenContent.getSubjects() == null || tokenContent.getSubjects().isEmpty()) {
throw new NotFoundException("Subject not found in token");
}
final SubjectResponse subjectResponse = tokenContent.getSubjects().get(0);
final OccurrenceInfoResponse occurrenceInfo = tokenContent.getOccurrenceInfo();

final AccessTokenPayload accessToken = this.buildAccessToken(subject, initialize, subjectResponse,
occurrenceInfo);
final AccessTokenPayload accessToken = this.buildAccessToken(
subject, initialize, subjectResponse, occurrenceInfo);
accessToken.setNonce(nonce);
return accessToken;
}
Expand Down Expand Up @@ -145,4 +133,24 @@ private AccessTokenPayload buildAccessToken(
accessTokenPayload.setVersion("1.0");
return accessTokenPayload;
}

private ValidationServiceInitializeResponse getValidationServiceInitialize(final DccTokenRequest dccToken,
final String subject, final ServiceProperties service, final String nonce) {
try {
return this.validationServiceRepository.initialize(service, dccToken, subject, nonce);
} catch (HttpClientErrorException e) {
log.error(e.getMessage(), e);
throw new RepositoryException("Validation service http client error", e);
}
}

private ServiceTokenContentResponse getBackendServiceTokenContent(final String subject,
final ServiceProperties service) {
try {
return this.backendRepository.tokenContent(subject, service);
} catch (HttpClientErrorException e) {
log.error(e.getMessage(), e);
throw new RepositoryException("Backend service http client error", e);
}
}
}

0 comments on commit 13da374

Please sign in to comment.