Skip to content

Commit

Permalink
Add user access api calls
Browse files Browse the repository at this point in the history
* Add ArangoDatabaseAsync.getPermissions(String)
* Add ArangoCollectionAsync.getPermissions(String)
* Add ArangoDBAsync.grantDefaultDatabaseAccess(String, Permissions)
* Add ArangoDBAsync.grantDefaultCollectionAccess(String, Permissions)
* Add ArangoDatabaseAsync.grantDefaultCollectionAccess(String,
Permissions)
  • Loading branch information
mpv1989 committed Jul 31, 2017
1 parent 1c2427c commit cc8c159
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v4.2.3 (2017-07-31)
---------------------------
* added ArangoDatabaseAsync.getPermissions(String)
* added ArangoCollectionAsync.getPermissions(String)
* added ArangoDBAsync.grantDefaultDatabaseAccess(String, Permissions)
* added ArangoDBAsync.grantDefaultCollectionAccess(String, Permissions)
* added ArangoDatabaseAsync.grantDefaultCollectionAccess(String, Permissions)
* fixed DateUtil (thread-safe)

v4.2.2 (2017-07-20)
---------------------------
* added ArangoDatabaseAsync.grantAccess(String, Permissions)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver-async</artifactId>
<version>4.2.3-SNAPSHOT</version>
<version>4.2.3</version>
<inceptionYear>2016</inceptionYear>
<packaging>jar</packaging>

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/arangodb/ArangoCollectionAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,24 @@ public CompletableFuture<Void> revokeAccess(final String user) {
* Documentation</a>
* @param user
* The name of the user
* @since ArangoDB 3.2.0
* @return void
*/
public CompletableFuture<Void> resetAccess(final String user) {
return executor.execute(resetAccessRequest(user), Void.class);
}

/**
* Get the collection access level
*
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/#get-the-specific-collection-access-level">
* API Documentation</a>
* @param user
* The name of the user
* @return permissions of the user
* @since ArangoDB 3.2.0
*/
public CompletableFuture<Permissions> getPermissions(final String user) throws ArangoDBException {
return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer());
}
}
54 changes: 54 additions & 0 deletions src/main/java/com/arangodb/ArangoDBAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,68 @@ public CompletableFuture<UserEntity> replaceUser(final String user, final UserUp
return executor.execute(replaceUserRequest(db().name(), user, options), UserEntity.class);
}

/**
* @deprecated use {@link #grantDefaultDatabaseAccess(String, Permissions)} instead
*
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
* @return void
*/
@Deprecated
public CompletableFuture<Void> updateUserDefaultDatabaseAccess(final String user, final Permissions permissions) {
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
}

/**
* Sets the default access level for databases for the user <code>user</code>. You need permission to the _system
* database in order to execute this call.
*
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
* @return void
*/
public CompletableFuture<Void> grantDefaultDatabaseAccess(final String user, final Permissions permissions)
throws ArangoDBException {
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
}

/**
* @deprecated user {@link #grantDefaultCollectionAccess(String, Permissions)} instead
*
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
* @return void
*/
@Deprecated
public CompletableFuture<Void> updateUserDefaultCollectionAccess(final String user, final Permissions permissions) {
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
}

/**
* Sets the default access level for collections for the user <code>user</code>. You need permission to the _system
* database in order to execute this call.
*
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
* @return void
*/
public CompletableFuture<Void> grantDefaultCollectionAccess(final String user, final Permissions permissions)
throws ArangoDBException {
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
}

/**
* Generic Execute. Use this method to execute custom FOXX services.
*
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/arangodb/ArangoDatabaseAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,56 @@ public CompletableFuture<Void> revokeAccess(final String user) {
* API Documentation</a>
* @param user
* The name of the user
* @since ArangoDB 3.2.0
* @return void
*/
public CompletableFuture<Void> resetAccess(final String user) {
return executor.execute(resetAccessRequest(user), Void.class);
}

/**
* Sets the default access level for collections within this database for the user <code>user</code>. You need
* permission to the _system database in order to execute this call.
*
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
* @throws ArangoDBException
*/
public CompletableFuture<Void> grantDefaultCollectionAccess(final String user, final Permissions permissions)
throws ArangoDBException {
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
}

/**
* @deprecated use {@link #grantDefaultCollectionAccess(String, Permissions)} instead
* @param user
* The name of the user
* @param permissions
* The permissions the user grant
* @since ArangoDB 3.2.0
*/
@Deprecated
public CompletableFuture<Void> updateUserDefaultCollectionAccess(final String user, final Permissions permissions) {
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
}

/**
* Get specific database access level
*
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/#get-the-database-access-level"> API
* Documentation</a>
* @param user
* The name of the user
* @return permissions of the user
* @since ArangoDB 3.2.0
*/
public CompletableFuture<Permissions> getPermissions(final String user) throws ArangoDBException {
return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer());
}

/**
* Create a cursor and return the first results
*
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2112,4 +2112,8 @@ public void resetAccessUserNotFound() throws InterruptedException, ExecutionExce
db.collection(COLLECTION_NAME).resetAccess("user1").get();
}

@Test
public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException {
assertThat(Permissions.RW, is(db.collection(COLLECTION_NAME).getPermissions("root").get()));
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/arangodb/ArangoDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void updateUserDefaultDatabaseAccess() throws InterruptedException, Execu
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
try {
arangoDB.createUser(USER, PW).get();
arangoDB.updateUserDefaultDatabaseAccess(USER, Permissions.RW).get();
arangoDB.grantDefaultDatabaseAccess(USER, Permissions.RW).get();
} finally {
arangoDB.deleteUser(USER).get();
}
Expand All @@ -332,7 +332,7 @@ public void updateUserDefaultCollectionAccess() throws InterruptedException, Exe
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
try {
arangoDB.createUser(USER, PW).get();
arangoDB.updateUserDefaultCollectionAccess(USER, Permissions.RW).get();
arangoDB.grantDefaultCollectionAccess(USER, Permissions.RW).get();
} finally {
arangoDB.deleteUser(USER).get();
}
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/com/arangodb/ArangoDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,20 @@ public void resetAccessUserNotFound() throws InterruptedException, ExecutionExce
}

@Test
public void updateUserDefaultCollectionAccess() throws InterruptedException, ExecutionException {
public void grantDefaultCollectionAccess() throws InterruptedException, ExecutionException {
try {
arangoDB.createUser("user1", "1234").get();
db.updateUserDefaultCollectionAccess("user1", Permissions.RW).get();
db.grantDefaultCollectionAccess("user1", Permissions.RW).get();
} finally {
arangoDB.deleteUser("user1").get();
}
}

@Test
public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException {
assertThat(Permissions.RW, is(db.getPermissions("root").get()));
}

@Test
public void query() throws InterruptedException, ExecutionException {
try {
Expand Down

0 comments on commit cc8c159

Please sign in to comment.