aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/SignatureManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-04 14:40:24 +0300
committerGravatar Vitaly Takmazov2018-10-04 14:40:24 +0300
commit2ed731f66cccdf0a38fbfda33ada8025ad186920 (patch)
tree7f4b366cd9b65526cc5112daf1ddeed9d278581c /juick-server/src/main/java/com/juick/server/SignatureManager.java
parent396409a01f12a39e3386b53e08ed260d2a1bd92a (diff)
ActivityPub: handle http error when getting Person context
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/SignatureManager.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/SignatureManager.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/juick-server/src/main/java/com/juick/server/SignatureManager.java b/juick-server/src/main/java/com/juick/server/SignatureManager.java
index 0c5ea512..98ccc24d 100644
--- a/juick-server/src/main/java/com/juick/server/SignatureManager.java
+++ b/juick-server/src/main/java/com/juick/server/SignatureManager.java
@@ -8,6 +8,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.tomitribe.auth.signatures.Signature;
@@ -25,6 +26,7 @@ import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
@Component
public class SignatureManager {
@@ -55,9 +57,9 @@ public class SignatureManager {
logger.info("accepted follower: {}", response.getStatusCodeValue());
}
public boolean verifySignature(String signatureString, URI actor, String method, String path, Map<String, String> headers) {
- Context context = getContext(actor);
- if (context instanceof Person) {
- Person person = (Person) context;
+ Optional<Context> context = getContext(actor);
+ if (context.isPresent() && context.get() instanceof Person) {
+ Person person = (Person) context.get();
Key key = KeystoreManager.publicKeyOf(person);
Verifier verifier = new Verifier(key, Signature.fromString(signatureString));
try {
@@ -72,7 +74,12 @@ public class SignatureManager {
logger.info("person not found");
return false;
}
- public Context getContext(URI contextUri) {
- return new RestTemplate().getForEntity(contextUri, Context.class).getBody();
+ Optional<Context> getContext(URI contextUri) {
+ try {
+ return Optional.of(new RestTemplate().getForEntity(contextUri, Context.class).getBody());
+ } catch (HttpClientErrorException e) {
+ logger.warn("Cannot identify {}", contextUri);
+ }
+ return Optional.empty();
}
}