Browse Source

Merge pull request #7481 from jitsi/aaronkvanmeerten/token-util-cache-in-object

FEAT: jwt pubkey cache inside object
master
Aaron van Meerten 5 years ago
parent
commit
21767fa7cf
No account linked to committer's email address
1 changed files with 11 additions and 4 deletions
  1. 11
    4
      resources/prosody-plugins/token/util.lib.lua

+ 11
- 4
resources/prosody-plugins/token/util.lib.lua View File

@@ -19,7 +19,6 @@ local http_headers = {
19 19
 
20 20
 -- TODO: Figure out a less arbitrary default cache size.
21 21
 local cacheSize = module:get_option_number("jwt_pubkey_cache_size", 128);
22
-local cache = require"util.cache".new(cacheSize);
23 22
 
24 23
 local Util = {}
25 24
 Util.__index = Util
@@ -38,6 +37,8 @@ function Util.new(module)
38 37
     self.asapKeyServer = module:get_option_string("asap_key_server");
39 38
     self.allowEmptyToken = module:get_option_boolean("allow_empty_token");
40 39
 
40
+    self.cache = require"util.cache".new(cacheSize);
41
+
41 42
     --[[
42 43
         Multidomain can be supported in some deployments. In these deployments
43 44
         there is a virtual conference muc, which address contains the subdomain
@@ -108,7 +109,7 @@ end
108 109
 -- @param keyId the key ID to request
109 110
 -- @return the public key (the content of requested resource) or nil
110 111
 function Util:get_public_key(keyId)
111
-    local content = cache:get(keyId);
112
+    local content = self.cache:get(keyId);
112 113
     if content == nil then
113 114
         -- If the key is not found in the cache.
114 115
         module:log("debug", "Cache miss for key: "..keyId);
@@ -117,7 +118,10 @@ function Util:get_public_key(keyId)
117 118
         local function cb(content_, code_, response_, request_)
118 119
             content, code = content_, code_;
119 120
             if code == 200 or code == 204 then
120
-                cache:set(keyId, content);
121
+                self.cache:set(keyId, content);
122
+            else
123
+                module:log("warn", "Error on public key request: Code %s, Content %s",
124
+                code_, content_);
121 125
             end
122 126
             done();
123 127
         end
@@ -138,7 +142,10 @@ function Util:get_public_key(keyId)
138 142
             -- TODO: This check is racey. Not likely to be a problem, but we should
139 143
             --       still stick a mutex on content / code at some point.
140 144
             if code == nil then
141
-                http.destroy_request(request);
145
+                -- no longer present in prosody 0.11, so check before calling
146
+                if http.destroy_request ~= nil then
147
+                    http.destroy_request(request);
148
+                end
142 149
                 done();
143 150
             end
144 151
         end

Loading…
Cancel
Save