diff options
Diffstat (limited to 'src/mongo/db/auth/action_set.cpp')
-rw-r--r-- | src/mongo/db/auth/action_set.cpp | 175 |
1 files changed, 87 insertions, 88 deletions
diff --git a/src/mongo/db/auth/action_set.cpp b/src/mongo/db/auth/action_set.cpp index 85bcc079814..6f89222679b 100644 --- a/src/mongo/db/auth/action_set.cpp +++ b/src/mongo/db/auth/action_set.cpp @@ -41,110 +41,109 @@ namespace mongo { - void ActionSet::addAction(const ActionType& action) { - if (action == ActionType::anyAction) { - addAllActions(); - return; - } - _actions.set(action.getIdentifier(), true); +void ActionSet::addAction(const ActionType& action) { + if (action == ActionType::anyAction) { + addAllActions(); + return; } + _actions.set(action.getIdentifier(), true); +} - void ActionSet::addAllActionsFromSet(const ActionSet& actions) { - if (actions.contains(ActionType::anyAction)) { - addAllActions(); - return; - } - _actions |= actions._actions; +void ActionSet::addAllActionsFromSet(const ActionSet& actions) { + if (actions.contains(ActionType::anyAction)) { + addAllActions(); + return; } + _actions |= actions._actions; +} - void ActionSet::addAllActions() { - _actions = ~std::bitset<ActionType::NUM_ACTION_TYPES>(); - } +void ActionSet::addAllActions() { + _actions = ~std::bitset<ActionType::NUM_ACTION_TYPES>(); +} + +void ActionSet::removeAction(const ActionType& action) { + _actions.set(action.getIdentifier(), false); + _actions.set(ActionType::anyAction.getIdentifier(), false); +} - void ActionSet::removeAction(const ActionType& action) { - _actions.set(action.getIdentifier(), false); +void ActionSet::removeAllActionsFromSet(const ActionSet& other) { + _actions &= ~other._actions; + if (!other.empty()) { _actions.set(ActionType::anyAction.getIdentifier(), false); } - - void ActionSet::removeAllActionsFromSet(const ActionSet& other) { - _actions &= ~other._actions; - if (!other.empty()) { - _actions.set(ActionType::anyAction.getIdentifier(), false); +} + +void ActionSet::removeAllActions() { + _actions = std::bitset<ActionType::NUM_ACTION_TYPES>(); +} + +bool ActionSet::contains(const ActionType& action) const { + return _actions[action.getIdentifier()]; +} + +bool ActionSet::isSupersetOf(const ActionSet& other) const { + return (_actions & other._actions) == other._actions; +} + +Status ActionSet::parseActionSetFromString(const std::string& actionsString, ActionSet* result) { + std::vector<std::string> actionsList; + splitStringDelim(actionsString, &actionsList, ','); + return parseActionSetFromStringVector(actionsList, result); +} + +Status ActionSet::parseActionSetFromStringVector(const std::vector<std::string>& actionsVector, + ActionSet* result) { + ActionSet actions; + for (size_t i = 0; i < actionsVector.size(); i++) { + ActionType action; + Status status = ActionType::parseActionFromString(actionsVector[i], &action); + if (status != Status::OK()) { + ActionSet empty; + *result = empty; + return status; } + if (action == ActionType::anyAction) { + actions.addAllActions(); + break; + } + actions.addAction(action); } + *result = actions; + return Status::OK(); +} - void ActionSet::removeAllActions() { - _actions = std::bitset<ActionType::NUM_ACTION_TYPES>(); - } - - bool ActionSet::contains(const ActionType& action) const { - return _actions[action.getIdentifier()]; - } - - bool ActionSet::isSupersetOf(const ActionSet& other) const { - return (_actions & other._actions) == other._actions; - } - - Status ActionSet::parseActionSetFromString(const std::string& actionsString, - ActionSet* result) { - std::vector<std::string> actionsList; - splitStringDelim(actionsString, &actionsList, ','); - return parseActionSetFromStringVector(actionsList, result); +std::string ActionSet::toString() const { + if (contains(ActionType::anyAction)) { + return ActionType::anyAction.toString(); } - - Status ActionSet::parseActionSetFromStringVector(const std::vector<std::string>& actionsVector, - ActionSet* result) { - ActionSet actions; - for (size_t i = 0; i < actionsVector.size(); i++) { - ActionType action; - Status status = ActionType::parseActionFromString(actionsVector[i], &action); - if (status != Status::OK()) { - ActionSet empty; - *result = empty; - return status; + StringBuilder str; + bool addedOne = false; + for (int i = 0; i < ActionType::actionTypeEndValue; i++) { + ActionType action(i); + if (contains(action)) { + if (addedOne) { + str << ","; } - if (action == ActionType::anyAction) { - actions.addAllActions(); - break; - } - actions.addAction(action); + str << ActionType::actionToString(action); + addedOne = true; } - *result = actions; - return Status::OK(); } + return str.str(); +} - std::string ActionSet::toString() const { - if (contains(ActionType::anyAction)) { - return ActionType::anyAction.toString(); - } - StringBuilder str; - bool addedOne = false; - for (int i = 0; i < ActionType::actionTypeEndValue; i++) { - ActionType action(i); - if (contains(action)) { - if (addedOne) { - str << ","; - } - str << ActionType::actionToString(action); - addedOne = true; - } - } - return str.str(); +std::vector<std::string> ActionSet::getActionsAsStrings() const { + std::vector<std::string> result; + if (contains(ActionType::anyAction)) { + result.push_back(ActionType::anyAction.toString()); + return result; } - - std::vector<std::string> ActionSet::getActionsAsStrings() const { - std::vector<std::string> result; - if (contains(ActionType::anyAction)) { - result.push_back(ActionType::anyAction.toString()); - return result; + for (int i = 0; i < ActionType::actionTypeEndValue; i++) { + ActionType action(i); + if (contains(action)) { + result.push_back(ActionType::actionToString(action)); } - for (int i = 0; i < ActionType::actionTypeEndValue; i++) { - ActionType action(i); - if (contains(action)) { - result.push_back(ActionType::actionToString(action)); - } - } - return result; } + return result; +} -} // namespace mongo +} // namespace mongo |