generated from digitalservicebund/java-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
a3c5b6c
commit 264c05e
Showing
15 changed files
with
177 additions
and
61 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
71 changes: 62 additions & 9 deletions
71
src/main/java/de/bund/digitalservice/a2j/config/FitConnectConfig.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 |
---|---|---|
@@ -1,28 +1,81 @@ | ||
package de.bund.digitalservice.a2j.config; | ||
|
||
import com.nimbusds.jose.jwk.JWK; | ||
import dev.fitko.fitconnect.api.config.ApplicationConfig; | ||
import dev.fitko.fitconnect.api.config.SenderConfig; | ||
import dev.fitko.fitconnect.api.config.SubscriberConfig; | ||
import dev.fitko.fitconnect.api.config.defaults.Environments; | ||
import dev.fitko.fitconnect.client.SenderClient; | ||
import dev.fitko.fitconnect.client.bootstrap.ApplicationConfigLoader; | ||
import dev.fitko.fitconnect.client.SubscriberClient; | ||
import dev.fitko.fitconnect.client.bootstrap.ClientFactory; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.text.ParseException; | ||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
@Configuration | ||
public class FitConnectConfig { | ||
private final ResourceLoader resourceLoader; | ||
@Value("${fitConnect.sender.clientId}") | ||
String senderClientId; | ||
|
||
public FitConnectConfig(ResourceLoader resourceLoader) { | ||
this.resourceLoader = resourceLoader; | ||
} | ||
@Value("${fitConnect.sender.clientSecret}") | ||
String senderClientSecret; | ||
|
||
@Value("${fitConnect.subscriber.clientId}") | ||
String subscriberClientId; | ||
|
||
@Value("${fitConnect.subscriber.clientSecret}") | ||
String subscriberClientSecret; | ||
|
||
@Value("${fitConnect.subscriber.privateDecryptionKeyPath}") | ||
String subscriberPrivateDecryptionKeyPath; | ||
|
||
@Value("${fitConnect.subscriber.privateSigningKeyPath}") | ||
String subscriberPrivateSigningKeyPath; | ||
|
||
@Bean | ||
public SenderClient senderClient() throws IOException { | ||
public SenderClient senderClient() { | ||
SenderConfig senderConfig = | ||
SenderConfig.builder().clientId(senderClientId).clientSecret(senderClientSecret).build(); | ||
|
||
ApplicationConfig config = | ||
ApplicationConfigLoader.loadConfigFromPath( | ||
Path.of(resourceLoader.getResource("classpath:fitConnectConfig.yaml").getURI())); | ||
ApplicationConfig.builder() | ||
.senderConfig(senderConfig) | ||
.activeEnvironment(Environments.TEST.getEnvironmentName()) | ||
.build(); | ||
|
||
return ClientFactory.createSenderClient(config); | ||
} | ||
|
||
@Bean | ||
public SubscriberClient subscriberClient() throws IOException, ParseException { | ||
SubscriberConfig subscriberConfig = | ||
SubscriberConfig.builder() | ||
.clientId(subscriberClientId) | ||
.clientSecret(subscriberClientSecret) | ||
.privateDecryptionKeys(List.of(loadKey(subscriberPrivateDecryptionKeyPath))) | ||
.privateSigningKey(loadKey(subscriberPrivateSigningKeyPath)) | ||
.build(); | ||
|
||
ApplicationConfig config = | ||
ApplicationConfig.builder() | ||
.subscriberConfig(subscriberConfig) | ||
.activeEnvironment(Environments.TEST.getEnvironmentName()) | ||
.build(); | ||
|
||
return ClientFactory.createSubscriberClient(config); | ||
} | ||
|
||
private JWK loadKey(String filePath) throws IOException, ParseException { | ||
Path path = Paths.get(new ClassPathResource(filePath).getURI()); | ||
String jwkContent = Files.readString(path); | ||
|
||
return JWK.parse(jwkContent); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/de/bund/digitalservice/a2j/config/SecurityConfig.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
16 changes: 0 additions & 16 deletions
16
src/main/java/de/bund/digitalservice/a2j/controller/ReceiverController.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/java/de/bund/digitalservice/a2j/controller/SubscriberController.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,22 @@ | ||
package de.bund.digitalservice.a2j.controller; | ||
|
||
import de.bund.digitalservice.a2j.service.subscriber.SubscriberService; | ||
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class SubscriberController { | ||
|
||
private final SubscriberService service; | ||
|
||
public SubscriberController(SubscriberService service) { | ||
this.service = service; | ||
} | ||
|
||
@PostMapping("callbacks/fit-connect") | ||
public void newSubmission(@RequestBody SubmissionForPickup submission) { | ||
service.pickUpSubmission(submission); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/de/bund/digitalservice/a2j/service/subscriber/FitConnectSubscriberService.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,27 @@ | ||
package de.bund.digitalservice.a2j.service.subscriber; | ||
|
||
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup; | ||
import dev.fitko.fitconnect.api.domain.subscriber.ReceivedSubmission; | ||
import dev.fitko.fitconnect.client.SubscriberClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FitConnectSubscriberService implements SubscriberService { | ||
|
||
private final SubscriberClient client; | ||
private static final Logger logger = LoggerFactory.getLogger(FitConnectSubscriberService.class); | ||
|
||
public FitConnectSubscriberService(SubscriberClient client) { | ||
this.client = client; | ||
} | ||
|
||
public void pickUpSubmission(SubmissionForPickup submissionForPickup) { | ||
ReceivedSubmission receivedSubmission = client.requestSubmission(submissionForPickup); | ||
logger.info("Submission requested. SubmissionId: " + submissionForPickup.getSubmissionId()); | ||
|
||
receivedSubmission.acceptSubmission(); | ||
logger.info("Submission accepted. CaseId: " + receivedSubmission.getCaseId()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/de/bund/digitalservice/a2j/service/subscriber/SubscriberService.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,8 @@ | ||
package de.bund.digitalservice.a2j.service.subscriber; | ||
|
||
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup; | ||
|
||
public interface SubscriberService { | ||
|
||
void pickUpSubmission(SubmissionForPickup submissionForPickup); | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
fitConnect: | ||
sender: | ||
clientId: senderClientId | ||
clientSecret: s3cr3t | ||
subscriber: | ||
clientId: subscriberClientId | ||
clientSecret: s3cr3t | ||
privateDecryptionKeyPath: decryption_key.json | ||
privateSigningKeyPath: signing_key.json | ||
activeEnvironment: TEST | ||
submission: | ||
destination: destinationId | ||
serviceType: | ||
urn: urn:de:fim:leika:leistung:99400048079000 | ||
name: Simple Dummy Service | ||
jsonUri: https://schema.fitko.de/fim/s17000717_1.0.schema.json | ||
callbackSecret: s3cr3t |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
submission: | ||
destination: d0fe1fad-erf3-4c67-123i-9d0ca6663bf3 | ||
serviceType: | ||
urn: urn:de:fim:leika:leistung:99400048079112 | ||
name: Simple Dummy Service | ||
jsonUri: https://schema.fitko.de/fim/s170007g_1.0.schema.json | ||
|
||
callbackSecret: s3cr3t | ||
fitConnect: | ||
sender: | ||
clientId: senderClientId | ||
clientSecret: s3cr3t | ||
subscriber: | ||
clientId: subscriberClientId | ||
clientSecret: s3cr3t | ||
privateDecryptionKeyPath: decryption_key.json | ||
privateSigningKeyPath: signing_key.json | ||
activeEnvironment: TEST | ||
submission: | ||
destination: destinationId | ||
serviceType: | ||
urn: urn:de:fim:leika:leistung:99400048079000 | ||
name: Simple Dummy Service | ||
jsonUri: https://schema.fitko.de/fim/s17000717_1.0.schema.json | ||
callbackSecret: s3cr3t |