summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/action_set.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/auth/action_set.cpp')
-rw-r--r--src/mongo/db/auth/action_set.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/mongo/db/auth/action_set.cpp b/src/mongo/db/auth/action_set.cpp
index b7c17ae1996..8eff5dd74eb 100644
--- a/src/mongo/db/auth/action_set.cpp
+++ b/src/mongo/db/auth/action_set.cpp
@@ -28,10 +28,18 @@
namespace mongo {
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;
}
@@ -41,10 +49,14 @@ namespace mongo {
void ActionSet::removeAction(const ActionType& action) {
_actions.set(action.getIdentifier(), false);
+ _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() {
@@ -63,15 +75,24 @@ namespace mongo {
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 < actionsList.size(); i++) {
+ for (size_t i = 0; i < actionsVector.size(); i++) {
ActionType action;
- Status status = ActionType::parseActionFromString(actionsList[i], &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;
@@ -79,6 +100,9 @@ namespace mongo {
}
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++) {
@@ -94,4 +118,19 @@ namespace mongo {
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;
+ }
+ for (int i = 0; i < ActionType::actionTypeEndValue; i++) {
+ ActionType action(i);
+ if (contains(action)) {
+ result.push_back(ActionType::actionToString(action));
+ }
+ }
+ return result;
+ }
+
} // namespace mongo