diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/SignatureManager.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java index 92cb7fd9..792cc8cd 100644 --- a/src/main/java/com/juick/SignatureManager.java +++ b/src/main/java/com/juick/SignatureManager.java @@ -90,12 +90,12 @@ public class SignatureManager { } public String addSignature(Actor from, String host, String method, String path, String dateString, - String digestHeader) throws IOException { + String digestHeader) throws IOException { return addSignature(from, host, method, path, dateString, digestHeader, keystoreManager); } public String addSignature(Actor from, String host, String method, String path, String dateString, - String digestHeader, KeystoreManager keystoreManager) throws IOException { + String digestHeader, KeystoreManager keystoreManager) throws IOException { List<String> requiredHeaders = StringUtils.isEmpty(digestHeader) ? Arrays.asList("(request-target)", "host", "date") : Arrays.asList("(request-target)", "host", "date", "digest"); @@ -138,7 +138,7 @@ public class SignatureManager { return AnonymousUser.INSTANCE; } } catch (NoSuchAlgorithmException | SignatureException | MissingRequiredHeaderException - | IOException e) { + | IOException e) { logger.warn("Verification error for {}: {}", signature.getKeyId(), e.getMessage()); } } else { @@ -156,12 +156,15 @@ public class SignatureManager { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.valueOf(ACTIVITY_MEDIA_TYPE))); HttpEntity<Void> activityRequest = new HttpEntity<>(headers); - Context context = apClient.exchange(contextUri, HttpMethod.GET, activityRequest, Context.class).getBody(); - if (context == null) { - logger.warn("Cannot identify {}", contextUri); - return Optional.empty(); + var response = apClient.exchange(contextUri, HttpMethod.GET, activityRequest, Context.class); + if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) { + var context = response.getBody(); + if (context == null) { + logger.warn("Cannot identify {}", contextUri); + return Optional.empty(); + } + return Optional.of(context); } - return Optional.of(context); } catch (Exception e) { logger.warn("{}", e.getMessage()); } |