diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index f9044fac0057b..f1d30b96f760d 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -576,7 +576,7 @@ public ShowResultSet visitShowTemporaryTablesStatement(ShowTemporaryTableStmt st @Override public ShowResultSet visitShowTableStatusStatement(ShowTableStatusStmt statement, ConnectContext context) { List> rows = Lists.newArrayList(); - Database db = context.getGlobalStateMgr().getLocalMetastore().getDb(statement.getDb()); + Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(statement.getDb()); ZoneId currentTimeZoneId = TimeUtils.getTimeZone().toZoneId(); if (db != null) { Locker locker = new Locker(); @@ -593,8 +593,8 @@ public ShowResultSet visitShowTableStatusStatement(ShowTableStatusStmt statement } try { - Authorizer.checkAnyActionOnTable(context.getCurrentUserIdentity(), - context.getCurrentRoleIds(), new TableName(db.getFullName(), table.getName())); + Authorizer.checkAnyActionOnTableLikeObject(context.getCurrentUserIdentity(), + context.getCurrentRoleIds(), db.getFullName(), table); } catch (AccessDeniedException e) { continue; } @@ -1853,10 +1853,10 @@ public ShowResultSet visitShowRestoreStatement(ShowRestoreStmt statement, Connec // restore info for external catalog AbstractJob jobI = GlobalStateMgr.getCurrentState().getBackupHandler().getJob(-1L); - if (jobI != null && jobI instanceof RestoreJob) { + if (jobI != null && jobI instanceof RestoreJob) { RestoreJob restoreJob = (RestoreJob) jobI; List info = restoreJob.getInfo(); - infos.add(info); + infos.add(info); } return new ShowResultSet(statement.getMetaData(), infos); diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Authorizer.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Authorizer.java index b3f95d2901614..be1a2c8ff159c 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Authorizer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Authorizer.java @@ -185,6 +185,10 @@ public static void checkAnyActionOnTableLikeObject(UserIdentity currentUser, Set private static void doCheckTableLikeObject(UserIdentity currentUser, Set roleIds, String dbName, BasicTable tbl, PrivilegeType privilegeType) throws AccessDeniedException { + if (tbl == null) { + return; + } + Table.TableType type = tbl.getType(); switch (type) { case OLAP: diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java index ed34d22ea4c37..7a55e13c449f4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java @@ -22,6 +22,7 @@ import com.starrocks.analysis.TableRef; import com.starrocks.backup.AbstractJob; import com.starrocks.backup.BackupJob; +import com.starrocks.catalog.BasicTable; import com.starrocks.catalog.Database; import com.starrocks.catalog.Function; import com.starrocks.catalog.FunctionSearchDesc; @@ -1630,7 +1631,7 @@ public Void visitCancelAlterTableStatement(CancelAlterTableStmt statement, Conne Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(statement.getDbName()); if (db != null) { Table table = GlobalStateMgr.getCurrentState().getLocalMetastore() - .getTable(db.getFullName(), statement.getTableName()); + .getTable(db.getFullName(), statement.getTableName()); if (table == null || !table.isMaterializedView()) { // ignore privilege check for old mv return null; @@ -1681,7 +1682,10 @@ public Void visitDescTableStmt(DescribeStmt statement, ConnectContext context) { @Override public Void visitShowCreateTableStatement(ShowCreateTableStmt statement, ConnectContext context) { try { - Authorizer.checkAnyActionOnTable(context.getCurrentUserIdentity(), context.getCurrentRoleIds(), statement.getTbl()); + BasicTable basicTable = GlobalStateMgr.getCurrentState().getMetadataMgr().getBasicTable( + statement.getTbl().getCatalog(), statement.getTbl().getDb(), statement.getTbl().getTbl()); + Authorizer.checkAnyActionOnTableLikeObject(context.getCurrentUserIdentity(), context.getCurrentRoleIds(), + statement.getDb(), basicTable); } catch (AccessDeniedException e) { AccessDeniedException.reportAccessDenied( statement.getTbl().getCatalog(), @@ -2153,7 +2157,7 @@ public Void visitBackupStatement(BackupStmt statement, ConnectContext context) { externalCatalogs.forEach(externalCatalog -> { try { Authorizer.checkCatalogAction(context.getCurrentUserIdentity(), context.getCurrentRoleIds(), - externalCatalog.getCatalogName(), PrivilegeType.USAGE); + externalCatalog.getCatalogName(), PrivilegeType.USAGE); } catch (AccessDeniedException e) { AccessDeniedException.reportAccessDenied( externalCatalog.getCatalogName(), @@ -2279,7 +2283,7 @@ public Void visitRestoreStatement(RestoreStmt statement, ConnectContext context) // check insert on specified table for (TableRef tableRef : tableRefs) { Table table = GlobalStateMgr.getCurrentState().getLocalMetastore() - .getTable(db.getFullName(), tableRef.getName().getTbl()); + .getTable(db.getFullName(), tableRef.getName().getTbl()); if (table != null) { try { Authorizer.checkTableAction(context.getCurrentUserIdentity(), context.getCurrentRoleIds(), diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ShowStmtAnalyzer.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ShowStmtAnalyzer.java index ab52835d61192..5a5fbf09267ed 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ShowStmtAnalyzer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ShowStmtAnalyzer.java @@ -139,7 +139,6 @@ public Void visitShowTemporaryTablesStatement(ShowTemporaryTableStmt node, Conne return visitShowTableStatement(node, context); } - @Override public Void visitShowTabletStatement(ShowTabletStmt node, ConnectContext context) { ShowTabletStmtAnalyzer.analyze(node, context); diff --git a/fe/starrocks_intellij_style.xml b/fe/starrocks_intellij_style.xml index da662d9afa386..ca994c26220d1 100644 --- a/fe/starrocks_intellij_style.xml +++ b/fe/starrocks_intellij_style.xml @@ -14,6 +14,7 @@ +