void decode_json(JSONObj *access_obj);
};
+
class RGWKeystoneTokenCache {
struct token_entry {
KeystoneToken token;
list<string>::iterator lru_iter;
};
- CephContext *cct;
+ CephContext * const cct;
string admin_token_id;
map<string, token_entry> tokens;
Mutex lock;
- size_t max;
+ const size_t max;
-public:
- RGWKeystoneTokenCache(CephContext *_cct, int _max)
- : cct(_cct),
+ RGWKeystoneTokenCache()
+ : cct(g_ceph_context),
lock("RGWKeystoneTokenCache", true /* recursive */),
- max(_max) {
+ max(cct->_conf->rgw_keystone_token_cache_size) {
}
+public:
+ RGWKeystoneTokenCache(const RGWKeystoneTokenCache&) = delete;
+ void operator=(const RGWKeystoneTokenCache&) = delete;
+
+ static RGWKeystoneTokenCache& get_instance();
bool find(const string& token_id, KeystoneToken& token);
bool find_admin(KeystoneToken& token);
void invalidate(const string& token_id);
};
+
class KeystoneAdminTokenRequest {
public:
virtual ~KeystoneAdminTokenRequest() = default;
typedef RGWKeystoneHTTPTransceiver RGWGetKeystoneAdminToken;
typedef RGWKeystoneHTTPTransceiver RGWGetRevokedTokens;
-static RGWKeystoneTokenCache *keystone_token_cache = NULL;
-
int RGWSwift::get_keystone_url(CephContext * const cct,
std::string& url)
{
KeystoneToken t;
/* Try cache first. */
- if (keystone_token_cache->find_admin(t)) {
+ if (RGWKeystoneTokenCache::get_instance().find_admin(t)) {
ldout(cct, 20) << "found cached admin token" << dendl;
token = t.token.id;
return 0;
return -EINVAL;
}
- keystone_token_cache->add_admin(t);
+ RGWKeystoneTokenCache::get_instance().add_admin(t);
token = t.token.id;
return 0;
}
}
string token_id = token->get_data();
- keystone_token_cache->invalidate(token_id);
+ RGWKeystoneTokenCache::get_instance().invalidate(token_id);
}
return 0;
ldout(cct, 20) << "token_id=" << token_id << dendl;
/* check cache first */
- if (keystone_token_cache->find(token_id, t)) {
+ if (RGWKeystoneTokenCache::get_instance().find(token_id, t)) {
rgw_set_keystone_token_auth_info(t, &info);
ldout(cct, 20) << "cached token.project.id=" << t.get_project_id() << dendl;
return -EPERM;
}
- keystone_token_cache->add(token_id, t);
+ RGWKeystoneTokenCache::get_instance().add(token_id, t);
ret = update_user_info(store, &info, rgw_user);
if (ret < 0)
void RGWSwift::init_keystone()
{
- keystone_token_cache = new RGWKeystoneTokenCache(cct, cct->_conf->rgw_keystone_token_cache_size);
-
keystone_revoke_thread = new KeystoneRevokeThread(cct, this);
keystone_revoke_thread->create("rgw_swift_k_rev");
}
void RGWSwift::finalize_keystone()
{
- delete keystone_token_cache;
- keystone_token_cache = NULL;
-
down_flag.set(1);
if (keystone_revoke_thread) {
keystone_revoke_thread->stop();