2
* Copyright (C) 2010 10gen Inc.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Affero General Public License, version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Affero General Public License for more details.
13
* You should have received a copy of the GNU Affero General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include <mongo/pch.h>
19
#include "mongo/db/auth/authorization_manager.h"
20
#include "mongo/db/commands.h"
23
class CmdConnectionStatus : public Command {
25
CmdConnectionStatus() : Command("connectionStatus") {}
26
virtual bool requiresAuth() { return false; }
27
virtual bool logTheOp() { return false; }
28
virtual bool slaveOk() const { return true; }
29
virtual LockType locktype() const { return NONE; }
30
virtual void addRequiredPrivileges(const std::string& dbname,
31
const BSONObj& cmdObj,
32
std::vector<Privilege>* out) {} // No auth required
34
void help(stringstream& h) const {
35
h << "Returns connection-specific information such as logged-in users";
38
bool run(const string&, BSONObj& cmdObj, int, string& errmsg,
39
BSONObjBuilder& result, bool fromRepl) {
40
AuthorizationManager* authMgr = ClientBasic::getCurrent()->getAuthorizationManager();
42
BSONObjBuilder authInfo(result.subobjStart("authInfo"));
44
BSONArrayBuilder authenticatedUsers(authInfo.subarrayStart("authenticatedUsers"));
46
PrincipalSet::NameIterator nameIter = authMgr->getAuthenticatedPrincipalNames();
47
for ( ; nameIter.more(); nameIter.next()) {
48
BSONObjBuilder principal(authenticatedUsers.subobjStart());
49
principal.append("user", nameIter->getUser());
50
principal.append("userSource", nameIter->getDB());
53
authenticatedUsers.doneFast();
59
} cmdConnectionStatus;