diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/auth/user.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/auth/user.cpp')
-rw-r--r-- | src/mongo/db/auth/user.cpp | 228 |
1 files changed, 112 insertions, 116 deletions
diff --git a/src/mongo/db/auth/user.cpp b/src/mongo/db/auth/user.cpp index a2afa97a4e3..dd4dd3196a9 100644 --- a/src/mongo/db/auth/user.cpp +++ b/src/mongo/db/auth/user.cpp @@ -41,123 +41,119 @@ namespace mongo { - User::User(const UserName& name) : - _name(name), - _refCount(0), - _isValid(1) {} +User::User(const UserName& name) : _name(name), _refCount(0), _isValid(1) {} - User::~User() { - dassert(_refCount == 0); - } - - const UserName& User::getName() const { - return _name; - } - - RoleNameIterator User::getRoles() const { - return makeRoleNameIteratorForContainer(_roles); - } - - RoleNameIterator User::getIndirectRoles() const { - return makeRoleNameIteratorForContainer(_indirectRoles); - } - - bool User::hasRole(const RoleName& roleName) const { - return _roles.count(roleName); - } - - const User::CredentialData& User::getCredentials() const { - return _credentials; - } - - bool User::isValid() const { - return _isValid.loadRelaxed() == 1; - } - - uint32_t User::getRefCount() const { - return _refCount; - } - - const ActionSet User::getActionsForResource(const ResourcePattern& resource) const { - unordered_map<ResourcePattern, Privilege>::const_iterator it = _privileges.find(resource); - if (it == _privileges.end()) { - return ActionSet(); - } - return it->second.getActions(); - } - - User* User::clone() const { - std::unique_ptr<User> result(new User(_name)); - result->_privileges = _privileges; - result->_roles = _roles; - result->_credentials = _credentials; - return result.release(); - } +User::~User() { + dassert(_refCount == 0); +} - void User::setCredentials(const CredentialData& credentials) { - _credentials = credentials; - } - - void User::setRoles(RoleNameIterator roles) { - _roles.clear(); - while (roles.more()) { - _roles.insert(roles.next()); - } - } - - void User::setIndirectRoles(RoleNameIterator indirectRoles) { - _indirectRoles.clear(); - while (indirectRoles.more()) { - _indirectRoles.push_back(indirectRoles.next()); - } - } +const UserName& User::getName() const { + return _name; +} - void User::setPrivileges(const PrivilegeVector& privileges) { - _privileges.clear(); - for (size_t i = 0; i < privileges.size(); ++i) { - const Privilege& privilege = privileges[i]; - _privileges[privilege.getResourcePattern()] = privilege; - } - } - - void User::addRole(const RoleName& roleName) { - _roles.insert(roleName); - } - - void User::addRoles(const std::vector<RoleName>& roles) { - for (std::vector<RoleName>::const_iterator it = roles.begin(); it != roles.end(); ++it) { - addRole(*it); - } - } +RoleNameIterator User::getRoles() const { + return makeRoleNameIteratorForContainer(_roles); +} - void User::addPrivilege(const Privilege& privilegeToAdd) { - ResourcePrivilegeMap::iterator it = _privileges.find(privilegeToAdd.getResourcePattern()); - if (it == _privileges.end()) { - // No privilege exists yet for this resource - _privileges.insert(std::make_pair(privilegeToAdd.getResourcePattern(), privilegeToAdd)); - } else { - dassert(it->first == privilegeToAdd.getResourcePattern()); - it->second.addActions(privilegeToAdd.getActions()); - } - } - - void User::addPrivileges(const PrivilegeVector& privileges) { - for (PrivilegeVector::const_iterator it = privileges.begin(); - it != privileges.end(); ++it) { - addPrivilege(*it); - } - } - - void User::invalidate() { - _isValid.store(0); - } - - void User::incrementRefCount() { - ++_refCount; - } - - void User::decrementRefCount() { - dassert(_refCount > 0); - --_refCount; - } -} // namespace mongo +RoleNameIterator User::getIndirectRoles() const { + return makeRoleNameIteratorForContainer(_indirectRoles); +} + +bool User::hasRole(const RoleName& roleName) const { + return _roles.count(roleName); +} + +const User::CredentialData& User::getCredentials() const { + return _credentials; +} + +bool User::isValid() const { + return _isValid.loadRelaxed() == 1; +} + +uint32_t User::getRefCount() const { + return _refCount; +} + +const ActionSet User::getActionsForResource(const ResourcePattern& resource) const { + unordered_map<ResourcePattern, Privilege>::const_iterator it = _privileges.find(resource); + if (it == _privileges.end()) { + return ActionSet(); + } + return it->second.getActions(); +} + +User* User::clone() const { + std::unique_ptr<User> result(new User(_name)); + result->_privileges = _privileges; + result->_roles = _roles; + result->_credentials = _credentials; + return result.release(); +} + +void User::setCredentials(const CredentialData& credentials) { + _credentials = credentials; +} + +void User::setRoles(RoleNameIterator roles) { + _roles.clear(); + while (roles.more()) { + _roles.insert(roles.next()); + } +} + +void User::setIndirectRoles(RoleNameIterator indirectRoles) { + _indirectRoles.clear(); + while (indirectRoles.more()) { + _indirectRoles.push_back(indirectRoles.next()); + } +} + +void User::setPrivileges(const PrivilegeVector& privileges) { + _privileges.clear(); + for (size_t i = 0; i < privileges.size(); ++i) { + const Privilege& privilege = privileges[i]; + _privileges[privilege.getResourcePattern()] = privilege; + } +} + +void User::addRole(const RoleName& roleName) { + _roles.insert(roleName); +} + +void User::addRoles(const std::vector<RoleName>& roles) { + for (std::vector<RoleName>::const_iterator it = roles.begin(); it != roles.end(); ++it) { + addRole(*it); + } +} + +void User::addPrivilege(const Privilege& privilegeToAdd) { + ResourcePrivilegeMap::iterator it = _privileges.find(privilegeToAdd.getResourcePattern()); + if (it == _privileges.end()) { + // No privilege exists yet for this resource + _privileges.insert(std::make_pair(privilegeToAdd.getResourcePattern(), privilegeToAdd)); + } else { + dassert(it->first == privilegeToAdd.getResourcePattern()); + it->second.addActions(privilegeToAdd.getActions()); + } +} + +void User::addPrivileges(const PrivilegeVector& privileges) { + for (PrivilegeVector::const_iterator it = privileges.begin(); it != privileges.end(); ++it) { + addPrivilege(*it); + } +} + +void User::invalidate() { + _isValid.store(0); +} + +void User::incrementRefCount() { + ++_refCount; +} + +void User::decrementRefCount() { + dassert(_refCount > 0); + --_refCount; +} +} // namespace mongo |