From 33bcd07be56804252323bc3a5a263669dde4cb89 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 28 Dec 2022 19:02:06 +0100 Subject: [PATCH] Remove old code --- src/Bridge/IBridge.cpp | 6 -- src/Dictionaries/MongoDBDictionarySource.cpp | 4 - src/Processors/Transforms/MongoDBSource.cpp | 99 -------------------- src/Storages/StorageMongoDB.cpp | 7 +- 4 files changed, 2 insertions(+), 114 deletions(-) diff --git a/src/Bridge/IBridge.cpp b/src/Bridge/IBridge.cpp index afaaf11b26a..2d97bba6287 100644 --- a/src/Bridge/IBridge.cpp +++ b/src/Bridge/IBridge.cpp @@ -61,14 +61,8 @@ namespace Poco::Net::SocketAddress socketBindListen(Poco::Net::ServerSocket & socket, const std::string & host, UInt16 port, Poco::Logger * log) { auto address = makeSocketAddress(host, port, log); -#if POCO_VERSION < 0x01080000 - socket.bind(address, /* reuseAddress = */ true); -#else socket.bind(address, /* reuseAddress = */ true, /* reusePort = */ false); -#endif - socket.listen(/* backlog = */ 64); - return address; } } diff --git a/src/Dictionaries/MongoDBDictionarySource.cpp b/src/Dictionaries/MongoDBDictionarySource.cpp index 9c751d5ce97..c6b6a01d241 100644 --- a/src/Dictionaries/MongoDBDictionarySource.cpp +++ b/src/Dictionaries/MongoDBDictionarySource.cpp @@ -145,13 +145,9 @@ MongoDBDictionarySource::MongoDBDictionarySource( connection->connect(host, port); if (!user.empty()) { -#if POCO_VERSION >= 0x01070800 Poco::MongoDB::Database poco_db(db); if (!poco_db.authenticate(*connection, user, password, method.empty() ? Poco::MongoDB::Database::AUTH_SCRAM_SHA1 : method)) throw Exception(ErrorCodes::MONGODB_CANNOT_AUTHENTICATE, "Cannot authenticate in MongoDB, incorrect user or password"); -#else - authenticate(*connection, db, user, password); -#endif } } } diff --git a/src/Processors/Transforms/MongoDBSource.cpp b/src/Processors/Transforms/MongoDBSource.cpp index b8f40789e83..057625f24f2 100644 --- a/src/Processors/Transforms/MongoDBSource.cpp +++ b/src/Processors/Transforms/MongoDBSource.cpp @@ -35,105 +35,6 @@ namespace ErrorCodes } -#if POCO_VERSION < 0x01070800 -/// See https://pocoproject.org/forum/viewtopic.php?f=10&t=6326&p=11426&hilit=mongodb+auth#p11485 -void authenticate(Poco::MongoDB::Connection & connection, const std::string & database, const std::string & user, const std::string & password) -{ - Poco::MongoDB::Database db(database); - - /// Challenge-response authentication. - std::string nonce; - - /// First step: request nonce. - { - auto command = db.createCommand(); - command->setNumberToReturn(1); - command->selector().add("getnonce", 1); - - Poco::MongoDB::ResponseMessage response; - connection.sendRequest(*command, response); - - if (response.documents().empty()) - throw Exception( - "Cannot authenticate in MongoDB: server returned empty response for 'getnonce' command", - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - - auto doc = response.documents()[0]; - try - { - double ok = doc->get("ok", 0); - if (ok != 1) - throw Exception( - "Cannot authenticate in MongoDB: server returned response for 'getnonce' command that" - " has field 'ok' missing or having wrong value", - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - - nonce = doc->get("nonce", ""); - if (nonce.empty()) - throw Exception( - "Cannot authenticate in MongoDB: server returned response for 'getnonce' command that" - " has field 'nonce' missing or empty", - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - } - catch (Poco::NotFoundException & e) - { - throw Exception( - "Cannot authenticate in MongoDB: server returned response for 'getnonce' command that has missing required field: " - + e.displayText(), - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - } - } - - /// Second step: use nonce to calculate digest and send it back to the server. - /// Digest is hex_md5(n.nonce + username + hex_md5(username + ":mongo:" + password)) - { - std::string first = user + ":mongo:" + password; - - Poco::MD5Engine md5; - md5.update(first); - std::string digest_first(Poco::DigestEngine::digestToHex(md5.digest())); - std::string second = nonce + user + digest_first; - md5.reset(); - md5.update(second); - std::string digest_second(Poco::DigestEngine::digestToHex(md5.digest())); - - auto command = db.createCommand(); - command->setNumberToReturn(1); - command->selector() - .add("authenticate", 1) - .add("user", user) - .add("nonce", nonce) - .add("key", digest_second); - - Poco::MongoDB::ResponseMessage response; - connection.sendRequest(*command, response); - - if (response.empty()) - throw Exception( - "Cannot authenticate in MongoDB: server returned empty response for 'authenticate' command", - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - - auto doc = response.documents()[0]; - try - { - double ok = doc->get("ok", 0); - if (ok != 1) - throw Exception( - "Cannot authenticate in MongoDB: server returned response for 'authenticate' command that" - " has field 'ok' missing or having wrong value", - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - } - catch (Poco::NotFoundException & e) - { - throw Exception( - "Cannot authenticate in MongoDB: server returned response for 'authenticate' command that has missing required field: " - + e.displayText(), - ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); - } - } -} -#endif - std::unique_ptr createCursor(const std::string & database, const std::string & collection, const Block & sample_block_to_select) { auto cursor = std::make_unique(database, collection); diff --git a/src/Storages/StorageMongoDB.cpp b/src/Storages/StorageMongoDB.cpp index 3ae9c974770..92d4c6c0686 100644 --- a/src/Storages/StorageMongoDB.cpp +++ b/src/Storages/StorageMongoDB.cpp @@ -72,16 +72,14 @@ void StorageMongoDB::connectIfNotConnected() auto auth_db = database_name; if (auth_source != query_params.end()) auth_db = auth_source->second; -#if POCO_VERSION >= 0x01070800 + if (!username.empty() && !password.empty()) { Poco::MongoDB::Database poco_db(auth_db); if (!poco_db.authenticate(*connection, username, password, Poco::MongoDB::Database::AUTH_SCRAM_SHA1)) throw Exception("Cannot authenticate in MongoDB, incorrect user or password", ErrorCodes::MONGODB_CANNOT_AUTHENTICATE); } -#else - authenticate(*connection, database_name, username, password); -#endif + authenticated = true; } } @@ -213,7 +211,6 @@ StorageMongoDBConfiguration StorageMongoDB::getConfiguration(ASTs engine_args, C if (engine_args.size() >= 6) configuration.options = checkAndGetLiteralArgument(engine_args[5], "database"); - } context->getRemoteHostFilter().checkHostAndPort(configuration.host, toString(configuration.port));