2
* Copyright (C) 2012 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/db/auth/auth_external_state_s.h"
21
#include "mongo/base/status.h"
22
#include "mongo/client/dbclientinterface.h"
23
#include "mongo/db/auth/authorization_manager.h"
24
#include "mongo/db/jsobj.h"
25
#include "mongo/s/grid.h"
29
AuthExternalStateMongos::AuthExternalStateMongos() {}
30
AuthExternalStateMongos::~AuthExternalStateMongos() {}
32
void AuthExternalStateMongos::startRequest() {
33
_checkShouldAllowLocalhost();
37
ScopedDbConnection* getConnectionForUsersCollection(const std::string& ns) {
39
// Note: The connection mechanism here is *not* ideal, and should not be used elsewhere.
40
// If the primary for the collection moves, this approach may throw rather than handle
41
// version exceptions.
44
DBConfigPtr config = grid.getDBConfig(ns);
45
Shard s = config->getShard(ns);
47
return ScopedDbConnection::getInternalScopedDbConnection(s.getConnString(), 30.0);
51
bool AuthExternalStateMongos::_findUser(const string& usersNamespace,
53
BSONObj* result) const {
54
scoped_ptr<ScopedDbConnection> conn(getConnectionForUsersCollection(usersNamespace));
55
*result = conn->get()->findOne(usersNamespace, query).getOwned();
57
return !result->isEmpty();