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.
Use sdk for callback verification 🤦
- Loading branch information
1 parent
ab5c68a
commit c89b919
Showing
12 changed files
with
73 additions
and
235 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
50 changes: 50 additions & 0 deletions
50
src/main/java/de/bund/digitalservice/a2j/service/receiver/CallbackVerificationFilter.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,50 @@ | ||
package de.bund.digitalservice.a2j.service.receiver; | ||
|
||
import dev.fitko.fitconnect.client.SenderClient; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
@Component | ||
public class CallbackVerificationFilter extends OncePerRequestFilter { | ||
private final SenderClient senderClient; | ||
private final String callbackSecret; | ||
|
||
public CallbackVerificationFilter( | ||
SenderClient senderClient, @Value("${callbackSecret}") String callbackSecret) { | ||
this.senderClient = senderClient; | ||
this.callbackSecret = callbackSecret; | ||
} | ||
|
||
@Override | ||
protected boolean shouldNotFilter(HttpServletRequest request) { | ||
return !request.getServletPath().startsWith("/callbacks/fit-connect"); | ||
} | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain chain) | ||
throws ServletException, IOException { | ||
|
||
if (!senderClient | ||
.validateCallback( | ||
request.getHeader("callback-athentication"), | ||
Long.parseLong(request.getHeader("callback-timestamp")), | ||
request.getReader().lines().reduce("", String::concat), | ||
callbackSecret) | ||
.isValid()) { | ||
|
||
System.out.println("Received fit-connect callback, returned 401"); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
return; | ||
} | ||
|
||
chain.doFilter(request, response); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
.../de/bund/digitalservice/a2j/service/receiver/verification/CallbackVerificationFilter.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
...de/bund/digitalservice/a2j/service/receiver/verification/CallbackVerificationService.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
src/main/java/de/bund/digitalservice/a2j/service/receiver/verification/HmacVerifier.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...main/java/de/bund/digitalservice/a2j/service/receiver/verification/TimestampVerifier.java
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,8 @@ | ||
submission: | ||
destination: d0fe1fad-d6f1-4c67-b4e7-9d0ca6663bf3 | ||
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 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
62 changes: 0 additions & 62 deletions
62
...und/digitalservice/a2j/service/receiver/verification/CallbackVerificationServiceTest.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
.../java/de/bund/digitalservice/a2j/service/receiver/verification/TimestampVerifierTest.java
This file was deleted.
Oops, something went wrong.