aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-05 22:46:23 +0300
committerGravatar Vitaly Takmazov2018-09-05 22:46:23 +0300
commit3ad367ca8a9a11c026938459f7b852f6391bd341 (patch)
tree263f1309e83c5dc5cd9b7e5cc97459f936d6895d /juick-server/src/main/java/com/juick/server/api
parent302200828e48932dba38dc36fd41dd23fb6dfc76 (diff)
KeystoreManager shares keystore between XMPP and ActivityPub
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java8
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java10
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Key.java22
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Person.java9
4 files changed, 46 insertions, 3 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index c0dcc3f6..0d987b58 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -1,6 +1,7 @@
package com.juick.server.api.activity;
import com.juick.User;
+import com.juick.server.KeystoreManager;
import com.juick.server.api.activity.model.*;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.UserUtils;
@@ -28,6 +29,8 @@ public class Profile {
private UserService userService;
@Inject
private MessagesService messagesService;
+ @Inject
+ private KeystoreManager keystoreManager;
@Value("${web_domain:localhost}")
private String domain;
@Value("${ap_base_uri:http://localhost:8080/}")
@@ -44,6 +47,11 @@ public class Profile {
uri.replacePath(String.format("/u/%s", userName));
person.setId(uri.toUriString());
person.setName(userName);
+ Key publicKey = new Key();
+ publicKey.setId(person.getId() + "#main-key");
+ publicKey.setOwner(person.getId());
+ publicKey.setPublicKeyPem(keystoreManager.getPublicKey());
+ person.setPublicKey(publicKey);
uri.replacePath("/post");
person.setInbox(uri.toUriString());
person.setOutbox(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
index 7859be86..84a3e018 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
@@ -3,6 +3,9 @@ package com.juick.server.api.activity.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
public abstract class ActivityObject {
@@ -23,11 +26,12 @@ public abstract class ActivityObject {
}
@JsonProperty("@context")
- public String getContext() {
- return CONTEXT_URI;
+ public List<String> getContext() {
+ return Arrays.asList(ACTIVITY_STREAMS_URI, SECURITY_URI);
}
- public final static String CONTEXT_URI = "https://www.w3.org/ns/activitystreams";
+ public final static String ACTIVITY_STREAMS_URI = "https://www.w3.org/ns/activitystreams";
+ public final static String SECURITY_URI = "https://w3id.org/security/v1";
public final static String LD_JSON_MEDIA_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
public final static String ACTIVITY_JSON_MEDIA_TYPE = "application/activity+json; profile=\"https://www.w3.org/ns/activitystreams\"";
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Key.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Key.java
new file mode 100644
index 00000000..32417778
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Key.java
@@ -0,0 +1,22 @@
+package com.juick.server.api.activity.model;
+
+public class Key extends ActivityObject {
+ private String owner;
+ private String publicKeyPem;
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public String getPublicKeyPem() {
+ return publicKeyPem;
+ }
+
+ public void setPublicKeyPem(String publicKeyPem) {
+ this.publicKeyPem = publicKeyPem;
+ }
+}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java
index f4312ffc..97fa5ae8 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java
@@ -9,6 +9,7 @@ public class Person extends ActivityObject {
private String following;
private String followers;
private Link url;
+ private Key publicKey;
@Override
public String getType() {
@@ -70,4 +71,12 @@ public class Person extends ActivityObject {
public void setUrl(Link url) {
this.url = url;
}
+
+ public Key getPublicKey() {
+ return publicKey;
+ }
+
+ public void setPublicKey(Key publicKey) {
+ this.publicKey = publicKey;
+ }
}