Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PolarHandlerCommon.java #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> users = new ArrayList<>();
for (PolarAccountInfo user : res.getFailedGrantees()) {
users.add(user.getIdentifier());
}

protected static void checkDrdsRoot(List<PolarAccountInfo> 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<PolarAccountInfo> 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<PolarAccountInfo> getGrantees(SQLExprTableSource sqlExprTableSource, List<SQLExpr> users,
List<SQLPrivilegeItem> privilegeItems, ServerConnection c)
Expand Down
Loading