Skip to content

Commit

Permalink
refactoring token service
Browse files Browse the repository at this point in the history
  • Loading branch information
epicsoft-llc committed Sep 22, 2021
1 parent e6e6705 commit 5929846
Showing 1 changed file with 25 additions and 17 deletions.
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 5929846

Please sign in to comment.