aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/SignatureManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-04 22:57:31 +0300
committerGravatar Vitaly Takmazov2023-01-04 22:57:31 +0300
commit120b26c55069f89cc60ef862514d5cf09566f348 (patch)
tree3bbcc3886c59f330a421269ebf2e24225fa844dc /src/main/java/com/juick/SignatureManager.java
parent9aee05354c68e2bb336ccc8e67b2c36ede41c997 (diff)
Fix class cast exception in tests
Diffstat (limited to 'src/main/java/com/juick/SignatureManager.java')
-rw-r--r--src/main/java/com/juick/SignatureManager.java19
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());
}