Merge branch 'MSC2140'
# Conflicts: # src/main/java/io/kamax/mxisd/session/SessionManager.java
This commit is contained in:
@@ -57,6 +57,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
@@ -240,12 +242,26 @@ public class SessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private String getDomain(String publicUrl) {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(publicUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
log.error("Malformed public url, use as is");
|
||||
return publicUrl;
|
||||
}
|
||||
int port = url.getPort();
|
||||
return url.getHost() + (port != -1 ? ":" + url.getPort() : "");
|
||||
}
|
||||
|
||||
private void checkAuthorization(String auth, JsonObject reqData) {
|
||||
if (!auth.startsWith("X-Matrix ")) {
|
||||
throw new NotAllowedException("Wrong authorization header");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(cfg.getServer().getPublicUrl())) {
|
||||
String domain = getDomain(cfg.getServer().getPublicUrl());
|
||||
|
||||
if (StringUtils.isBlank(domain)) {
|
||||
throw new NotAllowedException("Unable to verify request, missing `server.publicUrl` property");
|
||||
}
|
||||
|
||||
@@ -287,7 +303,7 @@ public class SessionManager {
|
||||
jsonObject.addProperty("method", "POST");
|
||||
jsonObject.addProperty("uri", "/_matrix/identity/api/v1/3pid/unbind");
|
||||
jsonObject.addProperty("origin", origin);
|
||||
jsonObject.addProperty("destination_is", URI.create(cfg.getServer().getPublicUrl()).getHost());
|
||||
jsonObject.addProperty("destination_is", domain);
|
||||
jsonObject.add("content", reqData);
|
||||
|
||||
String canonical = MatrixJson.encodeCanonical(jsonObject);
|
||||
|
||||
Reference in New Issue
Block a user