Skip to content

Commit 4b550cf

Browse files
Feature/2 add all system privileges (#14)
* #2: added system privileges, requirements and design for them
1 parent 6bd6313 commit 4b550cf

File tree

8 files changed

+66
-1
lines changed

8 files changed

+66
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ buildNumber.properties
99
.mvn/timing.properties
1010
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
1111
.mvn/wrapper/maven-wrapper.jar
12+
13+
# Intellij
14+
.idea
15+
# Intellij recommends to share iml files, however, better don't share files which might be outdated
16+
*.iml

doc/design.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ This section describes the runtime behavior of the software.
4040

4141
## Creating Database Objects
4242

43+
### Creating Database Users
44+
`dsn~creating-database-users~1`
45+
46+
Users can create database users by providing a username and a password.
47+
48+
Covers:
49+
50+
* `req~creating-users~1`
51+
52+
Needs: impl, utest, itest
53+
54+
### Granting System Privileges to Database Users
55+
`dsn~granting-system-privileges-to-database-users~1`
56+
57+
Users can select and grant System Privileges to created database users from the list of supported System Privileges.
58+
59+
Covers:
60+
61+
* `req~granting-system-privileges-to-users~1`
62+
63+
Needs: impl, utest, itest
64+
4365
### Creating Scripts
4466
`dsn~creating-scripts~1`
4567

doc/system_requirements.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ In this section lists functional requirements from the user's perspective. The r
7373

7474
### Creating Database Objects
7575

76+
#### Creating Users
77+
`req~creating-users~1`
78+
79+
Users can create database users through TDDB.
80+
81+
Covers:
82+
83+
* [feat~creating-database-objects~1](#creating-database-objects)
84+
85+
Needs: dsn
86+
87+
### Granting System Privileges to Users
88+
`req~granting-system-privileges-to-users~1`
89+
90+
Users can grant System Privileges to created database users.
91+
92+
Covers:
93+
94+
* [feat~creating-database-objects~1](#creating-database-objects)
95+
96+
Needs: dsn
97+
7698
#### Creating Scripts
7799
`req~creating-scripts~1`
78100

src/main/java/com/exasol/dbbuilder/ExasolObjectFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public Schema createSchema(final String name) {
3838
}
3939

4040
@Override
41+
// [impl->dsn~creating-database-users~1]
4142
public User createUser(final String name) {
4243
return new User(this.writer, name);
4344
}

src/main/java/com/exasol/dbbuilder/SystemPrivilege.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* Privilege as used in a {@code GRANT}.
55
*/
66
public enum SystemPrivilege {
7-
CREATE_SESSION, KILL_ANY_SESSION;
7+
GRANT_ANY_OBJECT_PRIVILEGE, GRANT_ANY_PRIVILEGE, GRANT_ANY_PRIORITY_GROUP, MANAGE_PRIORITY_GROUPS, CREATE_SESSION,
8+
KILL_ANY_SESSION, ALTER_SYSTEM, IMPORT, EXPORT, CREATE_USER, ALTER_USER, DROP_USER, IMPERSONATE_ANY_USER,
9+
CREATE_ROLE, DROP_ANY_ROLE, GRANT_ANY_ROLE, CREATE_CONNECTION, ALTER_ANY_CONNECTION, DROP_ANY_CONNECTION,
10+
GRANT_ANY_CONNECTION, USE_ANY_CONNECTION, ACCESS_ANY_CONNECTION, CREATE_SCHEMA, ALTER_ANY_SCHEMA, DROP_ANY_SCHEMA,
11+
CREATE_VIRTUAL_SCHEMA, ALTER_ANY_VIRTUAL_SCHEMA, ALTER_ANY_VIRTUAL_SCHEMA_REFRESH, DROP_ANY_VIRTUAL_SCHEMA,
12+
CREATE_TABLE, CREATE_ANY_TABLE, ALTER_ANY_TABLE, DELETE_ANY_TABLE, DROP_ANY_TABLE, INSERT_ANY_TABLE,
13+
SELECT_ANY_TABLE, SELECT_ANY_DICTIONARY, UPDATE_ANY_TABLE, CREATE_VIEW, CREATE_ANY_VIEW, DROP_ANY_VIEW,
14+
CREATE_FUNCTION, CREATE_ANY_FUNCTION, DROP_ANY_FUNCTION, EXECUTE_ANY_FUNCTION, CREATE_SCRIPT, CREATE_ANY_SCRIPT,
15+
DROP_ANY_SCRIPT, EXECUTE_ANY_SCRIPT;
816

917
@Override
1018
public String toString() {

src/main/java/com/exasol/dbbuilder/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public User grant(final DatabaseObject object, final ObjectPrivilege... privileg
118118
* @param privileges system privileges
119119
* @return {@link User} instance for fluent programming
120120
*/
121+
// [impl->dsn~granting-system-privileges-to-database-users~1]
121122
public User grant(final SystemPrivilege... privileges) {
122123
this.systemPrivileges.addAll(Set.of(privileges));
123124
this.writer.write(this, privileges);

src/test/java/com/exasol/dbbuilder/DatabaseObjectCreationIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ void testCreateTable() {
196196
}
197197

198198
@Test
199+
// [itest->dsn~creating-database-users~1]
199200
void testCreateUser() {
200201
assertObjectExistsInDatabase(this.factory.createUser("THE_USER"));
201202
}
202203

203204
@Test
205+
// [itest->dsn~creating-database-users~1]
204206
void testCreateLoginUser() throws SQLException {
205207
final User user = this.factory.createLoginUser("LOGIN_USER");
206208
try (final Connection connection = container.createConnectionForUser(user.getName(), user.getPassword())) {
@@ -209,6 +211,7 @@ void testCreateLoginUser() throws SQLException {
209211
}
210212

211213
@Test
214+
// [itest->dsn~creating-database-users~1]
212215
void testCreateLoginUserWithPassword() throws SQLException {
213216
final User user = this.factory.createLoginUser("LOGIN_USER_WITH_PASSWORD", "THE_PASSWORD");
214217
try (final Connection connection = container.createConnectionForUser(user.getName(), user.getPassword())) {
@@ -228,6 +231,7 @@ void testCreateVirtualSchema() {
228231
}
229232

230233
@Test
234+
// [itest->dsn~granting-system-privileges-to-database-users~1]
231235
void testGrantSystemPrivilegeToUser() {
232236
final User user = this.factory.createUser("SYSPRIVUSER").grant(CREATE_SESSION, KILL_ANY_SESSION);
233237
assertAll(() -> assertUserHasSystemPrivilege(user, CREATE_SESSION),

src/test/java/com/exasol/dbbuilder/UserTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import com.exasol.dbbuilder.objectwriter.DatabaseObjectWriter;
1515

16+
// [utest->dsn~creating-database-users~1]
1617
@ExtendWith(MockitoExtension.class)
1718
class UserTest {
1819
@Mock
@@ -57,6 +58,7 @@ void testGetObjectPrivileges(@Mock final DatabaseObject objectMock) {
5758
}
5859

5960
@Test
61+
// [utest->dsn~granting-system-privileges-to-database-users~1]
6062
void testGetSystemPrivileges() {
6163
final User user = new User(this.writerMock, "SYTEMUSER") //
6264
.grant(SystemPrivilege.CREATE_SESSION);

0 commit comments

Comments
 (0)