From ea435676049221c262d8bab8cddbf6dbb677acbe Mon Sep 17 00:00:00 2001 From: Qx Date: Tue, 5 Mar 2024 10:36:52 +0800 Subject: [PATCH] Fix the initial authentication status of the ACL user and the ACL permission judgment after the default user is connected (#2449) --- src/pika_client_conn.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/pika_client_conn.cc b/src/pika_client_conn.cc index 1c4e5a182b..1dddf830e5 100644 --- a/src/pika_client_conn.cc +++ b/src/pika_client_conn.cc @@ -3,17 +3,13 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. -#include "include/pika_client_conn.h" - #include -#include +#include #include #include -#include - -#include "include/pika_client_conn.h" #include "include/pika_admin.h" +#include "include/pika_client_conn.h" #include "include/pika_cmd_table_manager.h" #include "include/pika_command.h" #include "include/pika_conf.h" @@ -450,21 +446,19 @@ void PikaClientConn::DoAuth(const std::shared_ptr& user) { void PikaClientConn::UnAuth(const std::shared_ptr& user) { user_ = user; - authenticated_ = false; + // If the user does not have a password, and the user is valid, then the user does not need authentication + authenticated_ = user_->HasFlags(static_cast(AclUserFlag::NO_PASS)) && + !user_->HasFlags(static_cast(AclUserFlag::DISABLED)); } bool PikaClientConn::IsAuthed() const { return authenticated_; } bool PikaClientConn::AuthRequired() const { - if (IsAuthed()) { // the user is authed, not required - return false; - } - - if (user_->HasFlags(static_cast(AclUserFlag::NO_PASS))) { // the user is no password - return false; - } - - return user_->HasFlags(static_cast(AclUserFlag::DISABLED)); // user disabled + // If the user does not have a password, and the user is valid, then the user does not need authentication + // Otherwise, you need to determine whether go has been authenticated + return (!user_->HasFlags(static_cast(AclUserFlag::NO_PASS)) || + user_->HasFlags(static_cast(AclUserFlag::DISABLED))) && + !IsAuthed(); } std::string PikaClientConn::UserName() const { return user_->Name(); }