Search in sources :

Example 1 with ThreePidInvite

use of io.kamax.mxisd.invitation.ThreePidInvite 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 2 with ThreePidInvite

use of io.kamax.mxisd.invitation.ThreePidInvite 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)

Example 3 with ThreePidInvite

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

the class EmailNotificationTest method forThreepidInvite.

@Test
public void forThreepidInvite() throws MessagingException, IOException {
    String registerUrl = "https://" + RandomStringUtils.randomAlphanumeric(20) + ".example.org/register";
    gm.setUser(user, user);
    _MatrixID sender = MatrixID.asAcceptable(user, domain);
    ThreePidInvite inv = new ThreePidInvite(sender, ThreePidMedium.Email.getId(), target, "!rid:" + domain);
    inv.getProperties().put(PlaceholderNotificationGenerator.RegisterUrl, registerUrl);
    m.getNotif().sendForReply(new ThreePidInviteReply("a", inv, "b", "c", new ArrayList<>()));
    assertEquals(1, gm.getReceivedMessages().length);
    MimeMessage msg = gm.getReceivedMessages()[0];
    assertEquals(1, msg.getFrom().length);
    assertEquals(senderNameEncoded, msg.getFrom()[0].toString());
    assertEquals(1, msg.getRecipients(Message.RecipientType.TO).length);
    // We just check on the text/plain one. HTML is multipart and it's difficult so we skip
    MimeMultipart content = (MimeMultipart) msg.getContent();
    MimeBodyPart mbp = (MimeBodyPart) content.getBodyPart(0);
    String mbpContent = mbp.getContent().toString();
    assertTrue(mbpContent.contains(registerUrl));
}
Also used : ThreePidInvite(io.kamax.mxisd.invitation.ThreePidInvite) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID) ThreePidInviteReply(io.kamax.mxisd.invitation.ThreePidInviteReply) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

ThreePidInvite (io.kamax.mxisd.invitation.ThreePidInvite)3 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)2 IThreePidInvite (io.kamax.mxisd.invitation.IThreePidInvite)2 IThreePidInviteReply (io.kamax.mxisd.invitation.IThreePidInviteReply)2 JsonObject (com.google.gson.JsonObject)1 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 MatrixID (io.kamax.matrix.MatrixID)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 ThreePidInviteReply (io.kamax.mxisd.invitation.ThreePidInviteReply)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 Test (org.junit.Test)1