-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a95eb6
commit a68cf22
Showing
5 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,5 @@ public static final class ResultRequest { | |
private String type; | ||
|
||
private String details; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/eu/europa/ec/dgc/validation/decorator/service/SubjectService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package eu.europa.ec.dgc.validation.decorator.service; | ||
|
||
import eu.europa.ec.dgc.validation.decorator.config.DgcProperties.ServiceProperties; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.SubjectResponse; | ||
import eu.europa.ec.dgc.validation.decorator.exception.DccException; | ||
import eu.europa.ec.dgc.validation.decorator.exception.RepositoryException; | ||
import eu.europa.ec.dgc.validation.decorator.repository.BackendRepository; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SubjectService { | ||
|
||
private final IdentityService identityService; | ||
|
||
private final BackendRepository backendRepository; | ||
|
||
public ServiceProperties getServiceBySubject(String subject) { | ||
final ServiceTokenContentResponse tokenContent = this.getBackendTokenContent(subject); | ||
if (tokenContent != null && tokenContent.getSubjects() == null || tokenContent.getSubjects().isEmpty()) { | ||
throw new DccException("Subject not found in token", HttpStatus.NO_CONTENT.value()); | ||
} | ||
|
||
final SubjectResponse subjectResponse = tokenContent.getSubjects().get(0); | ||
final String serviceId = subjectResponse.getServiceIdUsed(); | ||
log.debug("Receive service ID (encoded) from booking service '{}'", serviceId); | ||
if (serviceId == null || serviceId.isBlank()) { | ||
throw new DccException(String.format("Subject without service ID '%s'", serviceId), | ||
HttpStatus.NO_CONTENT.value()); | ||
} | ||
|
||
final String decodedServiceId = new String(Base64.getUrlDecoder().decode(serviceId), StandardCharsets.UTF_8); | ||
log.debug("Receive service ID (decoded) from booking service '{}'", decodedServiceId); | ||
|
||
final ServiceProperties service = this.identityService.getServicePropertiesById(decodedServiceId); | ||
log.debug("Receive service: {}", service); | ||
return service; | ||
} | ||
|
||
private ServiceTokenContentResponse getBackendTokenContent(final String subject) { | ||
try { | ||
return this.backendRepository.tokenContent(subject); | ||
} catch (HttpClientErrorException e) { | ||
log.error(e.getMessage(), e); | ||
throw new RepositoryException("Backend service http client error", e); | ||
} | ||
} | ||
} |