Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / auth / AuthAuthorizeHandler.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2009-2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #include "AuthAuthorizeHandler.h"
16 #include "cephx/CephxAuthorizeHandler.h"
17 #include "none/AuthNoneAuthorizeHandler.h"
18 #include "common/Mutex.h"
19
20 AuthAuthorizeHandler *AuthAuthorizeHandlerRegistry::get_handler(int protocol)
21 {
22   if (!supported.is_supported_auth(protocol)) {
23     return NULL;
24   }
25   
26   Mutex::Locker l(m_lock);
27   map<int,AuthAuthorizeHandler*>::iterator iter = m_authorizers.find(protocol);
28   if (iter != m_authorizers.end())
29     return iter->second;
30
31   switch (protocol) {
32   case CEPH_AUTH_NONE:
33     m_authorizers[protocol] = new AuthNoneAuthorizeHandler();
34     return m_authorizers[protocol];
35     
36   case CEPH_AUTH_CEPHX:
37     m_authorizers[protocol] = new CephxAuthorizeHandler();
38     return m_authorizers[protocol];
39   }
40   return NULL;
41 }
42
43 AuthAuthorizeHandlerRegistry::~AuthAuthorizeHandlerRegistry()
44 {
45   for (map<int,AuthAuthorizeHandler*>::iterator iter = m_authorizers.begin();
46        iter != m_authorizers.end();
47        ++iter)
48     delete iter->second;
49 }