Search in sources :

Example 1 with IThreePidInviteReply

use of io.kamax.mxisd.invitation.IThreePidInviteReply in project mxisd by kamax-io.

the class SignEd25519Handler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) {
    JsonObject body = parseJsonObject(exchange);
    _MatrixID mxid = MatrixID.asAcceptable(GsonUtil.getStringOrThrow(body, "mxid"));
    String token = GsonUtil.getStringOrThrow(body, "token");
    String privKey = GsonUtil.getStringOrThrow(body, "private_key");
    IThreePidInviteReply reply = invMgr.getInvite(token, privKey);
    _MatrixID sender = reply.getInvite().getSender();
    JsonObject res = new JsonObject();
    res.addProperty("token", token);
    res.addProperty("sender", sender.getId());
    res.addProperty("mxid", mxid.getId());
    res.add("signatures", signMgr.signMessageGson(cfg.getServer().getName(), MatrixJson.encodeCanonical(res)));
    log.info("Signed data for invite using token {}", token);
    respondJson(exchange, res);
}
Also used : JsonObject(com.google.gson.JsonObject) IThreePidInviteReply(io.kamax.mxisd.invitation.IThreePidInviteReply) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID)

Example 2 with IThreePidInviteReply

use of io.kamax.mxisd.invitation.IThreePidInviteReply in project mxisd by kamax-io.

the class InvitationController method store.

@RequestMapping(value = "/store-invite", method = POST)
String store(HttpServletRequest request, @RequestParam String sender, @RequestParam String medium, @RequestParam String address, @RequestParam("room_id") String roomId) {
    Map<String, String> parameters = new HashMap<>();
    for (String key : request.getParameterMap().keySet()) {
        parameters.put(key, request.getParameter(key));
    }
    IThreePidInvite invite = new ThreePidInvite(new MatrixID(sender), medium, address, roomId, parameters);
    IThreePidInviteReply reply = mgr.storeInvite(invite);
    return gson.toJson(new ThreePidInviteReplyIO(reply, keyMgr.getPublicKeyBase64(keyMgr.getCurrentIndex()), srvCfg.getPublicUrl()));
}
Also used : ThreePidInvite(io.kamax.mxisd.invitation.ThreePidInvite) IThreePidInvite(io.kamax.mxisd.invitation.IThreePidInvite) HashMap(java.util.HashMap) ThreePidInviteReplyIO(io.kamax.mxisd.controller.identity.v1.io.ThreePidInviteReplyIO) IThreePidInvite(io.kamax.mxisd.invitation.IThreePidInvite) IThreePidInviteReply(io.kamax.mxisd.invitation.IThreePidInviteReply) MatrixID(io.kamax.matrix.MatrixID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IThreePidInviteReply

use of io.kamax.mxisd.invitation.IThreePidInviteReply in project mxisd by kamax-io.

the class InviteCommandProcessor method process.

@Override
public void process(Mxisd m, _MatrixClient client, _MatrixRoom room, CommandLine cmdLine) {
    if (cmdLine.getArgs().length < 2) {
        room.sendNotice(buildHelp());
    } else {
        String arg = cmdLine.getArgList().get(1);
        String response;
        if (StringUtils.equals("list", arg)) {
            StrBuilder b = new StrBuilder();
            List<IThreePidInviteReply> invites = m.getInvite().listInvites();
            if (invites.isEmpty()) {
                b.appendln("No invites!");
                response = b.toString();
            } else {
                b.appendln("Invites:");
                for (IThreePidInviteReply invite : invites) {
                    b.appendNewLine().append("ID: ").append(invite.getId());
                    b.appendNewLine().append("Room: ").append(invite.getInvite().getRoomId());
                    b.appendNewLine().append("Medium: ").append(invite.getInvite().getMedium());
                    b.appendNewLine().append("Address: ").append(invite.getInvite().getAddress());
                    b.appendNewLine();
                }
                response = b.appendNewLine().append("Total: " + invites.size()).toString();
            }
        } else if (StringUtils.equals("show", arg)) {
            if (cmdLine.getArgList().size() < 3) {
                response = buildHelp();
            } else {
                String id = cmdLine.getArgList().get(2);
                IThreePidInviteReply invite = m.getInvite().getInvite(id);
                StrBuilder b = new StrBuilder();
                b.appendln("Details for Invitation #" + id);
                b.appendNewLine().append("Room: ").append(invite.getInvite().getRoomId());
                b.appendNewLine().append("Sender: ").append(invite.getInvite().getSender().toString());
                b.appendNewLine().append("Medium: ").append(invite.getInvite().getMedium());
                b.appendNewLine().append("Address: ").append(invite.getInvite().getAddress());
                b.appendNewLine().append("Display name: ").append(invite.getDisplayName());
                b.appendNewLine().appendNewLine().append("Properties:");
                invite.getInvite().getProperties().forEach((k, v) -> {
                    b.appendNewLine().append("\t").append(k).append("=").append(v);
                });
                b.appendNewLine();
                response = b.toString();
            }
        } else if (StringUtils.equals("revoke", arg)) {
            if (cmdLine.getArgList().size() < 3) {
                response = buildHelp();
            } else {
                m.getInvite().expireInvite(cmdLine.getArgList().get(2));
                response = "OK";
            }
        } else {
            response = buildError("Unknown invite action: " + arg, true);
        }
        room.sendNotice(response);
    }
}
Also used : StrBuilder(org.apache.commons.lang.text.StrBuilder) StringUtils(org.apache.commons.lang.StringUtils) List(java.util.List) io.kamax.matrix.client._MatrixClient(io.kamax.matrix.client._MatrixClient) io.kamax.matrix.hs._MatrixRoom(io.kamax.matrix.hs._MatrixRoom) IThreePidInviteReply(io.kamax.mxisd.invitation.IThreePidInviteReply) CommandLine(org.apache.commons.cli.CommandLine) Mxisd(io.kamax.mxisd.Mxisd) IThreePidInviteReply(io.kamax.mxisd.invitation.IThreePidInviteReply) StrBuilder(org.apache.commons.lang.text.StrBuilder)

Example 4 with IThreePidInviteReply

use of io.kamax.mxisd.invitation.IThreePidInviteReply in project mxisd by kamax-io.

the class StoreInviteHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) {
    String reqContentType = getContentType(exchange).orElse("application/octet-stream");
    JsonObject invJson = new JsonObject();
    if (StringUtils.startsWith(reqContentType, "application/json")) {
        invJson = parseJsonObject(exchange);
    } else // Backward compatibility for pre-r0.1.0 implementations
    if (StringUtils.startsWith(reqContentType, "application/x-www-form-urlencoded")) {
        String body = getBodyUtf8(exchange);
        Map<String, Deque<String>> parms = QueryParameterUtils.parseQueryString(body, StandardCharsets.UTF_8.name());
        for (Map.Entry<String, Deque<String>> entry : parms.entrySet()) {
            if (entry.getValue().size() == 0) {
                return;
            }
            if (entry.getValue().size() > 1) {
                throw new BadRequestException("key " + entry.getKey() + " has more than one value");
            }
            invJson.addProperty(entry.getKey(), entry.getValue().peekFirst());
        }
    } else {
        throw new BadRequestException("Unsupported Content-Type: " + reqContentType);
    }
    Type parmType = new TypeToken<Map<String, String>>() {
    }.getType();
    Map<String, String> parameters = GsonUtil.get().fromJson(invJson, parmType);
    StoreInviteRequest inv = GsonUtil.get().fromJson(invJson, StoreInviteRequest.class);
    _MatrixID sender = MatrixID.asAcceptable(inv.getSender());
    IThreePidInvite invite = new ThreePidInvite(sender, inv.getMedium(), inv.getAddress(), inv.getRoomId(), parameters);
    IThreePidInviteReply reply = invMgr.storeInvite(invite);
    // FIXME the key info must be set by the invitation manager in the reply object!
    respondJson(exchange, new ThreePidInviteReplyIO(reply, keyMgr.getPublicKeyBase64(keyMgr.getServerSigningKey().getId()), cfg.getPublicUrl()));
}
Also used : ThreePidInvite(io.kamax.mxisd.invitation.ThreePidInvite) IThreePidInvite(io.kamax.mxisd.invitation.IThreePidInvite) JsonObject(com.google.gson.JsonObject) Type(java.lang.reflect.Type) StoreInviteRequest(io.kamax.mxisd.http.io.identity.StoreInviteRequest) ThreePidInviteReplyIO(io.kamax.mxisd.http.io.identity.ThreePidInviteReplyIO) BadRequestException(io.kamax.mxisd.exception.BadRequestException) IThreePidInvite(io.kamax.mxisd.invitation.IThreePidInvite) IThreePidInviteReply(io.kamax.mxisd.invitation.IThreePidInviteReply) Map(java.util.Map) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID)

Aggregations

IThreePidInviteReply (io.kamax.mxisd.invitation.IThreePidInviteReply)4 JsonObject (com.google.gson.JsonObject)2 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)2 IThreePidInvite (io.kamax.mxisd.invitation.IThreePidInvite)2 ThreePidInvite (io.kamax.mxisd.invitation.ThreePidInvite)2 MatrixID (io.kamax.matrix.MatrixID)1 io.kamax.matrix.client._MatrixClient (io.kamax.matrix.client._MatrixClient)1 io.kamax.matrix.hs._MatrixRoom (io.kamax.matrix.hs._MatrixRoom)1 Mxisd (io.kamax.mxisd.Mxisd)1 ThreePidInviteReplyIO (io.kamax.mxisd.controller.identity.v1.io.ThreePidInviteReplyIO)1 BadRequestException (io.kamax.mxisd.exception.BadRequestException)1 StoreInviteRequest (io.kamax.mxisd.http.io.identity.StoreInviteRequest)1 ThreePidInviteReplyIO (io.kamax.mxisd.http.io.identity.ThreePidInviteReplyIO)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CommandLine (org.apache.commons.cli.CommandLine)1 StringUtils (org.apache.commons.lang.StringUtils)1 StrBuilder (org.apache.commons.lang.text.StrBuilder)1