diff options
author | 2018-11-03 13:14:15 +0300 | |
---|---|---|
committer | 2018-11-03 13:14:15 +0300 | |
commit | 2a64e080a395170875d62d3bebaf4dce3815bb13 (patch) | |
tree | e9c34caf2a694899ea67ab13d6bb2e0c20bee20d /juick-server/src/main/java/com/juick/server/SignatureManager.java | |
parent | 5cf3c20ed4463c6f35d51fc4e10366fe2b850f29 (diff) |
ActivityPub: mentions with @user@server.tld
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/SignatureManager.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/SignatureManager.java | 26 |
1 files changed, 20 insertions, 6 deletions
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 927a62a7..b3b7a301 100644 --- a/juick-server/src/main/java/com/juick/server/SignatureManager.java +++ b/juick-server/src/main/java/com/juick/server/SignatureManager.java @@ -3,22 +3,22 @@ package com.juick.server; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.objects.Person; -import com.juick.service.activities.DeleteUserEvent; +import com.juick.server.api.webfinger.model.Account; +import com.juick.server.api.webfinger.model.Link; import com.juick.util.DateFormattersHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; 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; import org.tomitribe.auth.signatures.Signer; import org.tomitribe.auth.signatures.Verifier; +import rocks.xmpp.addr.Jid; import javax.inject.Inject; import java.io.IOException; @@ -27,12 +27,12 @@ import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SignatureException; import java.time.Instant; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import static com.juick.server.api.activity.model.Context.ACTIVITY_MEDIA_TYPE; + @Component public class SignatureManager { private static final Logger logger = LoggerFactory.getLogger(ActivityPubManager.class); @@ -58,7 +58,7 @@ public class SignatureManager { headers.put("date", requestDate); Signature signature = signer.sign("POST", inbox.getPath(), headers); HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Content-Type", Context.ACTIVITY_JSON_MEDIA_TYPE); + requestHeaders.add("Content-Type", Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE); requestHeaders.add("Date", requestDate); requestHeaders.add("Signature", signature.toString().substring(10)); HttpEntity<Context> request = new HttpEntity<>(Context.build(data), requestHeaders); @@ -96,4 +96,18 @@ public class SignatureManager { } return Optional.of(context); } + public Optional<Context> discoverPerson(String acct) { + Jid acctId = Jid.of(acct); + URI resourceUri = UriComponentsBuilder.fromUriString( + String.format("https://%s/.well-known/webfinger?resource=acct:%s", acctId.getDomain(), acct)).build().toUri(); + Account acctData = apClient.getForEntity(resourceUri, Account.class).getBody(); + if (acctData != null) { + for (Link l : acctData.getLinks()) { + if (l.getRel().equals("self") && l.getType().equals(ACTIVITY_MEDIA_TYPE)) { + return getContext(URI.create(l.getHref())); + } + } + } + return Optional.empty(); + } } |