Mongodb user with no auth enable
@amichelo reported that when connect with an username/password pair to a Mongodb instance that doesn't have the authentication enabled, the first connection goes wrong(right) with authentication failure the subsequent call to database are done without using username and password. this should not be occurs due to code below:
MongoAuthHook::MongoAuthHook(std::map<std::string,std::string>& key_value_custom_param):
has_autentication(false) {
if(key_value_custom_param.count("user")) {
user = key_value_custom_param["user"];
}
if(key_value_custom_param.count("pwd")){
pwd = key_value_custom_param["pwd"];
}
if(key_value_custom_param.count("db")) {
db = key_value_custom_param["db"];
}
has_autentication = key_value_custom_param.count("user") || key_value_custom_param.count("pwd");
}
void MongoAuthHook::onCreate( mongo::DBClientBase * conn ) {
std::string err;
if(has_autentication){
MDBHAC_LDBG_ << "Autenticate on - " << conn->getServerAddress();
if(!conn->auth(db, user, pwd, err, true)) {
MDBHAC_LERR_ << conn->getServerAddress() << " -> " << err << " user:" << user << " pwd:" <<pwd;
}
} else {
MDBHAC_LDBG_ << "No Autenticate on - " << conn->getServerAddress();
}
}
The has_autentication
variable should not became false...