summaryrefslogtreecommitdiffstats
path: root/keystone/token
diff options
context:
space:
mode:
authorAdam Young <ayoung@redhat.com>2012-09-06 11:54:04 -0400
committerAdam Young <ayoung@redhat.com>2012-09-06 16:33:17 -0400
commit150413cc4ba8ec854cf6fa30efeb7a653ad5e17a (patch)
tree7f2762e8e02fe45e2b2851f44bbba1788f7853cd /keystone/token
parentfd6d2f1b1184c5b8da1ded3a560ef57795863fb5 (diff)
downloadkeystone-150413cc4ba8ec854cf6fa30efeb7a653ad5e17a.tar.gz
keystone-150413cc4ba8ec854cf6fa30efeb7a653ad5e17a.tar.xz
keystone-150413cc4ba8ec854cf6fa30efeb7a653ad5e17a.zip
List tokens for memcached backend
Creates and updates an index of tokens in a memcache entry keyed by the user id Bug 1046905 Change-Id: If11d6b87b0a8ae5f8349f1ebb31790e943c70fbf
Diffstat (limited to 'keystone/token')
-rw-r--r--keystone/token/backends/memcache.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/keystone/token/backends/memcache.py b/keystone/token/backends/memcache.py
index b5cae2a0..437431bc 100644
--- a/keystone/token/backends/memcache.py
+++ b/keystone/token/backends/memcache.py
@@ -67,6 +67,15 @@ class Token(token.Driver):
expires_ts = utils.unixtime(data_copy['expires'])
kwargs['time'] = expires_ts
self.client.set(ptk, data_copy, **kwargs)
+ if 'id' in data['user']:
+ token_data = jsonutils.dumps(token_id)
+ user_id = data['user']['id']
+ user_key = 'usertokens-%s' % user_id
+ if not self.client.append(user_key, ',%s' % token_data):
+ if not self.client.add(user_key, token_data):
+ if not self.client.append(user_key, ',%s' % token_data):
+ msg = _('Unable to add token user list.')
+ raise exception.UnexpectedError(msg)
return copy.deepcopy(data_copy)
def _add_to_revocation_list(self, data):
@@ -86,6 +95,17 @@ class Token(token.Driver):
self._add_to_revocation_list(data)
return result
+ def list_tokens(self, user_id):
+ tokens = []
+ user_record = self.client.get('usertokens-%s' % user_id) or ""
+ token_list = jsonutils.loads('[%s]' % user_record)
+ for token_id in token_list:
+ ptk = self._prefix_token_id(token_id)
+ token = self.client.get(ptk)
+ if token:
+ tokens.append(token_id)
+ return tokens
+
def list_revoked_tokens(self):
list_json = self.client.get(self.revocation_key)
if list_json: