summaryrefslogtreecommitdiff
path: root/src/mongo/db/sessions_collection_mock.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2017-07-21 11:54:18 -0400
committerJason Carey <jcarey@argv.me>2017-07-26 15:53:42 -0400
commitedfe3f3b1276ef3598b1af673d088e6b5c4b3ad5 (patch)
tree08f0efcdb6100dc315cf5e9ac98c0c6261be928d /src/mongo/db/sessions_collection_mock.cpp
parentcb36a96d7c96cf1b24c7ef3b8b086cfc04c77642 (diff)
downloadmongo-edfe3f3b1276ef3598b1af673d088e6b5c4b3ad5.tar.gz
SERVER-30298 Add UserDigest LogicalSessionID
Inclusion of a sha256 digest of the full username to the logical session id (in addition to the current guid) is necessary to fully disambiguate logical sessions in degraded clusters (when the authoritative record for a session is unreachable). Semantics for the uid are as follows: session creation via startSession() * Sessions can only be created with one, and only one, user authenticated * The composite key is created from a guid created on the spot, as well as the digest of the currently auth'd username * Only the session guid is returned to the user * This prevents outside users from attempting to send back a value we'd have to check. It's preferable to decorate the guid with the user digest per command, rather than having to check a value the user might send. session use for a command * Sessions are passed via the lsid top level field in any command * Sessions are only meaningful for commands which requireAuth. For sessions which don't require auth, we strip session information from the command at parse time * Session ids are passed as an object, which can optionally include the username digest * It is illegal to pass the username digest unless the currently auth'd user has the impersonate privilege (the __system user does). This enables sessions on shard servers via mongos
Diffstat (limited to 'src/mongo/db/sessions_collection_mock.cpp')
-rw-r--r--src/mongo/db/sessions_collection_mock.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/mongo/db/sessions_collection_mock.cpp b/src/mongo/db/sessions_collection_mock.cpp
index 1079605badd..832213e1223 100644
--- a/src/mongo/db/sessions_collection_mock.cpp
+++ b/src/mongo/db/sessions_collection_mock.cpp
@@ -65,8 +65,7 @@ void MockSessionsCollectionImpl::clearHooks() {
_remove = stdx::bind(&MockSessionsCollectionImpl::_removeRecords, this, stdx::placeholders::_1);
}
-StatusWith<LogicalSessionRecord> MockSessionsCollectionImpl::fetchRecord(
- SignedLogicalSessionId id) {
+StatusWith<LogicalSessionRecord> MockSessionsCollectionImpl::fetchRecord(LogicalSessionId id) {
return _fetch(std::move(id));
}
@@ -84,7 +83,7 @@ void MockSessionsCollectionImpl::removeRecords(LogicalSessionIdSet sessions) {
void MockSessionsCollectionImpl::add(LogicalSessionRecord record) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
- _sessions.insert({record.getSignedLsid().getLsid(), std::move(record)});
+ _sessions.insert({record.getId(), std::move(record)});
}
void MockSessionsCollectionImpl::remove(LogicalSessionId lsid) {
@@ -106,12 +105,11 @@ const MockSessionsCollectionImpl::SessionMap& MockSessionsCollectionImpl::sessio
return _sessions;
}
-StatusWith<LogicalSessionRecord> MockSessionsCollectionImpl::_fetchRecord(
- SignedLogicalSessionId id) {
+StatusWith<LogicalSessionRecord> MockSessionsCollectionImpl::_fetchRecord(LogicalSessionId id) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
// If we do not have this record, return an error
- auto it = _sessions.find(id.getLsid());
+ auto it = _sessions.find(id);
if (it == _sessions.end()) {
return {ErrorCodes::NoSuchSession, "No matching record in the sessions collection"};
}
@@ -121,7 +119,7 @@ StatusWith<LogicalSessionRecord> MockSessionsCollectionImpl::_fetchRecord(
Status MockSessionsCollectionImpl::_insertRecord(LogicalSessionRecord record) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
- auto res = _sessions.insert({record.getSignedLsid().getLsid(), std::move(record)});
+ auto res = _sessions.insert({record.getId(), std::move(record)});
// We should never try to insert the same record twice. In theory this could
// happen because of a UUID conflict.