mirror of https://gitee.com/bigwinds/arangodb
223 lines
7.6 KiB
C++
223 lines
7.6 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief role of a user
|
|
///
|
|
/// @file
|
|
///
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// @author Dr. Frank Celler
|
|
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "Role.h"
|
|
|
|
#include "Logger/Logger.h"
|
|
#include "Basics/Mutex.h"
|
|
#include "Basics/MutexLocker.h"
|
|
|
|
using namespace std;
|
|
using namespace triagens::basics;
|
|
using namespace triagens::admin;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- private variables
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup RestServer
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief mutex for registry
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static Mutex RoleLock;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief registry
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static map<string, Role*> RoleRegistry;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- static public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup RestServer
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief creates a new role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Role* Role::create (string const& name, right_t manage) {
|
|
MUTEX_LOCKER(RoleLock);
|
|
|
|
map<string, Role*>::const_iterator i = RoleRegistry.find(name);
|
|
|
|
if (i != RoleRegistry.end()) {
|
|
LOGGER_DEBUG << "user '" << name << "' already exists";
|
|
return 0;
|
|
}
|
|
|
|
Role* user = new Role(name, manage);
|
|
|
|
RoleRegistry[name] = user;
|
|
|
|
return user;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns a role by name
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Role* Role::lookup (string const& name) {
|
|
MUTEX_LOCKER(RoleLock);
|
|
|
|
map<string, Role*>::const_iterator i = RoleRegistry.find(name);
|
|
|
|
if (i == RoleRegistry.end()) {
|
|
return 0;
|
|
}
|
|
else {
|
|
return i->second;
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief clear all roles
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void Role::unloadRoles () {
|
|
MUTEX_LOCKER(RoleLock);
|
|
|
|
for (map<string, Role*>::const_iterator i = RoleRegistry.begin(); i != RoleRegistry.end(); ++i) {
|
|
delete i->second;
|
|
}
|
|
|
|
RoleRegistry.clear();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- constructors and destructors
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup RestServer
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief constructor
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Role::Role (string const& name, right_t manage)
|
|
: _name(name), _rightToManage(manage) {
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- public methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup RestServer
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the name of a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
string const& Role::getName () const {
|
|
return _name;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the rights of a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
set<right_t> const& Role::getRights () const {
|
|
return _rights;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief adds a right to a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void Role::addRight (right_t right) {
|
|
_rights.insert(right);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief sets the rights of a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void Role::setRights (vector<right_t> const& rights) {
|
|
_rights.clear();
|
|
_rights.insert(rights.begin(), rights.end());
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief removes a right from a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void Role::removeRight (right_t right) {
|
|
_rights.erase(right);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief clears all rights of a role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void Role::clearRights () {
|
|
_rights.clear();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns right required to manage this role
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
right_t Role::rightToManage () const {
|
|
return _rightToManage;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
|
// End:
|