aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/SignatureManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/SignatureManager.java')
-rw-r--r--src/main/java/com/juick/SignatureManager.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java
index 0c6acb4a..49c8c7dd 100644
--- a/src/main/java/com/juick/SignatureManager.java
+++ b/src/main/java/com/juick/SignatureManager.java
@@ -129,26 +129,30 @@ public class SignatureManager {
if (context.isPresent() && context.get() instanceof Actor) {
Actor actor = (Actor) context.get();
Key key = KeystoreManager.publicKeyOf(actor);
-
- Verifier verifier = new Verifier(key, signature);
- try {
- boolean result = verifier.verify(method, path, headers);
- if (result) {
- User user = new User();
- user.setUri(URI.create(actor.getId()));
- if (key.equals(keystoreManager.getPublicKey())) {
- return userService.getUserByName(actor.getName());
- }
- if (actor.isSuspended()) {
- logger.info("{} is suspended, deleting", actor.getId());
- applicationEventPublisher.publishEvent(new DeleteUserEvent(this, actor.getId()));
+ if (key != null) {
+ Verifier verifier = new Verifier(key, signature);
+ try {
+ boolean result = verifier.verify(method, path, headers);
+ if (result) {
+ User user = new User();
+ user.setUri(URI.create(actor.getId()));
+ if (key.equals(keystoreManager.getPublicKey())) {
+ return userService.getUserByName(actor.getName());
+ }
+ if (actor.isSuspended()) {
+ logger.info("{} is suspended, deleting", actor.getId());
+ applicationEventPublisher.publishEvent(new DeleteUserEvent(this, actor.getId()));
+ }
+ return user;
+ } else {
+ return AnonymousUser.INSTANCE;
}
- return user;
- } else {
- return AnonymousUser.INSTANCE;
+ } catch (NoSuchAlgorithmException | SignatureException | MissingRequiredHeaderException
+ | IOException e) {
+ logger.warn("Invalid signature {}: {}", signatureString, e.getMessage());
}
- } catch (NoSuchAlgorithmException | SignatureException | MissingRequiredHeaderException | IOException e) {
- logger.warn("Invalid signature {}: {}", signatureString, e.getMessage());
+ } else {
+ logger.warn("Unknown actor");
}
} else {
logger.warn("Unknown keyId");