-
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.
Merge pull request #24 from eu-digital-green-certificates/feat/access…
…tokenpayload functionality outsourced to AccessTokenPayloadBuilder
- Loading branch information
Showing
4 changed files
with
216 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,76 @@ | ||
<h1 align="center"> | ||
EU Digital COVID Certificate Validation Decorator | ||
</h1> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/eu-digital-green-certificates/dgca-validation-decorator/actions/workflows/ci-main.yml" title="ci-main.yml"> | ||
<img src="https://github.com/eu-digital-green-certificates/dgca-validation-decorator/actions/workflows/ci-main.yml/badge.svg"> | ||
</a> | ||
<a href="/../../commits/" title="Last Commit"> | ||
<img src="https://img.shields.io/github/last-commit/eu-digital-green-certificates/dgca-validation-decorator?style=flat"> | ||
</a> | ||
<a href="/../../issues" title="Open Issues"> | ||
<img src="https://img.shields.io/github/issues/eu-digital-green-certificates/dgca-validation-decorator?style=flat"> | ||
</a> | ||
<a href="./LICENSE" title="License"> | ||
<img src="https://img.shields.io/badge/License-Apache%202.0-green.svg?style=flat"> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="#about">About</a> • | ||
<a href="#development">Development</a> • | ||
<a href="#documentation">Documentation</a> • | ||
<a href="#support-and-feedback">Support</a> • | ||
<a href="#how-to-contribute">Contribute</a> • | ||
<a href="#licensing">Licensing</a> | ||
</p> | ||
|
||
## About | ||
|
||
This repository contains the source code of the EU Digital COVID Certificate Validation Decorator. | ||
|
||
- [ ] TODO: Describe Component | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
- [ ] TODO: Prerequisites | ||
|
||
### Build | ||
|
||
- [ ] TODO: Build | ||
|
||
## Documentation | ||
|
||
- [ ] TODO: Documentation | ||
|
||
## Support and feedback | ||
|
||
The following channels are available for discussions, feedback, and support requests: | ||
|
||
| Type | Channel | | ||
| ------------------------ | ------------------------------------------------------ | | ||
| **Issues** | <a href="/../../issues" title="Open Issues"><img src="https://img.shields.io/github/issues/eu-digital-green-certificates/dgca-validation-decorator?style=flat"></a> | | ||
| **Other requests** | <a href="mailto:[email protected]" title="Email DGC Team"><img src="https://img.shields.io/badge/email-DGC%20team-green?logo=mail.ru&style=flat-square&logoColor=white"></a> | | ||
|
||
## How to contribute | ||
|
||
Contribution and feedback is encouraged and always welcome. For more information about how to contribute, the project structure, | ||
as well as additional contribution information, see our [Contribution Guidelines](./CONTRIBUTING.md). By participating in this | ||
project, you agree to abide by its [Code of Conduct](./CODE_OF_CONDUCT.md) at all times. | ||
|
||
## Licensing | ||
|
||
Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
|
||
Licensed under the **Apache License, Version 2.0** (the "License"); you may not use this file except in compliance with the License. | ||
|
||
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the [LICENSE](./LICENSE) for the specific | ||
language governing permissions and limitations under the License. | ||
<h1 align="center"> | ||
EU Digital COVID Certificate Validation Decorator | ||
</h1> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/eu-digital-green-certificates/dgca-validation-decorator/actions/workflows/ci-main.yml" title="ci-main.yml"> | ||
<img src="https://github.com/eu-digital-green-certificates/dgca-validation-decorator/actions/workflows/ci-main.yml/badge.svg"> | ||
</a> | ||
<a href="/../../commits/" title="Last Commit"> | ||
<img src="https://img.shields.io/github/last-commit/eu-digital-green-certificates/dgca-validation-decorator?style=flat"> | ||
</a> | ||
<a href="/../../issues" title="Open Issues"> | ||
<img src="https://img.shields.io/github/issues/eu-digital-green-certificates/dgca-validation-decorator?style=flat"> | ||
</a> | ||
<a href="./LICENSE" title="License"> | ||
<img src="https://img.shields.io/badge/License-Apache%202.0-green.svg?style=flat"> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="#about">About</a> • | ||
<a href="#development">Development</a> • | ||
<a href="#documentation">Documentation</a> • | ||
<a href="#support-and-feedback">Support</a> • | ||
<a href="#how-to-contribute">Contribute</a> • | ||
<a href="#licensing">Licensing</a> | ||
</p> | ||
|
||
## About | ||
|
||
This repository contains the source code of the EU Digital COVID Certificate Validation Decorator. | ||
|
||
The Validation Decorator is a template. To make your own adjustments, the three interfaces `KeyProvider`, `BackendRepository` and `AccessTokenPayloadBuilder` should be implemented. | ||
|
||
- [ ] TODO: Describe Component | ||
|
||
## Development | ||
|
||
### Prerequisites | ||
|
||
- [ ] TODO: Prerequisites | ||
|
||
### Build | ||
|
||
- [ ] TODO: Build | ||
|
||
## Documentation | ||
|
||
- [ ] TODO: Documentation | ||
|
||
## Support and feedback | ||
|
||
The following channels are available for discussions, feedback, and support requests: | ||
|
||
| Type | Channel | | ||
| ------------------------ | ------------------------------------------------------ | | ||
| **Issues** | <a href="/../../issues" title="Open Issues"><img src="https://img.shields.io/github/issues/eu-digital-green-certificates/dgca-validation-decorator?style=flat"></a> | | ||
| **Other requests** | <a href="mailto:[email protected]" title="Email DGC Team"><img src="https://img.shields.io/badge/email-DGC%20team-green?logo=mail.ru&style=flat-square&logoColor=white"></a> | | ||
|
||
## How to contribute | ||
|
||
Contribution and feedback is encouraged and always welcome. For more information about how to contribute, the project structure, | ||
as well as additional contribution information, see our [Contribution Guidelines](./CONTRIBUTING.md). By participating in this | ||
project, you agree to abide by its [Code of Conduct](./CODE_OF_CONDUCT.md) at all times. | ||
|
||
## Licensing | ||
|
||
Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
|
||
Licensed under the **Apache License, Version 2.0** (the "License"); you may not use this file except in compliance with the License. | ||
|
||
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the [LICENSE](./LICENSE) for the specific | ||
language governing permissions and limitations under the License. |
35 changes: 35 additions & 0 deletions
35
src/main/java/eu/europa/ec/dgc/validation/decorator/service/AccessTokenPayloadBuilder.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,35 @@ | ||
/*- | ||
* ---license-start | ||
* European Digital COVID Certificate Validation Decorator Service / dgca-validation-decorator | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.validation.decorator.service; | ||
|
||
import eu.europa.ec.dgc.validation.decorator.dto.AccessTokenPayload; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.OccurrenceInfoResponse; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.SubjectResponse; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ValidationServiceInitializeResponse; | ||
|
||
public interface AccessTokenPayloadBuilder { | ||
|
||
AccessTokenPayload build( | ||
final String subject, | ||
final ValidationServiceInitializeResponse initialize, | ||
final SubjectResponse subjectResponse, | ||
final OccurrenceInfoResponse occurrenceInfo); | ||
} |
102 changes: 102 additions & 0 deletions
102
...ain/java/eu/europa/ec/dgc/validation/decorator/service/AccessTokenPayloadBuilderImpl.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,102 @@ | ||
/*- | ||
* ---license-start | ||
* European Digital COVID Certificate Validation Decorator Service / dgca-validation-decorator | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.validation.decorator.service; | ||
|
||
import eu.europa.ec.dgc.validation.decorator.config.DgcProperties; | ||
import eu.europa.ec.dgc.validation.decorator.dto.AccessTokenPayload; | ||
import eu.europa.ec.dgc.validation.decorator.dto.AccessTokenPayload.AccessTokenConditions; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.OccurrenceInfoResponse; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.SubjectResponse; | ||
import eu.europa.ec.dgc.validation.decorator.entity.ValidationServiceInitializeResponse; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.OffsetDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AccessTokenPayloadBuilderImpl implements AccessTokenPayloadBuilder { | ||
|
||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxxxx"); | ||
|
||
private static final DateTimeFormatter DOB_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
private final DgcProperties dgcProperties; | ||
|
||
@Override | ||
public AccessTokenPayload build( | ||
final String subject, | ||
final ValidationServiceInitializeResponse initialize, | ||
final SubjectResponse subjectResponse, | ||
final OccurrenceInfoResponse occurrenceInfo) { | ||
final AccessTokenConditions accessTokenConditions = new AccessTokenConditions(); | ||
accessTokenConditions.setLang(occurrenceInfo.getLanguage()); | ||
accessTokenConditions.setFnt(subjectResponse.getForename()); | ||
accessTokenConditions.setGnt(subjectResponse.getLastname()); | ||
accessTokenConditions.setCoa(occurrenceInfo.getCountryOfArrival()); | ||
accessTokenConditions.setCod(occurrenceInfo.getCountryOfDeparture()); | ||
accessTokenConditions.setRoa(occurrenceInfo.getRegionOfArrival()); | ||
accessTokenConditions.setRod(occurrenceInfo.getRegionOfDeparture()); | ||
accessTokenConditions.setType(occurrenceInfo.getConditionTypes()); | ||
accessTokenConditions.setCategory(occurrenceInfo.getCategories()); | ||
accessTokenConditions.setDob(this.parseBirthDay(subjectResponse.getBirthDate())); | ||
|
||
final OffsetDateTime departureTime = occurrenceInfo.getDepartureTime(); | ||
accessTokenConditions.setValidFrom(departureTime.format(FORMATTER)); | ||
accessTokenConditions.setValidationClock(occurrenceInfo.getArrivalTime().format(FORMATTER)); | ||
accessTokenConditions.setValidTo(departureTime.plusDays(2).format(FORMATTER)); | ||
|
||
final AccessTokenPayload accessTokenPayload = new AccessTokenPayload(); | ||
accessTokenPayload.setJti(subjectResponse.getJti()); | ||
accessTokenPayload.setIss(this.dgcProperties.getToken().getIssuer()); | ||
accessTokenPayload.setIat(Instant.now().getEpochSecond()); | ||
accessTokenPayload.setExp(initialize.getExp()); | ||
accessTokenPayload.setSub(subject); | ||
accessTokenPayload.setAud(initialize.getAud()); | ||
accessTokenPayload.setType(occurrenceInfo.getType()); | ||
accessTokenPayload.setConditions(accessTokenConditions); | ||
accessTokenPayload.setVersion("1.0"); | ||
return accessTokenPayload; | ||
} | ||
|
||
private String parseBirthDay(final String in) { | ||
if (in != null && !in.isBlank()) { | ||
try { | ||
return OffsetDateTime.parse(in).format(DOB_FORMATTER); | ||
} catch (Exception e) { | ||
// not handle | ||
} | ||
try { | ||
return LocalDate.parse(in, DateTimeFormatter.ofPattern("MM-dd-yyyy")).format(DOB_FORMATTER); | ||
} catch (Exception e) { | ||
// not handle | ||
} | ||
try { | ||
return in.substring(0, 10); | ||
} catch (Exception e) { | ||
// not handle | ||
} | ||
} | ||
return in; | ||
} | ||
} |
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