diff options
author | Spencer T Brody <spencer@10gen.com> | 2012-12-21 15:56:12 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2012-12-21 17:50:50 -0500 |
commit | 377ef5136dff3fc340df312f0c422f96d8256802 (patch) | |
tree | 8c075e740cea75bb3b66665490d9d3245c871151 /src/mongo/db/introspect.cpp | |
parent | 6f02ce4f3e8ec16f3d6ae636d8f25a9368f4257d (diff) | |
download | mongo-377ef5136dff3fc340df312f0c422f96d8256802.tar.gz |
SERVER-7572 Make profiler record user names from AuthorizationManager
Diffstat (limited to 'src/mongo/db/introspect.cpp')
-rw-r--r-- | src/mongo/db/introspect.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index 56b281384a6..6029281d0c0 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -19,6 +19,8 @@ #include "mongo/pch.h" #include "mongo/bson/util/builder.h" +#include "mongo/db/auth/authorization_manager.h" +#include "mongo/db/auth/principal_set.h" #include "mongo/db/curop.h" #include "mongo/db/databaseholder.h" #include "mongo/db/introspect.h" @@ -32,6 +34,19 @@ namespace { namespace mongo { +namespace { + void _appendUserInfo(BSONObjBuilder& builder, AuthorizationManager* authManager) { + PrincipalSet::NameIterator nameIter = authManager->getAuthenticatedPrincipalNames(); + + builder.append("user", nameIter.more() ? nameIter->getFullName() : ""); + BSONArrayBuilder allUsers(builder.subarrayStart("allUsers")); + for ( ; nameIter.more(); nameIter.next()) { + allUsers.append(nameIter->getFullName()); + } + allUsers.doneFast(); + } +} // namespace + static void _profile(const Client& c, CurOp& currentOp, BufBuilder& profileBufBuilder) { Database *db = c.database(); DEV verify( db ); @@ -46,9 +61,8 @@ namespace mongo { b.appendDate("ts", jsTime()); b.append("client", c.clientAddress()); - if (c.getAuthenticationInfo()) { - b.append("user", c.getAuthenticationInfo()->getUser(nsToDatabase(ns))); - } + AuthorizationManager* authManager = c.getAuthorizationManager(); + _appendUserInfo(b, authManager); BSONObj p = b.done(); @@ -61,8 +75,7 @@ namespace mongo { BSONObjBuilder b(profileBufBuilder); b.appendDate("ts", jsTime()); b.append("client", c.clientAddress() ); - if ( c.getAuthenticationInfo() ) - b.append( "user" , c.getAuthenticationInfo()->getUser( nsToDatabase( ns ) ) ); + _appendUserInfo(b, authManager); b.append("err", "profile line too large (max is 100KB)"); |