diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2017-07-12 10:54:32 -0400 |
---|---|---|
committer | Spencer Jackson <spencer.jackson@mongodb.com> | 2017-07-14 19:21:13 -0400 |
commit | ebd0ca53d1de618911be6e6eea6f3380c44517f5 (patch) | |
tree | 675a8b0cceea8d4ae43ac254d410b36859b4c126 /src/mongo/db/auth/address_restriction.cpp | |
parent | 1622c6b7a7971ea7fbdd4b3d5b10455e48e5cf69 (diff) | |
download | mongo-ebd0ca53d1de618911be6e6eea6f3380c44517f5.tar.gz |
SERVER-29173: Parse authentication restrictions from user documents
Diffstat (limited to 'src/mongo/db/auth/address_restriction.cpp')
-rw-r--r-- | src/mongo/db/auth/address_restriction.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/db/auth/address_restriction.cpp b/src/mongo/db/auth/address_restriction.cpp index 8b2de7770bd..e0417749097 100644 --- a/src/mongo/db/auth/address_restriction.cpp +++ b/src/mongo/db/auth/address_restriction.cpp @@ -62,3 +62,32 @@ mongo::StatusWith<mongo::RestrictionSet<>> mongo::parseAddressRestrictionSet( } catch (const DBException& e) { return Status(ErrorCodes::BadValue, e.what()); } + +mongo::StatusWith<mongo::SharedRestrictionDocument> mongo::parseAuthenticationRestriction( + const BSONArray& arr) { + static_assert( + std::is_same<std::shared_ptr<RestrictionDocument<>>, SharedRestrictionDocument>::value, + "SharedRestrictionDocument expected to be a shared_ptr to a RestrictionDocument<>"); + using document_type = SharedRestrictionDocument::element_type; + static_assert(std::is_same<document_type::pointer_type, + std::unique_ptr<document_type::element_type>>::value, + "SharedRestrictionDocument expected to contain a sequence of unique_ptrs"); + + document_type::sequence_type doc; + for (const auto& elem : arr) { + if (elem.type() != Object) { + return Status(ErrorCodes::UnsupportedFormat, + "restriction array sub-documents must be address restriction objects"); + } + + auto restriction = parseAddressRestrictionSet(elem.Obj()); + if (!restriction.isOK()) { + return restriction.getStatus(); + } + + doc.emplace_back( + stdx::make_unique<document_type::element_type>(std::move(restriction.getValue()))); + } + + return std::make_shared<document_type>(std::move(doc)); +} |