MSC2140 Add option to enable/disable v1 and v2 api.
This commit is contained in:
@@ -25,8 +25,6 @@ public class IsAPIv1 {
|
||||
public static final String Base = "/_matrix/identity/api/v1";
|
||||
|
||||
public static String getValidate(String medium, String sid, String secret, String token) {
|
||||
// FIXME use some kind of URLBuilder
|
||||
return Base + "/validate/" + medium + "/submitToken?sid=" + sid + "&client_secret=" + secret + "&token=" + token;
|
||||
return String.format("%s/validate/%s/submitToken?sid=%s&client_secret=%s&token=%s", Base, medium, sid, secret, token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
31
src/main/java/io/kamax/mxisd/http/IsAPIv2.java
Normal file
31
src/main/java/io/kamax/mxisd/http/IsAPIv2.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.http;
|
||||
|
||||
public class IsAPIv2 {
|
||||
|
||||
public static final String Base = "/_matrix/identity/v2";
|
||||
|
||||
public static String getValidate(String medium, String sid, String secret, String token) {
|
||||
return String.format("%s/validate/%s/submitToken?sid=%s&client_secret=%s&token=%s", Base, medium, sid, secret, token);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.kamax.mxisd.http.undertow.handler;
|
||||
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.IsAPIv2;
|
||||
import io.kamax.mxisd.matrix.IdentityServiceAPI;
|
||||
import io.undertow.server.HttpHandler;
|
||||
|
||||
public interface ApiHandler extends HttpHandler {
|
||||
|
||||
default String getPath(IdentityServiceAPI api) {
|
||||
switch (api) {
|
||||
case V2:
|
||||
return IsAPIv2.Base + getHandlerPath();
|
||||
case V1:
|
||||
return IsAPIv1.Base + getHandlerPath();
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown api version: " + api);
|
||||
}
|
||||
}
|
||||
|
||||
String getHandlerPath();
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.io.identity.ClientBulkLookupAnswer;
|
||||
import io.kamax.mxisd.http.io.identity.ClientBulkLookupRequest;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.lookup.BulkLookupRequest;
|
||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||
import io.kamax.mxisd.lookup.strategy.LookupStrategy;
|
||||
@@ -33,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BulkLookupHandler extends LookupHandler {
|
||||
public class BulkLookupHandler extends LookupHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/bulk_lookup";
|
||||
|
||||
@@ -69,4 +70,8 @@ public class BulkLookupHandler extends LookupHandler {
|
||||
respondJson(exchange, answer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/bulk_lookup";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
import io.kamax.mxisd.crypto.KeyManager;
|
||||
import io.kamax.mxisd.crypto.KeyType;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EphemeralKeyIsValidHandler extends KeyIsValidHandler {
|
||||
public class EphemeralKeyIsValidHandler extends KeyIsValidHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/pubkey/ephemeral/isvalid";
|
||||
|
||||
@@ -48,4 +49,8 @@ public class EphemeralKeyIsValidHandler extends KeyIsValidHandler {
|
||||
respondJson(exchange, mgr.isValid(KeyType.Ephemeral, pubKey) ? validKey : invalidKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/pubkey/ephemeral/isvalid";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,10 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
|
||||
public class HelloHandler extends BasicHttpHandler {
|
||||
public class HelloHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base;
|
||||
|
||||
@@ -33,4 +34,8 @@ public class HelloHandler extends BasicHttpHandler {
|
||||
respondJson(exchange, "{}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,13 @@ import io.kamax.mxisd.crypto.KeyManager;
|
||||
import io.kamax.mxisd.crypto.KeyType;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class KeyGetHandler extends BasicHttpHandler {
|
||||
public class KeyGetHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Key = "key";
|
||||
public static final String Path = IsAPIv1.Base + "/pubkey/{" + Key + "}";
|
||||
@@ -61,4 +62,8 @@ public class KeyGetHandler extends BasicHttpHandler {
|
||||
respond(exchange, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/pubkey/{" + Key + "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
import io.kamax.mxisd.crypto.KeyManager;
|
||||
import io.kamax.mxisd.crypto.KeyType;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RegularKeyIsValidHandler extends KeyIsValidHandler {
|
||||
public class RegularKeyIsValidHandler extends KeyIsValidHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/pubkey/isvalid";
|
||||
|
||||
@@ -48,4 +49,8 @@ public class RegularKeyIsValidHandler extends KeyIsValidHandler {
|
||||
respondJson(exchange, mgr.isValid(KeyType.Regular, pubKey) ? validKey : invalidKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/pubkey/isvalid";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,14 @@ import io.kamax.mxisd.http.io.identity.RequestTokenResponse;
|
||||
import io.kamax.mxisd.http.io.identity.SessionEmailTokenRequestJson;
|
||||
import io.kamax.mxisd.http.io.identity.SessionPhoneTokenRequestJson;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.session.SessionManager;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SessionStartHandler extends BasicHttpHandler {
|
||||
public class SessionStartHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Medium = "medium";
|
||||
public static final String Path = IsAPIv1.Base + "/validate/{" + Medium + "}/requestToken";
|
||||
@@ -84,4 +85,8 @@ public class SessionStartHandler extends BasicHttpHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/validate/{" + Medium + "}/requestToken";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.io.identity.BindRequest;
|
||||
import io.kamax.mxisd.http.io.identity.SingeLookupReplyJson;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.invitation.InvitationManager;
|
||||
import io.kamax.mxisd.lookup.SingleLookupReply;
|
||||
import io.kamax.mxisd.session.SessionManager;
|
||||
@@ -42,7 +43,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
|
||||
public class SessionTpidBindHandler extends BasicHttpHandler {
|
||||
public class SessionTpidBindHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/3pid/bind";
|
||||
|
||||
@@ -97,4 +98,8 @@ public class SessionTpidBindHandler extends BasicHttpHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/3pid/bind";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,14 @@ import com.google.gson.JsonObject;
|
||||
import io.kamax.mxisd.exception.SessionNotValidatedException;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.lookup.ThreePidValidation;
|
||||
import io.kamax.mxisd.session.SessionManager;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SessionTpidGetValidatedHandler extends BasicHttpHandler {
|
||||
public class SessionTpidGetValidatedHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/3pid/getValidated3pid";
|
||||
|
||||
@@ -62,4 +63,8 @@ public class SessionTpidGetValidatedHandler extends BasicHttpHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/3pid/getValidated3pid";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,13 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.session.SessionManager;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SessionTpidUnbindHandler extends BasicHttpHandler {
|
||||
public class SessionTpidUnbindHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/3pid/unbind";
|
||||
|
||||
@@ -48,4 +49,9 @@ public class SessionTpidUnbindHandler extends BasicHttpHandler {
|
||||
sessionMgr.unbind(auth, body);
|
||||
writeBodyAsUtf8(exchange, "{}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/3pid/unbind";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,14 @@ package io.kamax.mxisd.http.undertow.handler.identity.v1;
|
||||
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.session.SessionManager;
|
||||
import io.kamax.mxisd.session.ValidationResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class SessionValidateHandler extends BasicHttpHandler {
|
||||
public abstract class SessionValidateHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/validate/{medium}/submitToken";
|
||||
|
||||
@@ -52,4 +53,8 @@ public abstract class SessionValidateHandler extends BasicHttpHandler {
|
||||
return mgr.validate(sid, secret, token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/validate/{medium}/submitToken";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,14 @@ import io.kamax.mxisd.config.MxisdConfig;
|
||||
import io.kamax.mxisd.crypto.SignatureManager;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.invitation.InvitationManager;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SignEd25519Handler extends BasicHttpHandler {
|
||||
public class SignEd25519Handler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/sign-ed25519";
|
||||
|
||||
@@ -72,4 +73,8 @@ public class SignEd25519Handler extends BasicHttpHandler {
|
||||
respondJson(exchange, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/sign-ed25519";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.crypto.SignatureManager;
|
||||
import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.io.identity.SingeLookupReplyJson;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.lookup.SingleLookupReply;
|
||||
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
||||
import io.kamax.mxisd.lookup.strategy.LookupStrategy;
|
||||
@@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class SingleLookupHandler extends LookupHandler {
|
||||
public class SingleLookupHandler extends LookupHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/lookup";
|
||||
|
||||
@@ -77,4 +78,8 @@ public class SingleLookupHandler extends LookupHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/lookup";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import io.kamax.mxisd.http.IsAPIv1;
|
||||
import io.kamax.mxisd.http.io.identity.StoreInviteRequest;
|
||||
import io.kamax.mxisd.http.io.identity.ThreePidInviteReplyIO;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.ApiHandler;
|
||||
import io.kamax.mxisd.invitation.IThreePidInvite;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.invitation.InvitationManager;
|
||||
@@ -45,7 +46,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
|
||||
public class StoreInviteHandler extends BasicHttpHandler {
|
||||
public class StoreInviteHandler extends BasicHttpHandler implements ApiHandler {
|
||||
|
||||
public static final String Path = IsAPIv1.Base + "/store-invite";
|
||||
|
||||
@@ -100,4 +101,8 @@ public class StoreInviteHandler extends BasicHttpHandler {
|
||||
respondJson(exchange, new ThreePidInviteReplyIO(reply, keyMgr.getPublicKeyBase64(keyMgr.getServerSigningKey().getId()), cfg.getPublicUrl()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandlerPath() {
|
||||
return "/store-invite";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user