aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com
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
parent396409a01f12a39e3386b53e08ed260d2a1bd92a (diff)
ActivityPub: handle http error when getting Person context
Diffstat (limited to 'juick-server/src/main/java/com')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java8
-rw-r--r--juick-server/src/main/java/com/juick/server/SignatureManager.java17
2 files changed, 16 insertions, 9 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
index e0bbdb85..cbe7f623 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -53,8 +53,8 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
User followedUser = socialService.getUserByAccountUri(acct);
if (!followedUser.isAnonymous()) {
// automatically accept follower requests
- Person me = (Person) signatureManager.getContext(URI.create(acct));
- Person follower = (Person) signatureManager.getContext(URI.create(followEvent.getRequest().getActor()));
+ Person me = (Person) signatureManager.getContext(URI.create(acct)).get();
+ Person follower = (Person) signatureManager.getContext(URI.create(followEvent.getRequest().getActor())).get();
Accept accept = new Accept();
accept.setActor(me.getId());
accept.setObject(followEvent.getRequest());
@@ -85,9 +85,9 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
User user = msg.getUser();
String userUri = personUri(user);
Note note = makeNote(msg);
- Person me = (Person) signatureManager.getContext(URI.create(userUri));
+ Person me = (Person) signatureManager.getContext(URI.create(userUri)).get();
socialService.getFollowers(user).forEach(acct -> {
- Person follower = (Person) signatureManager.getContext(URI.create(acct));
+ Person follower = (Person) signatureManager.getContext(URI.create(acct)).get();
Create create = new Create();
create.setId(note.getId());
create.setActor(me.getId());
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();
}
}