diff options
Diffstat (limited to 'src/mongo/db/auth/action_set.h')
-rw-r--r-- | src/mongo/db/auth/action_set.h | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/src/mongo/db/auth/action_set.h b/src/mongo/db/auth/action_set.h index 4a5c6ef45d0..339a68f019c 100644 --- a/src/mongo/db/auth/action_set.h +++ b/src/mongo/db/auth/action_set.h @@ -35,60 +35,62 @@ namespace mongo { - /* - * An ActionSet is a bitmask of ActionTypes that represents a set of actions. - * These are the actions that a Privilege can grant a user to perform on a resource. - * If the special ActionType::anyAction is granted to this set, it automatically sets all bits - * in the bitmask, indicating that it contains all possible actions. - */ - class ActionSet { - public: - - ActionSet() : _actions(0) {} - - void addAction(const ActionType& action); - void addAllActionsFromSet(const ActionSet& actionSet); - void addAllActions(); - - // Removes action from the set. Also removes the "anyAction" action, if present. - // Note: removing the "anyAction" action does *not* remove all other actions. - void removeAction(const ActionType& action); - void removeAllActionsFromSet(const ActionSet& actionSet); - void removeAllActions(); - - bool empty() const { return _actions.none(); } - - bool equals(const ActionSet& other) const { return this->_actions == other._actions; } +/* + * An ActionSet is a bitmask of ActionTypes that represents a set of actions. + * These are the actions that a Privilege can grant a user to perform on a resource. + * If the special ActionType::anyAction is granted to this set, it automatically sets all bits + * in the bitmask, indicating that it contains all possible actions. + */ +class ActionSet { +public: + ActionSet() : _actions(0) {} + + void addAction(const ActionType& action); + void addAllActionsFromSet(const ActionSet& actionSet); + void addAllActions(); + + // Removes action from the set. Also removes the "anyAction" action, if present. + // Note: removing the "anyAction" action does *not* remove all other actions. + void removeAction(const ActionType& action); + void removeAllActionsFromSet(const ActionSet& actionSet); + void removeAllActions(); + + bool empty() const { + return _actions.none(); + } - bool contains(const ActionType& action) const; + bool equals(const ActionSet& other) const { + return this->_actions == other._actions; + } - // Returns true only if this ActionSet contains all the actions present in the 'other' - // ActionSet. - bool isSupersetOf(const ActionSet& other) const; + bool contains(const ActionType& action) const; - // Returns the std::string representation of this ActionSet - std::string toString() const; + // Returns true only if this ActionSet contains all the actions present in the 'other' + // ActionSet. + bool isSupersetOf(const ActionSet& other) const; - // Returns a vector of strings representing the actions in the ActionSet. - std::vector<std::string> getActionsAsStrings() const; + // Returns the std::string representation of this ActionSet + std::string toString() const; - // Takes a comma-separated std::string of action type std::string representations and returns - // an int bitmask of the actions. - static Status parseActionSetFromString(const std::string& actionsString, ActionSet* result); + // Returns a vector of strings representing the actions in the ActionSet. + std::vector<std::string> getActionsAsStrings() const; - // Takes a vector of action type std::string representations and returns an ActionSet of the - // actions. - static Status parseActionSetFromStringVector(const std::vector<std::string>& actionsVector, - ActionSet* result); + // Takes a comma-separated std::string of action type std::string representations and returns + // an int bitmask of the actions. + static Status parseActionSetFromString(const std::string& actionsString, ActionSet* result); - private: + // Takes a vector of action type std::string representations and returns an ActionSet of the + // actions. + static Status parseActionSetFromStringVector(const std::vector<std::string>& actionsVector, + ActionSet* result); - // bitmask of actions this privilege grants - std::bitset<ActionType::NUM_ACTION_TYPES> _actions; - }; +private: + // bitmask of actions this privilege grants + std::bitset<ActionType::NUM_ACTION_TYPES> _actions; +}; - static inline bool operator==(const ActionSet& lhs, const ActionSet& rhs) { - return lhs.equals(rhs); - } +static inline bool operator==(const ActionSet& lhs, const ActionSet& rhs) { + return lhs.equals(rhs); +} -} // namespace mongo +} // namespace mongo |