Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

mod_token_verification.lua 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local log = module._log;
  4. local host = module.host;
  5. local st = require "util.stanza";
  6. local is_admin = require "core.usermanager".is_admin;
  7. local parentHostName = string.gmatch(tostring(host), "%w+.(%w.+)")();
  8. if parentHostName == nil then
  9. log("error", "Failed to start - unable to get parent hostname");
  10. return;
  11. end
  12. local parentCtx = module:context(parentHostName);
  13. if parentCtx == nil then
  14. log("error",
  15. "Failed to start - unable to get parent context for host: %s",
  16. tostring(parentHostName));
  17. return;
  18. end
  19. local token_util = module:require "token/util".new(parentCtx);
  20. -- no token configuration
  21. if token_util == nil then
  22. return;
  23. end
  24. log("debug",
  25. "%s - starting MUC token verifier app_id: %s app_secret: %s allow empty: %s",
  26. tostring(host), tostring(token_util.appId), tostring(token_util.appSecret),
  27. tostring(token_util.allowEmptyToken));
  28. local function verify_user(session, stanza)
  29. log("debug", "Session token: %s, session room: %s",
  30. tostring(session.auth_token),
  31. tostring(session.jitsi_meet_room));
  32. -- token not required for admin users
  33. local user_jid = stanza.attr.from;
  34. if is_admin(user_jid) then
  35. log("debug", "Token not required from admin user: %s", user_jid);
  36. return nil;
  37. end
  38. log("debug",
  39. "Will verify token for user: %s, room: %s ", user_jid, stanza.attr.to);
  40. if not token_util:verify_room(session, stanza.attr.to) then
  41. log("error", "Token %s not allowed to join: %s",
  42. tostring(session.auth_token), tostring(stanza.attr.to));
  43. session.send(
  44. st.error_reply(
  45. stanza, "cancel", "not-allowed", "Room and token mismatched"));
  46. return false; -- we need to just return non nil
  47. end
  48. log("debug",
  49. "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to);
  50. end
  51. module:hook("muc-room-pre-create", function(event)
  52. local origin, stanza = event.origin, event.stanza;
  53. log("debug", "pre create: %s %s", tostring(origin), tostring(stanza));
  54. return verify_user(origin, stanza);
  55. end);
  56. module:hook("muc-occupant-pre-join", function(event)
  57. local origin, room, stanza = event.origin, event.room, event.stanza;
  58. log("debug", "pre join: %s %s", tostring(room), tostring(stanza));
  59. return verify_user(origin, stanza);
  60. end);