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

Permission for Relation model. #13158

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

ColinLeeo
Copy link
Collaborator

@ColinLeeo ColinLeeo commented Aug 14, 2024

In this pr:

  1. Supported permission management under the table model, including user management and permission control.
  2. Optimized some logical structures in the code, adjusted abstractions, making it easier to maintain and expand.
  3. Removed support for upgrading from the old permission system before version 1.3. Upgrading to the 1.4 series requires upgrading to version 1.3 first.

@ColinLeeo ColinLeeo marked this pull request as draft August 14, 2024 02:21
@ColinLeeo ColinLeeo changed the base branch from ty/TableModelGrammar to master August 14, 2024 02:38
@ColinLeeo ColinLeeo changed the base branch from master to ty/TableModelGrammar August 14, 2024 02:39
plan = new AuthorPlan(configPhysicalPlanType);
plan = new AuthorTreePlan(configPhysicalPlanType);
break;
case RCreateRole:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better keep the order consistent to the definitions.

final boolean grantOpt,
final int permission,
final String password) {
super(authorType);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May directly call the super() with more parameters.

@@ -576,7 +577,7 @@ public void AuthorPlanTest() throws IOException, IllegalPathException {

// create user
req0 =
new AuthorPlan(
new AuthorTreePlan(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to add the ser/de tests for new plans.

Copy link
Collaborator Author

@ColinLeeo ColinLeeo Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their ser/de functions were tested at authOperationProcedureTest, which ser/de itself and its owned author plan.

case REVOKE_USER_ROLE:
return QueryType.WRITE;
case LIST_ROLE:
case LIST_USER:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has the "List privilege" been designed, or are they shown in the "list role/user"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is outdate, see RelationalAuthorStatement.java

+ tableName
+ "user name:"
+ userName
+ "role name"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format can be more normalized..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not exist in this pr, see RelationalAuthorStatement.java.

}
return text;
}
@Override
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bettter add a blank line, and why do we use "''" in the password?

if (ctx.grant_privilege_object().ON() != null) {
String privilegeText = ctx.grant_privilege_object().object_privilege().getText();
PrivilegeType priv = PrivilegeType.valueOf(privilegeText.toUpperCase());
if (ctx.grant_privilege_object().object_type().getText().equalsIgnoreCase("TABLE")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the "db.table" and "ANY" taken into account here?


TSStatus checkUserSysPrivileges(String username, int permisssion);
TSStatus checkUserSysPrivileges(String username, PrivilegeType permisssion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better change it to "permission", not "permisssion"..

@Caideyipi
Copy link
Collaborator

Be sure to check the license issues.

this.grantOption = false;
}

public PrivilegeModelType ModelType() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use camelCase

7: required bool grantOpt
}

struct TCheckUserRelationalPrivilegesReq {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems useless?

@ColinLeeo ColinLeeo changed the base branch from ty/TableModelGrammar to master December 5, 2024 06:28
@ColinLeeo ColinLeeo marked this pull request as ready for review December 19, 2024 15:25
;

privilegeObjectScope
: systemPrivilege
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr is to big.. I will create a new pr base this pr to support ALL.

@ColinLeeo ColinLeeo requested a review from JackieTien97 January 2, 2025 03:49
@@ -1191,6 +1301,7 @@ PASSING: 'PASSING';
PAST: 'PAST';
PATH: 'PATH';
PATTERN: 'PATTERN';
PASSWORD: 'PASSWORD';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to check the dictionary order...

return tableName;
}

public Set<Integer> getPermissions() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly not useful?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works when we support ALL privileges.

ReadWriteIOUtils.write(getType().getPlanType(), stream);
BasicStructureSerDeUtil.write(userName, stream);
BasicStructureSerDeUtil.write(roleName, stream);
BasicStructureSerDeUtil.write(password, stream);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to write "newPassword"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, newPassword is useless. In TreeAuthorPlan, It is used to store the user's new password, which can be replaced by a password field. So in RelationalAuthorPlan, the user's new password or his original password will all be stored in the password field.

BasicStructureSerDeUtil.write(userName, stream);
BasicStructureSerDeUtil.write(roleName, stream);
BasicStructureSerDeUtil.write(password, stream);
if (databaseName == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this string directly?

plan.getRoleName(),
plan.getPassword(),
plan.getNewPassword(),
plan.getPermissions(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better change this to back to "permissions"... This has been trimmed by user's pattern....

Assert.assertEquals(privs.get(0).getPrivileges().size(), 2);
Assert.assertFalse(privs.get(0).getPrivileges().contains(PrivilegeType.READ_DATA.ordinal()));
AuthUtils.removePrivilege(rootPath, PrivilegeType.READ_DATA, privs);
Assert.assertEquals(privs.get(0).getPrivilegeIntSet().size(), 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May put the "expected value" first...

@@ -604,7 +605,7 @@ private ColumnHeaderConstant() {
public static final List<ColumnHeader> LIST_USER_PRIVILEGES_Column_HEADERS =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use upper case here, and better name it as "USER_OR_ROLE_PRIVILEGES"

LOGGER.warn("Cannot load admin, Creating a new one", e);
admin = null;
}
User admin = getEntry(CommonDescriptor.getInstance().getConfig().getAdminName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

”Entry“ may be too unclear... Maybe "identity" is better?

}

@Override
public boolean createUser(
public boolean createEntry(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it "createUser" if this is not overrided from its super class.

lock.readUnlock(username);
return user;
public User getEntry(String username) {
return (User) super.getEntry(username);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to override it here?

public boolean checkTBVisible(String database, String tbName) {
return !anyScopePrivilegeSet.isEmpty()
|| (objectPrivilegeMap.containsKey(database)
&& objectPrivilegeMap.get(database).getTablePrivilegeMap().containsKey(tbName));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly this shall be "||" according to the definition? Though you may need to check if any DB privileges exist....

@@ -387,6 +466,10 @@ private void checkCacheAvailable() {
cacheOutDate = false;
}

public void setAcceptCache(boolean acceptCache) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

@@ -88,4 +94,184 @@ public void checkCanShowOrDescTable(String userName, QualifiedObjectName tableNa
public void checkUserHasMaintainPrivilege(String userName) {
authChecker.checkGlobalPrivilege(userName, TableModelPrivilege.MAINTAIN);
}

@Override
public void checkUserCanRunAuthorStatement(String userName, RelationalAuthorStatement statement) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the AuthorType and checking logic of the (tree) AuthorStatement? They look the same....


protected Set<PrivilegeType> anyScopePrivileGrantOptSet;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Privilege?

return objectPrivilegeMap;
}

public DatabasePrivilege getObjectPrivilege(String objectName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is dangerous... Currently it's only used in "grant" thus it is OK. However, if someone wants to only get the database privilege from outside, there will be an empty database privilege, then the database may be able to be shown.

role.revokeTBPrivilegeGrantOption(dbName, tbName, privilegeType);
return true;
}
if (role.hasPrivilegeToRevoke(dbName, tbName, privilegeType)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems useless here?

public boolean checkPathPrivilege(PartialPath path, int privilegeId) {
return AuthUtils.checkPathPrivilege(path, privilegeId, pathPrivilegeList);
public boolean checkTablePrivilegeGrantOption(String dbname, String table, PrivilegeType priv) {
if (checkAnyScopePrivilegeGrantOption(priv)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be called twice..

@@ -193,33 +535,43 @@ public boolean equals(Object o) {
return Objects.equals(name, role.name)
&& Objects.equals(pathPrivilegeList, role.pathPrivilegeList)
&& Objects.equals(sysPrivilegeSet, role.sysPrivilegeSet)
&& Objects.equals(sysPriGrantOpt, role.sysPriGrantOpt);
&& Objects.equals(sysPriGrantOpt, role.sysPriGrantOpt)
&& Objects.equals(objectPrivilegeMap, role.objectPrivilegeMap);
}

@Override
public int hashCode() {
return Objects.hash(name, pathPrivilegeList, sysPrivilegeSet);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashCode?

@@ -193,33 +535,43 @@ public boolean equals(Object o) {
return Objects.equals(name, role.name)
&& Objects.equals(pathPrivilegeList, role.pathPrivilegeList)
&& Objects.equals(sysPrivilegeSet, role.sysPrivilegeSet)
&& Objects.equals(sysPriGrantOpt, role.sysPriGrantOpt);
&& Objects.equals(sysPriGrantOpt, role.sysPriGrantOpt)
&& Objects.equals(objectPrivilegeMap, role.objectPrivilegeMap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnyScope?

return role;
}
int version = dataInputStream.readInt();
assert version == VERSION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should guarantee the compatibility here...

}

@Override
public int hashCode() {
return Objects.hash(name, pathPrivilegeList, sysPrivilegeSet);
}

private void serializePrivilegeSet(DataOutputStream outputStream, Set<PrivilegeType> set)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be identical to SerializeUtils.serializePrivilegeTypeSet...

for (PrivilegeType type : types) {
dataOutputStream.writeInt(type.ordinal());
}
} catch (IOException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to catch it?

@@ -246,6 +598,14 @@ public void deserialize(ByteBuffer buffer) {
pathPrivilege.deserialize(buffer);
pathPrivilegeList.add(pathPrivilege);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyScopePrivilegeSet?

void reset() throws AuthException;

/**
* List all roles in the database.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users/roles

/**
* List all roles in the database.
*
* @return A list that contains names of all roles.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users/roles

void grantPrivilegeToEntry(String entryName, PrivilegeUnion privilegeUnion) throws AuthException;

/**
* Revoke a privilege on seriesPath from a entry.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on series path?

}

public TablePrivilege() {
//
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving "//" may not be a good idea...

@@ -423,6 +465,7 @@ public TAuthizedPatternTreeResp generateAuthizedPTree(String username, int permi
throws AuthException {
TAuthizedPatternTreeResp resp = new TAuthizedPatternTreeResp();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better rename this to "Authorized"

@@ -1169,6 +1170,67 @@ protected Void visitShowTopics(ShowTopics node, Integer context) {
return null;
}

@Override
protected Void visitRelationalAuthorPlan(RelationalAuthorStatement node, Integer context) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, personally I think all other sqls just write the full SQL...


assertEquals(
authorInfo.checkRoleOfUser("user", "role").getStatus().getCode(),
TSStatusCode.SUCCESS_STATUS.getStatusCode());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better place the expected value at first.

// to check relational privilege, database or table is required
// to check system privilege, just spec permission

// if grant opt is ture, check grant option of spec permission.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

}

public DatabasePrivilege() {
//
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not leave "//"?

}

DatabasePrivilege that = (DatabasePrivilege) o;
return databaseName.equals(that.databaseName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "Objects.equals()" may be safer because the "databaseName" is nullable(though now nullable privilege won't call "equals()")

tableName.getDatabaseName(),
tableName.getObjectName());
if (result.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
throw new RuntimeException(new IoTDBException(result.getMessage(), result.getCode()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "AccessControlException" instead?

return;
}
TSStatus result =
AuthorityChecker.getTSStatus(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getGrantOptTSStatus?

@Override
public void checkTablePrivilegeGrantOption(
String userName, QualifiedObjectName tableName, TableModelPrivilege privilege) {
TSStatus result =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there are no "AuthorityChecker.SUPER_USER.equals(userName)" here...

@Override
public void checkDatabasePrivilegeGrantOption(
String userName, String databaseName, TableModelPrivilege privilege) {
TSStatus result =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there are no "AuthorityChecker.SUPER_USER.equals(userName)" here...

@Override
public Node visitAlterUserStatement(RelationalSqlParser.AlterUserStatementContext ctx) {
RelationalAuthorStatement stmt = new RelationalAuthorStatement(AuthorRType.UPDATE_USER);
stmt.setRoleName(ctx.userName.getText());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "roleName" here?

if (toTable) {
databaseName = clientSession.getDatabaseName();
if (databaseName == null) {
throw new SemanticException("Database is set yet.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

……

if (fromTable) {
databaseName = clientSession.getDatabaseName();
if (databaseName == null) {
throw new SemanticException("Database is set yet.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

private Set<PrivilegeType> privileges;
private Set<PrivilegeType> grantOpts;

private final int PRI_SIZE = PrivilegeType.getPrivilegeCount(PrivilegeModelType.TREE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be static

for (Integer privilegeId : privileges) {
builder.append(" ").append(PrivilegeType.values()[privilegeId]);
if (grantOpts.contains(privilegeId)) {
List<PrivilegeType> sortedPrivileges = new ArrayList<>(privileges);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better change line 185 BTW

dbPrivilege2.revokeTablePrivilege("test", PrivilegeType.SELECT);
dbPrivilege2.revokeTableGrantOption("test", PrivilegeType.SELECT);
dbPrivilege2.revokeTablePrivilege("test", PrivilegeType.DELETE);
Assert.assertEquals(dbPrivilege2.getTablePrivilegeMap().size(), 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice the order of the expected value and the actual one

dbPrivilege2.revokeTablePrivilege("test2", PrivilegeType.SELECT);
dbPrivilege2.revokeDBPrivilege(PrivilegeType.INSERT);
dbPrivilege2.revokeDBGrantOption(PrivilegeType.ALTER);
Assert.assertEquals(dbPrivilege2.getTablePrivilegeMap().size(), 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

} else if (item.isRelationalPrivilege()) {
databasePrivilege.grantDBPrivilege(item);
databasePrivilege.grantDBGrantOption(item);
databasePrivilege.grantTablePrivilege("testTable", item);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better add grant option for admin


public class TablePrivilegeTest {
@Test
public void testTablePrivilege_Init() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not reflect the real change of table privilege, because the "privilege" and "grant option" seems indepentent here.

@@ -756,11 +757,12 @@ public void testNormalGrantRevoke() {

// 3. check simple privilege revoke from user/role on simple path
for (PrivilegeType type : PrivilegeType.values()) {
if (type.isRelationalPrivilege()) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better place the "continue" in a separate line?

* seriesPath-free privilege, this should be "root".
* @param privilegeId An integer that represents a privilege.
* @param grantOpt Whether the privilege is grant option.
* @param userName The username of the user to which the privilege should be added.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better add a little description fro the "union" field

roles[i].getPathPrivilegeList().add(pathPrivilege);
roles[i].getSysPrivilege().add(i + 4);
roles[i].grantSysPrivilege(PrivilegeType.values()[i + 4], false);
roles[i].grantDBPrivilege("testdb", PrivilegeType.CREATE, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly the "CREATE" is granted twice

user1.toString());
Assert.assertTrue(user1.equals(user));
Assert.assertEquals(user1, user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better swap the sequence

import static org.junit.Assert.assertTrue;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@category({TableLocalStandaloneIT.class, TableClusterIT.class})

import static org.junit.Assert.assertTrue;

@RunWith(IoTDBTestRunner.class)
@Category({ClusterIT.class})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@category({TableClusterIT.class})

public class IoTDBClusterAuthorityRelationalIT {
@Before
public void setUp() throws Exception {
// Init 1C0D environment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1C1D?

assertEquals(status.getCode(), TSStatusCode.SUCCESS_STATUS.getStatusCode());
}

private void cleanUserAndRole(SyncConfigNodeIServiceClient client) throws TException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only "user" is cleared?

AuthorRType.GRANT_USER_ROLE.ordinal(), "user1", "role1", "", "", "", -1, false));
grantSysPrivilegeAndCheck(client, "user1", "role1", true, PrivilegeType.MANAGE_USER, false);
grantSysPrivilegeAndCheck(client, "user1", "role1", true, PrivilegeType.MANAGE_ROLE, true);
grantSysPrivilegeAndCheck(client, "user1", "role1", false, PrivilegeType.MAINTAIN, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better only specify one of user and role to make it clearer…… And in fact we shall only pass one "name" into the parameter

@@ -101,174 +98,143 @@ public void createAndDeleteUser() throws AuthException {

@Test
public void createAndDeleteRole() throws AuthException {
authorizer.createRole(user.getName());
authorizer.createRole(userName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use "roleName"?

} catch (AuthException e) {
assertEquals("Role user already exists", e.getMessage());
}
authorizer.deleteRole(user.getName());
authorizer.createUser("test", "password");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use "userName"?

try {
authorizer.revokePrivilegeFromUser(
user.getName(), nodeName, PrivilegeType.READ_DATA.ordinal());
userName, new PrivilegeUnion(nodeName, PrivilegeType.READ_DATA));
} catch (AuthException e) {
assertEquals("User user does not have READ_DATA on root.laptop.d1", e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be thrown now, do not catch it

accessor.saveEntry(user);
accessor.reset();
User loadUser = accessor.loadEntry("test");
assertEquals(user, loadUser);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better reserve the "List" and "Delete" tests.

List<String> resultLines = Arrays.asList(result.split("\n"));
assertEquals(ansLines.size(), resultLines.size());
for (String resultLine : resultLines) {
assertTrue(ansLines.contains(resultLine));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use "contains"? BTW, there is a similar function called TestUtils.assertResultSetEqual().

return "No such role %s";
}

protected BasicRoleManager() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it used?


// user's priv:
// 1. MANAGE_DATABASE
// 2. USE_PIPE with grant option
// 3. READ_DATA root.d1.**
// 4. WRITE_SCHEMA root.d1.** with grant option
// 5. SELECT on database, ALTER on database with grant option
// 6. UPDATE on database.table, DELETE on database.table with grant option

// role's priv:
// 1. USE_UDF
// 2. USE_CQ with grant option
// 3. READ_DATA root.t9.** with grant option
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t9? Database privilege?

"user1", Collections.singletonList(pathRoot), PrivilegeType.MANAGE_USER.ordinal()));
Assert.assertEquals(
authorityFetcher.checkUserSysPrivilegesGrantOpt("user1", PrivilegeType.USE_PIPE).getCode(),
TSStatusCode.SUCCESS_STATUS.getStatusCode());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the expected value at the front

authorityFetcher
.checkUserPathPrivilegesGrantOpt(
"user1",
Collections.singletonList(new PartialPath("root.d1.d1.**")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above just said "root.d1.d2"

Collections.singletonList(new PartialPath("root.**")),
PrivilegeType.WRITE_SCHEMA)
.getCode(),
TSStatusCode.NO_PERMISSION.getStatusCode());
// reuqire root.d1.d2 with write_schema, return true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"require"


List<String> roleList = new ArrayList<>();
if (roleOfUser.exists()) {
Set<String> roleList = new HashSet<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roleSet

assert (tag == VERSION);
user.setName(IOUtils.readString(dataInputStream, STRING_ENCODING, strBufferLocal));
user.setPassword(IOUtils.readString(dataInputStream, STRING_ENCODING, strBufferLocal));
user.setSysPrivilegesWithMask(dataInputStream.readInt());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put this in "loadPrivileges"?

Set<String> roleSet = new HashSet<>();
if (roleOfUser.exists()) {
inputStream = new FileInputStream(roleOfUser);
try (DataInputStream roleInpuStream =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roleInputStream

public List<String> listAllUsers() {
File userDir = SystemFileFactory.INSTANCE.getFile(userDirPath);
public List<String> listAllEntries() {
File userDir = SystemFileFactory.INSTANCE.getFile(entryDirPath);
String[] names =
userDir.list(
(dir, name) ->
(name.endsWith(IoTDBConstant.PROFILE_SUFFIX)
&& !name.endsWith(ROLE_SUFFIX + IoTDBConstant.PROFILE_SUFFIX))
|| (name.endsWith(TEMP_SUFFIX) && !name.endsWith(ROLE_SUFFIX + TEMP_SUFFIX)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROLE_SUFFIX + PROFILE_SUFFIX + TEMP_SUFFIX?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants