Skip to content

Commit fddafcf

Browse files
author
mpv1989
committed
Add user permission api changes
1 parent b9c8025 commit fddafcf

File tree

5 files changed

+123
-7
lines changed

5 files changed

+123
-7
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v4.2.2 (xxxx-xx-xx)
2+
---------------------------
3+
* added ArangoDatabaseAsync.grantAccess(String, Permissions)
4+
* added ArangoCollectionAsync.grantAccess(String, Permissions)
5+
16
v4.2.1 (2017-06-20)
27
---------------------------
38
* fixed deserializing of internal field _id

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.arangodb.entity.DocumentUpdateEntity;
3434
import com.arangodb.entity.IndexEntity;
3535
import com.arangodb.entity.MultiDocumentEntity;
36+
import com.arangodb.entity.Permissions;
3637
import com.arangodb.internal.ArangoExecutor.ResponseDeserializer;
3738
import com.arangodb.internal.ArangoExecutorAsync;
3839
import com.arangodb.internal.InternalArangoCollection;
@@ -780,4 +781,21 @@ public CompletableFuture<CollectionRevisionEntity> getRevision() {
780781
return executor.execute(getRevisionRequest(), CollectionRevisionEntity.class);
781782
}
782783

784+
/**
785+
* Grants or revoke access to the collection for user user. You need permission to the _system database in order to
786+
* execute this call.
787+
*
788+
* @see <a href=
789+
* "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-collection-access"> API
790+
* Documentation</a>
791+
* @param user
792+
* The name of the user
793+
* @param permissions
794+
* The permissions the user grant
795+
*/
796+
public CompletableFuture<Void> grantAccess(final String user, final Permissions permissions)
797+
throws ArangoDBException {
798+
return executor.execute(grantAccessRequest(user, permissions), Void.class);
799+
}
800+
783801
}

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.arangodb.entity.EdgeDefinition;
3636
import com.arangodb.entity.GraphEntity;
3737
import com.arangodb.entity.IndexEntity;
38+
import com.arangodb.entity.Permissions;
3839
import com.arangodb.entity.QueryCachePropertiesEntity;
3940
import com.arangodb.entity.QueryEntity;
4041
import com.arangodb.entity.QueryTrackingPropertiesEntity;
@@ -216,24 +217,44 @@ public CompletableFuture<Boolean> drop() {
216217
* API Documentation</a>
217218
* @param user
218219
* The name of the user
220+
* @param permissions
221+
* The permissions the user grant
219222
* @return void
220223
*/
224+
public CompletableFuture<Void> grantAccess(final String user, final Permissions permissions) {
225+
return executor.execute(grantAccessRequest(user, permissions), Void.class);
226+
}
227+
228+
/**
229+
* Grants access to the database dbname for user user. You need permission to the _system database in order to
230+
* execute this call.
231+
*
232+
* @deprecated use {@link #grantAccess(String, Permissions)} instead
233+
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-database-access">
234+
* API Documentation</a>
235+
* @param user
236+
* The name of the user
237+
* @return void
238+
*/
239+
@Deprecated
221240
public CompletableFuture<Void> grantAccess(final String user) {
222-
return executor.execute(grantAccessRequest(user), Void.class);
241+
return executor.execute(grantAccessRequest(user, Permissions.RW), Void.class);
223242
}
224243

225244
/**
226245
* Revokes access to the database dbname for user user. You need permission to the _system database in order to
227246
* execute this call.
228247
*
248+
* @deprecated use {@link #grantAccess(String, Permissions)} instead
229249
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-database-access">
230250
* API Documentation</a>
231251
* @param user
232252
* The name of the user
233253
* @return void
234254
*/
255+
@Deprecated
235256
public CompletableFuture<Void> revokeAccess(final String user) {
236-
return executor.execute(revokeAccessRequest(user), Void.class);
257+
return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
237258
}
238259

239260
/**

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.arangodb.entity.IndexEntity;
5858
import com.arangodb.entity.IndexType;
5959
import com.arangodb.entity.MultiDocumentEntity;
60+
import com.arangodb.entity.Permissions;
6061
import com.arangodb.entity.ServerRole;
6162
import com.arangodb.model.CollectionCreateOptions;
6263
import com.arangodb.model.CollectionPropertiesOptions;
@@ -2008,4 +2009,54 @@ public void getRevision() throws InterruptedException, ExecutionException {
20082009
f.get();
20092010
}
20102011

2012+
@Test
2013+
public void grantAccessRW() throws InterruptedException, ExecutionException {
2014+
try {
2015+
arangoDB.createUser("user1", "1234", null).get();
2016+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.RW).get();
2017+
} finally {
2018+
arangoDB.deleteUser("user1").get();
2019+
}
2020+
}
2021+
2022+
@Test
2023+
public void grantAccessRO() throws InterruptedException, ExecutionException {
2024+
try {
2025+
arangoDB.createUser("user1", "1234", null).get();
2026+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.RO).get();
2027+
} finally {
2028+
arangoDB.deleteUser("user1").get();
2029+
}
2030+
}
2031+
2032+
@Test
2033+
public void grantAccessNONE() throws InterruptedException, ExecutionException {
2034+
try {
2035+
arangoDB.createUser("user1", "1234", null).get();
2036+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.NONE).get();
2037+
} finally {
2038+
arangoDB.deleteUser("user1").get();
2039+
}
2040+
}
2041+
2042+
@Test(expected = ExecutionException.class)
2043+
public void grantAccessUserNotFound() throws InterruptedException, ExecutionException {
2044+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.RW).get();
2045+
}
2046+
2047+
@Test
2048+
public void revokeAccess() throws InterruptedException, ExecutionException {
2049+
try {
2050+
arangoDB.createUser("user1", "1234", null).get();
2051+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.NONE).get();
2052+
} finally {
2053+
arangoDB.deleteUser("user1").get();
2054+
}
2055+
}
2056+
2057+
@Test(expected = ExecutionException.class)
2058+
public void revokeAccessUserNotFound() throws InterruptedException, ExecutionException {
2059+
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.NONE).get();
2060+
}
2061+
20112062
}

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.arangodb.entity.GraphEntity;
6262
import com.arangodb.entity.IndexEntity;
6363
import com.arangodb.entity.PathEntity;
64+
import com.arangodb.entity.Permissions;
6465
import com.arangodb.entity.QueryCachePropertiesEntity;
6566
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
6667
import com.arangodb.entity.QueryEntity;
@@ -324,33 +325,53 @@ public void getCollectionsExcludeSystem() throws InterruptedException, Execution
324325
}
325326

326327
@Test
327-
public void grantAccess() throws InterruptedException, ExecutionException {
328+
public void grantAccessRW() throws InterruptedException, ExecutionException {
328329
try {
329330
arangoDB.createUser("user1", "1234", null).get();
330-
db.grantAccess("user1").get();
331+
db.grantAccess("user1", Permissions.RW).get();
332+
} finally {
333+
arangoDB.deleteUser("user1").get();
334+
}
335+
}
336+
337+
@Test
338+
public void grantAccessRO() throws InterruptedException, ExecutionException {
339+
try {
340+
arangoDB.createUser("user1", "1234", null).get();
341+
db.grantAccess("user1", Permissions.RO).get();
342+
} finally {
343+
arangoDB.deleteUser("user1").get();
344+
}
345+
}
346+
347+
@Test
348+
public void grantAccessNONE() throws InterruptedException, ExecutionException {
349+
try {
350+
arangoDB.createUser("user1", "1234", null).get();
351+
db.grantAccess("user1", Permissions.NONE).get();
331352
} finally {
332353
arangoDB.deleteUser("user1").get();
333354
}
334355
}
335356

336357
@Test(expected = ExecutionException.class)
337358
public void grantAccessUserNotFound() throws InterruptedException, ExecutionException {
338-
db.grantAccess("user1").get();
359+
db.grantAccess("user1", Permissions.RW).get();
339360
}
340361

341362
@Test
342363
public void revokeAccess() throws InterruptedException, ExecutionException {
343364
try {
344365
arangoDB.createUser("user1", "1234", null).get();
345-
db.revokeAccess("user1").get();
366+
db.grantAccess("user1", Permissions.NONE).get();
346367
} finally {
347368
arangoDB.deleteUser("user1").get();
348369
}
349370
}
350371

351372
@Test(expected = ExecutionException.class)
352373
public void revokeAccessUserNotFound() throws InterruptedException, ExecutionException {
353-
db.revokeAccess("user1").get();
374+
db.grantAccess("user1", Permissions.NONE).get();
354375
}
355376

356377
@Test

0 commit comments

Comments
 (0)