Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Intellij
.idea
# Intellij recommends to share iml files, however, better don't share files which might be outdated
*.iml
22 changes: 22 additions & 0 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ This section describes the runtime behavior of the software.

## Creating Database Objects

### Creating Database Users
`dsn~creating-database-users~1`

Users can create database users by providing a username and a password.

Covers:

* `req~creating-users~1`

Needs: impl, utest, itest

### Granting System Privileges to Database Users
`dsn~granting-system-privileges-to-database-users~1`

Users can select and grant System Privileges to created database users from the list of supported System Privileges.

Covers:

* `req~granting-system-privileges-to-users~1`

Needs: impl, utest, itest

### Creating Scripts
`dsn~creating-scripts~1`

Expand Down
22 changes: 22 additions & 0 deletions doc/system_requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ In this section lists functional requirements from the user's perspective. The r

### Creating Database Objects

#### Creating Users
`req~creating-users~1`

Users can create database users through TDDB.

Covers:

* [feat~creating-database-objects~1](#creating-database-objects)

Needs: dsn

### Granting System Privileges to Users
`req~granting-system-privileges-to-users~1`

Users can grant System Privileges to created database users.

Covers:

* [feat~creating-database-objects~1](#creating-database-objects)

Needs: dsn

#### Creating Scripts
`req~creating-scripts~1`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Schema createSchema(final String name) {
}

@Override
// [impl->dsn~creating-database-users~1]
public User createUser(final String name) {
return new User(this.writer, name);
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/exasol/dbbuilder/SystemPrivilege.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
* Privilege as used in a {@code GRANT}.
*/
public enum SystemPrivilege {
CREATE_SESSION, KILL_ANY_SESSION;
GRANT_ANY_OBJECT_PRIVILEGE, GRANT_ANY_PRIVILEGE, GRANT_ANY_PRIORITY_GROUP, MANAGE_PRIORITY_GROUPS, CREATE_SESSION,
KILL_ANY_SESSION, ALTER_SYSTEM, IMPORT, EXPORT, CREATE_USER, ALTER_USER, DROP_USER, IMPERSONATE_ANY_USER,
CREATE_ROLE, DROP_ANY_ROLE, GRANT_ANY_ROLE, CREATE_CONNECTION, ALTER_ANY_CONNECTION, DROP_ANY_CONNECTION,
GRANT_ANY_CONNECTION, USE_ANY_CONNECTION, ACCESS_ANY_CONNECTION, CREATE_SCHEMA, ALTER_ANY_SCHEMA, DROP_ANY_SCHEMA,
CREATE_VIRTUAL_SCHEMA, ALTER_ANY_VIRTUAL_SCHEMA, ALTER_ANY_VIRTUAL_SCHEMA_REFRESH, DROP_ANY_VIRTUAL_SCHEMA,
CREATE_TABLE, CREATE_ANY_TABLE, ALTER_ANY_TABLE, DELETE_ANY_TABLE, DROP_ANY_TABLE, INSERT_ANY_TABLE,
SELECT_ANY_TABLE, SELECT_ANY_DICTIONARY, UPDATE_ANY_TABLE, CREATE_VIEW, CREATE_ANY_VIEW, DROP_ANY_VIEW,
CREATE_FUNCTION, CREATE_ANY_FUNCTION, DROP_ANY_FUNCTION, EXECUTE_ANY_FUNCTION, CREATE_SCRIPT, CREATE_ANY_SCRIPT,
DROP_ANY_SCRIPT, EXECUTE_ANY_SCRIPT;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Verified list complete.


@Override
public String toString() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/exasol/dbbuilder/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public User grant(final DatabaseObject object, final ObjectPrivilege... privileg
* @param privileges system privileges
* @return {@link User} instance for fluent programming
*/
// [impl->dsn~granting-system-privileges-to-database-users~1]
public User grant(final SystemPrivilege... privileges) {
this.systemPrivileges.addAll(Set.of(privileges));
this.writer.write(this, privileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ void testCreateTable() {
}

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

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

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

@Test
// [itest->dsn~granting-system-privileges-to-database-users~1]
void testGrantSystemPrivilegeToUser() {
final User user = this.factory.createUser("SYSPRIVUSER").grant(CREATE_SESSION, KILL_ANY_SESSION);
assertAll(() -> assertUserHasSystemPrivilege(user, CREATE_SESSION),
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/exasol/dbbuilder/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.exasol.dbbuilder.objectwriter.DatabaseObjectWriter;

// [utest->dsn~creating-database-users~1]
@ExtendWith(MockitoExtension.class)
class UserTest {
@Mock
Expand Down Expand Up @@ -57,6 +58,7 @@ void testGetObjectPrivileges(@Mock final DatabaseObject objectMock) {
}

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