@@ -66,8 +66,22 @@ public void listUserPrivileges() throws SQLException {
66
66
Statement adminStmt = adminCon .createStatement ()) {
67
67
68
68
adminStmt .execute ("create user testuser 'password123456'" );
69
+ try (Connection userCon =
70
+ EnvFactory .getEnv ()
71
+ .getConnection ("testuser" , "password123456" , BaseEnv .TABLE_SQL_DIALECT );
72
+ Statement userStmt = userCon .createStatement ()) {
73
+ ResultSet resultSet = userStmt .executeQuery ("LIST USER" );
74
+ Assert .assertTrue (resultSet .next ());
75
+ Assert .assertEquals ("testuser" , resultSet .getString (1 ));
76
+ Assert .assertFalse (resultSet .next ());
77
+ }
69
78
adminStmt .execute ("create database testdb" );
70
- adminStmt .execute ("GRANT MANAGE_USER to user testuser" );
79
+ adminStmt .execute ("GRANT SECURITY to user testuser" );
80
+ Assert .assertThrows (
81
+ SQLException .class ,
82
+ () -> {
83
+ adminStmt .execute ("GRANT MANAGE_USER to user testuser" );
84
+ });
71
85
Assert .assertThrows (
72
86
SQLException .class ,
73
87
() -> {
@@ -85,7 +99,11 @@ public void listUserPrivileges() throws SQLException {
85
99
adminStmt .execute ("GRANT MAINTAIN to user testuser" );
86
100
});
87
101
88
- adminStmt .execute ("GRANT MANAGE_ROLE TO USER testuser" );
102
+ Assert .assertThrows (
103
+ SQLException .class ,
104
+ () -> {
105
+ adminStmt .execute ("GRANT MANAGE_ROLE to user testuser" );
106
+ });
89
107
adminStmt .execute ("GRANT SELECT ON ANY TO USER testuser" );
90
108
adminStmt .execute ("GRANT INSERT ON ANY TO USER testuser" );
91
109
adminStmt .execute ("GRANT DELETE ON ANY TO USER testuser" );
@@ -106,8 +124,7 @@ public void listUserPrivileges() throws SQLException {
106
124
Set <String > ans =
107
125
new HashSet <>(
108
126
Arrays .asList (
109
- ",,MANAGE_USER,false," ,
110
- ",,MANAGE_ROLE,false," ,
127
+ ",,SECURITY,false," ,
111
128
",*.*,SELECT,false," ,
112
129
",*.*,INSERT,false," ,
113
130
",*.*,DELETE,false," ,
@@ -162,8 +179,7 @@ public void checkAuthorStatementPrivilegeCheck() throws SQLException {
162
179
});
163
180
164
181
// admin can do all things below.
165
- adminStmt .execute ("GRANT MANAGE_USER to user testuser2 with grant option" );
166
- adminStmt .execute ("GRANT MANAGE_ROLE to user testuser" );
182
+ adminStmt .execute ("GRANT SECURITY to user testuser with grant option" );
167
183
168
184
adminStmt .execute ("use testdb" );
169
185
adminStmt .execute ("GRANT SELECT ON TABLE TB to user testuser" );
@@ -183,49 +199,18 @@ public void checkAuthorStatementPrivilegeCheck() throws SQLException {
183
199
EnvFactory .getEnv ()
184
200
.getConnection ("testuser" , "password123456" , BaseEnv .TABLE_SQL_DIALECT );
185
201
Statement userStmt = userCon1 .createStatement ()) {
186
- // 1. user1's privileges
187
- // testdb.TB select
188
- // testdb.TB insert
189
- // testdb.* insert
190
- // any alter
191
- // manage_role
192
-
193
- // cannot create user
194
- Assert .assertThrows (
195
- SQLException .class ,
196
- () -> {
197
- userStmt .execute ("CREATE USER testuser3 'password'" );
198
- });
202
+
199
203
// can create role
200
204
userStmt .execute ("CREATE ROLE testrole2" );
201
205
// can grant role to user
202
206
userStmt .execute ("GRANT ROLE testrole2 to testuser" );
203
- // cannot grant privileges to other
204
- Assert .assertThrows (
205
- SQLException .class ,
206
- () -> {
207
- userStmt .execute ("GRANT SELECT ON testdb.TB to role testrole2" );
208
- });
209
-
210
- Assert .assertThrows (
211
- SQLException .class ,
212
- () -> {
213
- userStmt .execute ("GRANT ALTER ON ANY to role testrole2" );
214
- });
215
-
216
- // cannot grant manage_role to other
217
- Assert .assertThrows (
218
- SQLException .class ,
219
- () -> {
220
- userStmt .execute ("GRANT manage_role to role testrole2" );
221
- });
222
207
223
208
// can list itself privileges and the all roles privileges
224
209
ResultSet rs = userStmt .executeQuery ("List privileges of user testuser" );
225
210
Set <String > ans =
226
211
new HashSet <>(
227
212
Arrays .asList (
228
- ",,MANAGE_ROLE,false ," ,
213
+ ",,SECURITY,true ," ,
229
214
",*.*,ALTER,false," ,
230
215
",testdb.*,INSERT,false," ,
231
216
",testdb.tb,SELECT,false," ,
@@ -237,60 +222,14 @@ public void checkAuthorStatementPrivilegeCheck() throws SQLException {
237
222
rs = userStmt .executeQuery ("List privileges of role testrole2" );
238
223
TestUtils .assertResultSetEqual (
239
224
rs , "Role,Scope,Privileges,GrantOption," , Collections .emptySet ());
240
- // testdb.TB's privilege is not grant option.
241
- Assert .assertThrows (
242
- SQLException .class ,
243
- () -> {
244
- userStmt .execute ("GRANT insert on testdb.TB to role testrole2" );
245
- });
246
-
247
- Assert .assertThrows (
248
- SQLException .class ,
249
- () -> {
250
- userStmt .execute ("GRANT ALTER on any to role testrole2" );
251
- });
252
- }
253
-
254
- try (Connection userCon1 =
255
- EnvFactory .getEnv ()
256
- .getConnection ("testuser2" , "password123456" , BaseEnv .TABLE_SQL_DIALECT );
257
- Statement userStmt = userCon1 .createStatement ()) {
258
- // 2. user2's privileges
259
- // MANAGE_USER with grant option
260
- // testdb.tb drop with grant option
261
- // testdb.tb create with grant option
262
- // testdb.* drop with grant option
263
- // any select with grant option
264
-
265
- // can create user.
266
225
userStmt .execute ("CREATE USER testuser3 'password123456'" );
267
226
268
- // can not create role
269
- Assert .assertThrows (
270
- SQLException .class ,
271
- () -> {
272
- userStmt .execute ("CREATE ROLE testrole3" );
273
- });
274
-
275
- // cannot list role's privileges
276
- Assert .assertThrows (
277
- SQLException .class ,
278
- () -> {
279
- userStmt .executeQuery ("List privileges of role testrole" );
280
- });
281
-
282
227
userStmt .execute ("GRANT drop on database testdb to user testuser3" );
283
228
userStmt .execute ("GRANT SELECT ON database testdb to user testuser3" );
284
- ResultSet rs = userStmt .executeQuery ("List privileges of user testuser3" );
285
- Set <String > ans =
286
- new HashSet <>(Arrays .asList (",testdb.*,SELECT,false," , ",testdb.*,DROP,false," ));
229
+ rs = userStmt .executeQuery ("List privileges of user testuser3" );
230
+ ans = new HashSet <>(Arrays .asList (",testdb.*,SELECT,false," , ",testdb.*,DROP,false," ));
287
231
TestUtils .assertResultSetEqual (rs , "Role,Scope,Privileges,GrantOption," , ans );
288
232
userStmt .execute ("REVOKE SELECT ON DATABASE testdb from user testuser3" );
289
- Assert .assertThrows (
290
- SQLException .class ,
291
- () -> {
292
- userStmt .execute ("GRANT CREATE ON DATABASE testdb to user testuser3" );
293
- });
294
233
295
234
rs = userStmt .executeQuery ("List privileges of user testuser3" );
296
235
TestUtils .assertResultSetEqual (
@@ -329,7 +268,7 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
329
268
+ " with grant option" );
330
269
Set <String > listPrivilegeResult = new HashSet <>();
331
270
for (PrivilegeType privilegeType : PrivilegeType .values ()) {
332
- if (privilegeType .isRelationalPrivilege ()) {
271
+ if (privilegeType .isRelationalPrivilege () && ! privilegeType . isDeprecated () ) {
333
272
listPrivilegeResult .add (
334
273
(isUser ? "," : "test," ) + "testdb.tb1," + privilegeType + ",true," );
335
274
}
@@ -426,6 +365,9 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
426
365
// 1. grant all on user/role
427
366
adminStmt .execute ("grant all to " + (isUser ? "user test" : "role test" ));
428
367
for (PrivilegeType privilegeType : PrivilegeType .values ()) {
368
+ if (privilegeType .isDeprecated () || privilegeType .isHided ()) {
369
+ continue ;
370
+ }
429
371
if (privilegeType .isRelationalPrivilege ()) {
430
372
listPrivilegeResult .add ((isUser ? "," : "test," ) + "*.*," + privilegeType + ",false," );
431
373
} else if (privilegeType .forRelationalSys ()) {
@@ -475,7 +417,9 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
475
417
476
418
Set <String > listUserPrivilegeResult = new HashSet <>();
477
419
for (PrivilegeType privilegeType : PrivilegeType .values ()) {
478
- if (privilegeType == PrivilegeType .SELECT ) {
420
+ if (privilegeType == PrivilegeType .SELECT
421
+ || privilegeType .isDeprecated ()
422
+ || privilegeType .isHided ()) {
479
423
continue ;
480
424
}
481
425
if (privilegeType .isRelationalPrivilege ()) {
@@ -488,6 +432,9 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
488
432
489
433
Set <String > listRolePrivilegeResult = new HashSet <>();
490
434
for (PrivilegeType privilegeType : PrivilegeType .values ()) {
435
+ if (privilegeType .isDeprecated () || privilegeType .isHided ()) {
436
+ continue ;
437
+ }
491
438
if (privilegeType .isRelationalPrivilege ()) {
492
439
listRolePrivilegeResult .add ("role1,*.*," + privilegeType + ",true," );
493
440
}
@@ -507,20 +454,6 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
507
454
resultSet = userConStatement .executeQuery ("List privileges of role role1" );
508
455
TestUtils .assertResultSetEqual (
509
456
resultSet , "Role,Scope,Privileges,GrantOption," , listRolePrivilegeResult );
510
-
511
- // Do not have grant option
512
- Assert .assertThrows (
513
- SQLException .class ,
514
- () -> {
515
- userConStatement .execute ("GRANT SELECT ON DATABASE TEST to role role1" );
516
- });
517
-
518
- // Do not have grant option
519
- Assert .assertThrows (
520
- SQLException .class ,
521
- () -> {
522
- userConStatement .execute ("GRANT ALL to user test2" );
523
- });
524
457
}
525
458
526
459
try (Connection userCon =
@@ -537,7 +470,7 @@ public void checkGrantRevokeAllPrivileges() throws SQLException {
537
470
538
471
try (Connection adminCon = EnvFactory .getEnv ().getConnection (BaseEnv .TABLE_SQL_DIALECT );
539
472
Statement adminStmt = adminCon .createStatement ()) {
540
- adminStmt .execute ("revoke MANAGE_USER from user test2" );
473
+ adminStmt .execute ("revoke SECURITY from user test2" );
541
474
}
542
475
543
476
try (Connection userCon =
0 commit comments