Skip to content

Commit cc8c159

Browse files
author
mpv1989
committed
Add user access api calls
* Add ArangoDatabaseAsync.getPermissions(String) * Add ArangoCollectionAsync.getPermissions(String) * Add ArangoDBAsync.grantDefaultDatabaseAccess(String, Permissions) * Add ArangoDBAsync.grantDefaultCollectionAccess(String, Permissions) * Add ArangoDatabaseAsync.grantDefaultCollectionAccess(String, Permissions)
1 parent 1c2427c commit cc8c159

File tree

8 files changed

+131
-5
lines changed

8 files changed

+131
-5
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
v4.2.3 (2017-07-31)
2+
---------------------------
3+
* added ArangoDatabaseAsync.getPermissions(String)
4+
* added ArangoCollectionAsync.getPermissions(String)
5+
* added ArangoDBAsync.grantDefaultDatabaseAccess(String, Permissions)
6+
* added ArangoDBAsync.grantDefaultCollectionAccess(String, Permissions)
7+
* added ArangoDatabaseAsync.grantDefaultCollectionAccess(String, Permissions)
8+
* fixed DateUtil (thread-safe)
9+
110
v4.2.2 (2017-07-20)
211
---------------------------
312
* added ArangoDatabaseAsync.grantAccess(String, Permissions)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.arangodb</groupId>
66
<artifactId>arangodb-java-driver-async</artifactId>
7-
<version>4.2.3-SNAPSHOT</version>
7+
<version>4.2.3</version>
88
<inceptionYear>2016</inceptionYear>
99
<packaging>jar</packaging>
1010

src/main/java/com/arangodb/ArangoCollectionAsync.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,24 @@ public CompletableFuture<Void> revokeAccess(final String user) {
837837
* Documentation</a>
838838
* @param user
839839
* The name of the user
840+
* @since ArangoDB 3.2.0
840841
* @return void
841842
*/
842843
public CompletableFuture<Void> resetAccess(final String user) {
843844
return executor.execute(resetAccessRequest(user), Void.class);
844845
}
845846

847+
/**
848+
* Get the collection access level
849+
*
850+
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/#get-the-specific-collection-access-level">
851+
* API Documentation</a>
852+
* @param user
853+
* The name of the user
854+
* @return permissions of the user
855+
* @since ArangoDB 3.2.0
856+
*/
857+
public CompletableFuture<Permissions> getPermissions(final String user) throws ArangoDBException {
858+
return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer());
859+
}
846860
}

src/main/java/com/arangodb/ArangoDBAsync.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,68 @@ public CompletableFuture<UserEntity> replaceUser(final String user, final UserUp
576576
return executor.execute(replaceUserRequest(db().name(), user, options), UserEntity.class);
577577
}
578578

579+
/**
580+
* @deprecated use {@link #grantDefaultDatabaseAccess(String, Permissions)} instead
581+
*
582+
* @param user
583+
* The name of the user
584+
* @param permissions
585+
* The permissions the user grant
586+
* @since ArangoDB 3.2.0
587+
* @return void
588+
*/
589+
@Deprecated
579590
public CompletableFuture<Void> updateUserDefaultDatabaseAccess(final String user, final Permissions permissions) {
580591
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
581592
}
582593

594+
/**
595+
* Sets the default access level for databases for the user <code>user</code>. You need permission to the _system
596+
* database in order to execute this call.
597+
*
598+
* @param user
599+
* The name of the user
600+
* @param permissions
601+
* The permissions the user grant
602+
* @since ArangoDB 3.2.0
603+
* @return void
604+
*/
605+
public CompletableFuture<Void> grantDefaultDatabaseAccess(final String user, final Permissions permissions)
606+
throws ArangoDBException {
607+
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
608+
}
609+
610+
/**
611+
* @deprecated user {@link #grantDefaultCollectionAccess(String, Permissions)} instead
612+
*
613+
* @param user
614+
* The name of the user
615+
* @param permissions
616+
* The permissions the user grant
617+
* @since ArangoDB 3.2.0
618+
* @return void
619+
*/
620+
@Deprecated
583621
public CompletableFuture<Void> updateUserDefaultCollectionAccess(final String user, final Permissions permissions) {
584622
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
585623
}
586624

625+
/**
626+
* Sets the default access level for collections for the user <code>user</code>. You need permission to the _system
627+
* database in order to execute this call.
628+
*
629+
* @param user
630+
* The name of the user
631+
* @param permissions
632+
* The permissions the user grant
633+
* @since ArangoDB 3.2.0
634+
* @return void
635+
*/
636+
public CompletableFuture<Void> grantDefaultCollectionAccess(final String user, final Permissions permissions)
637+
throws ArangoDBException {
638+
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
639+
}
640+
587641
/**
588642
* Generic Execute. Use this method to execute custom FOXX services.
589643
*

src/main/java/com/arangodb/ArangoDatabaseAsync.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,56 @@ public CompletableFuture<Void> revokeAccess(final String user) {
260260
* API Documentation</a>
261261
* @param user
262262
* The name of the user
263+
* @since ArangoDB 3.2.0
263264
* @return void
264265
*/
265266
public CompletableFuture<Void> resetAccess(final String user) {
266267
return executor.execute(resetAccessRequest(user), Void.class);
267268
}
268269

270+
/**
271+
* Sets the default access level for collections within this database for the user <code>user</code>. You need
272+
* permission to the _system database in order to execute this call.
273+
*
274+
* @param user
275+
* The name of the user
276+
* @param permissions
277+
* The permissions the user grant
278+
* @since ArangoDB 3.2.0
279+
* @throws ArangoDBException
280+
*/
281+
public CompletableFuture<Void> grantDefaultCollectionAccess(final String user, final Permissions permissions)
282+
throws ArangoDBException {
283+
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
284+
}
285+
286+
/**
287+
* @deprecated use {@link #grantDefaultCollectionAccess(String, Permissions)} instead
288+
* @param user
289+
* The name of the user
290+
* @param permissions
291+
* The permissions the user grant
292+
* @since ArangoDB 3.2.0
293+
*/
294+
@Deprecated
269295
public CompletableFuture<Void> updateUserDefaultCollectionAccess(final String user, final Permissions permissions) {
270296
return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class);
271297
}
272298

299+
/**
300+
* Get specific database access level
301+
*
302+
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/#get-the-database-access-level"> API
303+
* Documentation</a>
304+
* @param user
305+
* The name of the user
306+
* @return permissions of the user
307+
* @since ArangoDB 3.2.0
308+
*/
309+
public CompletableFuture<Permissions> getPermissions(final String user) throws ArangoDBException {
310+
return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer());
311+
}
312+
273313
/**
274314
* Create a cursor and return the first results
275315
*

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,4 +2112,8 @@ public void resetAccessUserNotFound() throws InterruptedException, ExecutionExce
21122112
db.collection(COLLECTION_NAME).resetAccess("user1").get();
21132113
}
21142114

2115+
@Test
2116+
public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException {
2117+
assertThat(Permissions.RW, is(db.collection(COLLECTION_NAME).getPermissions("root").get()));
2118+
}
21152119
}

src/test/java/com/arangodb/ArangoDBTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void updateUserDefaultDatabaseAccess() throws InterruptedException, Execu
321321
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
322322
try {
323323
arangoDB.createUser(USER, PW).get();
324-
arangoDB.updateUserDefaultDatabaseAccess(USER, Permissions.RW).get();
324+
arangoDB.grantDefaultDatabaseAccess(USER, Permissions.RW).get();
325325
} finally {
326326
arangoDB.deleteUser(USER).get();
327327
}
@@ -332,7 +332,7 @@ public void updateUserDefaultCollectionAccess() throws InterruptedException, Exe
332332
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
333333
try {
334334
arangoDB.createUser(USER, PW).get();
335-
arangoDB.updateUserDefaultCollectionAccess(USER, Permissions.RW).get();
335+
arangoDB.grantDefaultCollectionAccess(USER, Permissions.RW).get();
336336
} finally {
337337
arangoDB.deleteUser(USER).get();
338338
}

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,20 @@ public void resetAccessUserNotFound() throws InterruptedException, ExecutionExce
400400
}
401401

402402
@Test
403-
public void updateUserDefaultCollectionAccess() throws InterruptedException, ExecutionException {
403+
public void grantDefaultCollectionAccess() throws InterruptedException, ExecutionException {
404404
try {
405405
arangoDB.createUser("user1", "1234").get();
406-
db.updateUserDefaultCollectionAccess("user1", Permissions.RW).get();
406+
db.grantDefaultCollectionAccess("user1", Permissions.RW).get();
407407
} finally {
408408
arangoDB.deleteUser("user1").get();
409409
}
410410
}
411411

412+
@Test
413+
public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException {
414+
assertThat(Permissions.RW, is(db.getPermissions("root").get()));
415+
}
416+
412417
@Test
413418
public void query() throws InterruptedException, ExecutionException {
414419
try {

0 commit comments

Comments
 (0)