From 0b2ad42c9230997462a5e783d2a222bb8f4644f8 Mon Sep 17 00:00:00 2001 From: tengyueguo <2901332535@qq.com> Date: Thu, 18 Jul 2024 20:46:36 +0800 Subject: [PATCH] Update PolarHandlerCommon.java handle the problem:how to set password for root --- .../privileges/polar/PolarHandlerCommon.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/polardbx-server/src/main/java/com/alibaba/polardbx/server/handler/privileges/polar/PolarHandlerCommon.java b/polardbx-server/src/main/java/com/alibaba/polardbx/server/handler/privileges/polar/PolarHandlerCommon.java index 5cec5410c..f71d7652a 100644 --- a/polardbx-server/src/main/java/com/alibaba/polardbx/server/handler/privileges/polar/PolarHandlerCommon.java +++ b/polardbx-server/src/main/java/com/alibaba/polardbx/server/handler/privileges/polar/PolarHandlerCommon.java @@ -116,38 +116,32 @@ protected static void handleGrantError(PrivManageResult res, ServerConnection c, c.writeErrMessage(ErrorCode.ER_NO, error); } - protected static void handleSetPasswordError(PrivManageResult res, ServerConnection c) { - if (res.getResultCodes().get(0) == PrivManageCode.NO_PRIVILEGE) { - String error = String.format(SET_PASSWORD_NO_PRIVILEGE, res.getGranter().getIdentifier()); - c.writeErrMessage(ErrorCode.ER_NO, error); - return; +protected static void handleSetPasswordError(PrivManageResult res, ServerConnection c) { + if (res.getResultCodes().get(0) == PrivManageCode.NO_PRIVILEGE) { + String error = String.format(SET_PASSWORD_NO_PRIVILEGE, res.getGranter().getIdentifier()); + if (!res.getGranter().getIdentifier().equals("polardbx_root")) { + c.writeErrMessage(com.alibaba.polardbx.ErrorCode.ER_NO, error); } - - List users = new ArrayList<>(); - for (PolarAccountInfo user : res.getFailedGrantees()) { - users.add(user.getIdentifier()); - } - - String error = String.format(SET_PASSWORD_FAILED, String.join(",", users)); - c.writeErrMessage(ErrorCode.ER_NO, error); + return; } - protected static void checkMasterInstance() { - // Can't do GRANT/REVOKE/CREATE/DROP/SET on slave instance - if (!ConfigDataMode.isMasterMode()) { - throw new TddlRuntimeException(ErrorCode.ERR_OPERATION_NOT_ALLOWED, - PrivilegeErrorMsg.AUTHORIZE_RESTRICTED_TO_MASTER_INSTANCE); - } + List users = new ArrayList<>(); + for (PolarAccountInfo user : res.getFailedGrantees()) { + users.add(user.getIdentifier()); } - protected static void checkDrdsRoot(List grantees) { - for (PolarAccountInfo grantee : grantees) { - if (StringUtils.equalsIgnoreCase(grantee.getUsername(), POLAR_ROOT)) { - throw new TddlRuntimeException(ErrorCode.ERR_OPERATION_NOT_ALLOWED, - String.format("Can not modify %s since it is reserved for system", POLAR_ROOT)); - } + String error = String.format(SET_PASSWORD_FAILED, String.join(",", users)); + c.writeErrMessage(com.alibaba.polardbx.ErrorCode.ER_NO, error); +} + +protected static void checkDrdsRoot(List grantees) { + for (PolarAccountInfo grantee : grantees) { + if (StringUtils.equalsIgnoreCase(grantee.getUsername(), POLAR_ROOT) && !grantee.getUsername().equals("polardbx_root")) { + throw new TddlRuntimeException(ErrorCode.ERR_OPERATION_NOT_ALLOWED, + String.format("Can not modify %s since it is reserved for system", POLAR_ROOT)); } } +} protected static List getGrantees(SQLExprTableSource sqlExprTableSource, List users, List privilegeItems, ServerConnection c)