diff options
author | Andy Schwerin <schwerin@10gen.com> | 2013-10-05 12:36:03 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2013-10-05 17:39:16 -0400 |
commit | ee34eb5c05c5b8072dc1354845ed34989596456b (patch) | |
tree | 600b18fcbf22dfccf64496f5a3dc02636e56e50f /src/mongo | |
parent | 07c18d3c1147bd11ea50902542432a178f4f685f (diff) | |
download | mongo-ee34eb5c05c5b8072dc1354845ed34989596456b.tar.gz |
SERVER-10670 Add setPrivileges and setRoleData methods to User.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/auth/user.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/auth/user.h | 20 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/mongo/db/auth/user.cpp b/src/mongo/db/auth/user.cpp index 0dcc7d3ff76..03ef82bbe1b 100644 --- a/src/mongo/db/auth/user.cpp +++ b/src/mongo/db/auth/user.cpp @@ -73,6 +73,22 @@ namespace mongo { _credentials = credentials; } + void User::setRoleData(const std::vector<User::RoleData>& roles) { + _roles.clear(); + for (size_t i = 0; i < roles.size(); ++i) { + const User::RoleData& role = roles[i]; + _roles[role.name] = role; + } + } + + 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) { RoleData& role = _roles[roleName]; if (role.name.empty()) { diff --git a/src/mongo/db/auth/user.h b/src/mongo/db/auth/user.h index 24f588cd335..698583885bf 100644 --- a/src/mongo/db/auth/user.h +++ b/src/mongo/db/auth/user.h @@ -59,6 +59,7 @@ namespace mongo { name(_name), hasRole(_hasRole), canDelegate(_canDelegate) {} }; + typedef unordered_map<ResourcePattern, Privilege> ResourcePrivilegeMap; typedef unordered_map<RoleName, RoleData> RoleDataMap; explicit User(const UserName& name); @@ -70,11 +71,16 @@ namespace mongo { const UserName& getName() const; /** - * Returns an iterator that can be used to get the list of roles this user belongs to. + * Returns a reference to the information about the users' role membership. */ const RoleDataMap& getRoles() const; /** + * Returns a reference to the information about the user's privileges. + */ + const ResourcePrivilegeMap& getPrivileges() const { return _privileges; } + + /** * Returns the CredentialData for this user. */ const CredentialData& getCredentials() const; @@ -111,6 +117,16 @@ namespace mongo { void setCredentials(const CredentialData& credentials); /** + * Replaces any existing user role membership information with "roles". + */ + void setRoleData(const std::vector<RoleData>& roles); + + /** + * Replaces any existing user privilege information with "privileges". + */ + void setPrivileges(const PrivilegeVector& privileges); + + /** * Adds the given role name to the list of roles of which this user is a member. */ void addRole(const RoleName& role); @@ -170,8 +186,6 @@ namespace mongo { UserName _name; - typedef unordered_map<ResourcePattern, Privilege> ResourcePrivilegeMap; - // Maps resource name to privilege on that resource ResourcePrivilegeMap _privileges; |