|
14 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | */ |
16 | 16 |
|
17 | | -#include "mongo/db/auth/auth_external_state_impl.h" |
| 17 | +#include "mongo/db/auth/auth_external_state.h" |
18 | 18 |
|
19 | | -#include "mongo/base/status.h" |
20 | | -#include "mongo/client/dbclientinterface.h" |
21 | 19 | #include "mongo/db/auth/authorization_manager.h" |
22 | | -#include "mongo/db/client.h" |
23 | | -#include "mongo/util/debug_util.h" |
24 | 20 |
|
25 | 21 | namespace mongo { |
26 | 22 |
|
27 | | - Status AuthExternalStateImpl::initialize(DBClientBase* adminDBConnection) { |
28 | | - if (noauth) { |
| 23 | + AuthExternalState::AuthExternalState() {} |
| 24 | + AuthExternalState::~AuthExternalState() {} |
| 25 | + |
| 26 | + Status AuthExternalState::getPrivilegeDocumentOverConnection(DBClientBase* conn, |
| 27 | + const std::string& dbname, |
| 28 | + const std::string& principalName, |
| 29 | + BSONObj* result) { |
| 30 | + if (principalName == internalSecurity.user) { |
| 31 | + if (internalSecurity.pwd.empty()) { |
| 32 | + return Status(ErrorCodes::UserNotFound, |
| 33 | + "key file must be used to log in with internal user", |
| 34 | + 15889); |
| 35 | + } |
| 36 | + *result = BSON("user" << principalName << "pwd" << internalSecurity.pwd).getOwned(); |
29 | 37 | return Status::OK(); |
30 | 38 | } |
31 | 39 |
|
32 | | - try { |
33 | | - _adminUserExists = AuthorizationManager::hasPrivilegeDocument(adminDBConnection, |
34 | | - "admin"); |
35 | | - } catch (DBException& e) { |
36 | | - return Status(ErrorCodes::InternalError, |
37 | | - mongoutils::str::stream() << "An error occurred while checking for the " |
38 | | - "existence of an admin user: " << e.what(), |
| 40 | + std::string usersNamespace = dbname + ".system.users"; |
| 41 | + |
| 42 | + BSONObj userBSONObj; |
| 43 | + BSONObj query = BSON("user" << principalName); |
| 44 | + userBSONObj = conn->findOne(usersNamespace, query, 0, QueryOption_SlaveOk); |
| 45 | + if (userBSONObj.isEmpty()) { |
| 46 | + return Status(ErrorCodes::UserNotFound, |
| 47 | + mongoutils::str::stream() << "auth: couldn't find user " << principalName |
| 48 | + << ", " << usersNamespace, |
39 | 49 | 0); |
40 | 50 | } |
41 | | - ONCE { |
42 | | - if (!_adminUserExists) { |
43 | | - log() << "note: no users configured in admin.system.users, allowing localhost access" |
44 | | - << endl; |
45 | | - } |
46 | | - } |
47 | | - return Status::OK(); |
48 | | - } |
49 | 51 |
|
50 | | - bool AuthExternalStateImpl::shouldIgnoreAuthChecks() const { |
51 | | - return noauth || (!_adminUserExists && cc().getIsLocalHostConnection()) || cc().isGod(); |
| 52 | + *result = userBSONObj.getOwned(); |
| 53 | + return Status::OK(); |
52 | 54 | } |
53 | 55 |
|
54 | | -} // namespace mongo |
| 56 | +} // namespace mongo |
0 commit comments