Skip to content

Commit 940358d

Browse files
author
mpv1989
committed
Add user permission api changes, getDocuments api
1 parent 966caa3 commit 940358d

File tree

7 files changed

+166
-2
lines changed

7 files changed

+166
-2
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ v4.2.2 (xxxx-xx-xx)
22
---------------------------
33
* added ArangoDatabaseAsync.grantAccess(String, Permissions)
44
* added ArangoCollectionAsync.grantAccess(String, Permissions)
5+
* added ArangoDatabaseAsync.resetAccess(String)
6+
* added ArangoCollectionAsync.resetAccess(String)
7+
* added ArangoDBAsync.updateUserDefaultDatabaseAccess(String, Permissions)
8+
* added ArangoDBAsync.updateUserDefaultCollectionAccess(String, Permissions)
9+
* added ArangoCollectionAsync.getDocuments(Collection<String>, Class)
10+
511

612
v4.2.1 (2017-06-20)
713
---------------------------

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ public <T> CompletableFuture<T> getDocument(
235235
return result;
236236
}
237237

238+
/**
239+
* Reads multiple documents
240+
*
241+
* @param keys
242+
* The keys of the documents
243+
* @param type
244+
* The type of the documents (POJO class, VPackSlice or String for Json)
245+
* @return the documents and possible errors
246+
*/
247+
public <T> CompletableFuture<MultiDocumentEntity<T>> getDocuments(
248+
final Collection<String> keys,
249+
final Class<T> type) {
250+
final DocumentReadOptions options = new DocumentReadOptions();
251+
return executor.execute(getDocumentsRequest(keys, options), getDocumentsResponseDeserializer(type, options));
252+
}
253+
238254
/**
239255
* Replaces the document with key with the one in the body, provided there is such a document and no precondition is
240256
* violated
@@ -792,10 +808,39 @@ public CompletableFuture<CollectionRevisionEntity> getRevision() {
792808
* The name of the user
793809
* @param permissions
794810
* The permissions the user grant
811+
* @return void
795812
*/
796-
public CompletableFuture<Void> grantAccess(final String user, final Permissions permissions)
797-
throws ArangoDBException {
813+
public CompletableFuture<Void> grantAccess(final String user, final Permissions permissions) {
798814
return executor.execute(grantAccessRequest(user, permissions), Void.class);
799815
}
800816

817+
/**
818+
* Revokes access to the collection for user user. You need permission to the _system database in order to execute
819+
* this call.
820+
*
821+
* @see <a href=
822+
* "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-collection-access"> API
823+
* Documentation</a>
824+
* @param user
825+
* The name of the user
826+
* @return void
827+
*/
828+
public CompletableFuture<Void> revokeAccess(final String user) {
829+
return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
830+
}
831+
832+
/**
833+
* Clear the collection access level, revert back to the default access level.
834+
*
835+
* @see <a href=
836+
* "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-collection-access"> API
837+
* Documentation</a>
838+
* @param user
839+
* The name of the user
840+
* @return void
841+
*/
842+
public CompletableFuture<Void> resetAccess(final String user) {
843+
return executor.execute(resetAccessRequest(user), Void.class);
844+
}
845+
801846
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.arangodb.entity.ArangoDBVersion;
3535
import com.arangodb.entity.LogEntity;
3636
import com.arangodb.entity.LogLevelEntity;
37+
import com.arangodb.entity.Permissions;
3738
import com.arangodb.entity.ServerRole;
3839
import com.arangodb.entity.UserEntity;
3940
import com.arangodb.internal.ArangoDBConstants;
@@ -575,6 +576,14 @@ public CompletableFuture<UserEntity> replaceUser(final String user, final UserUp
575576
return executor.execute(replaceUserRequest(db().name(), user, options), UserEntity.class);
576577
}
577578

579+
public CompletableFuture<Void> updateUserDefaultDatabaseAccess(final String user, final Permissions permissions) {
580+
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
581+
}
582+
583+
public CompletableFuture<Void> updateUserDefaultCollectionAccess(final String user, final Permissions permissions) {
584+
return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class);
585+
}
586+
578587
/**
579588
* Generic Execute. Use this method to execute custom FOXX services.
580589
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ public CompletableFuture<Void> revokeAccess(final String user) {
253253
return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
254254
}
255255

256+
/**
257+
* Clear the database access level, revert back to the default access level.
258+
*
259+
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-database-access">
260+
* API Documentation</a>
261+
* @param user
262+
* The name of the user
263+
* @return void
264+
*/
265+
public CompletableFuture<Void> resetAccess(final String user) {
266+
return executor.execute(resetAccessRequest(user), Void.class);
267+
}
268+
256269
/**
257270
* Create a cursor and return the first results
258271
*

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@
2727
import static org.hamcrest.Matchers.hasItem;
2828
import static org.hamcrest.Matchers.instanceOf;
2929
import static org.hamcrest.Matchers.is;
30+
import static org.hamcrest.Matchers.isOneOf;
3031
import static org.hamcrest.Matchers.not;
3132
import static org.hamcrest.Matchers.nullValue;
3233
import static org.hamcrest.Matchers.startsWith;
3334
import static org.junit.Assert.assertThat;
3435
import static org.junit.Assert.fail;
3536

3637
import java.util.ArrayList;
38+
import java.util.Arrays;
3739
import java.util.Collection;
40+
import java.util.Collections;
3841
import java.util.HashMap;
3942
import java.util.Map;
4043
import java.util.concurrent.CompletableFuture;
@@ -254,6 +257,41 @@ public void getDocumentWrongKey() throws InterruptedException, ExecutionExceptio
254257
db.collection(COLLECTION_NAME).getDocument("no/no", BaseDocument.class).get();
255258
}
256259

260+
@Test
261+
public void getDocuments() throws InterruptedException, ExecutionException {
262+
final Collection<BaseDocument> values = new ArrayList<>();
263+
values.add(new BaseDocument("1"));
264+
values.add(new BaseDocument("2"));
265+
values.add(new BaseDocument("3"));
266+
db.collection(COLLECTION_NAME).insertDocuments(values).get();
267+
final MultiDocumentEntity<BaseDocument> documents = db.collection(COLLECTION_NAME)
268+
.getDocuments(Arrays.asList("1", "2", "3"), BaseDocument.class).get();
269+
assertThat(documents, is(notNullValue()));
270+
assertThat(documents.getDocuments().size(), is(3));
271+
for (final BaseDocument document : documents.getDocuments()) {
272+
assertThat(document.getId(),
273+
isOneOf(COLLECTION_NAME + "/" + "1", COLLECTION_NAME + "/" + "2", COLLECTION_NAME + "/" + "3"));
274+
}
275+
}
276+
277+
@Test
278+
public void getDocumentsNotFound() throws InterruptedException, ExecutionException {
279+
final MultiDocumentEntity<BaseDocument> readResult = db.collection(COLLECTION_NAME)
280+
.getDocuments(Collections.singleton("no"), BaseDocument.class).get();
281+
assertThat(readResult, is(notNullValue()));
282+
assertThat(readResult.getDocuments().size(), is(0));
283+
assertThat(readResult.getErrors().size(), is(1));
284+
}
285+
286+
@Test
287+
public void getDocumentsWrongKey() throws InterruptedException, ExecutionException {
288+
final MultiDocumentEntity<BaseDocument> readResult = db.collection(COLLECTION_NAME)
289+
.getDocuments(Collections.singleton("no/no"), BaseDocument.class).get();
290+
assertThat(readResult, is(notNullValue()));
291+
assertThat(readResult.getDocuments().size(), is(0));
292+
assertThat(readResult.getErrors().size(), is(1));
293+
}
294+
257295
@Test
258296
public void updateDocument() throws ArangoDBException, InterruptedException, ExecutionException {
259297
final BaseDocument doc = new BaseDocument();
@@ -2059,4 +2097,19 @@ public void revokeAccessUserNotFound() throws InterruptedException, ExecutionExc
20592097
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.NONE).get();
20602098
}
20612099

2100+
@Test
2101+
public void resetAccess() throws InterruptedException, ExecutionException {
2102+
try {
2103+
arangoDB.createUser("user1", "1234", null).get();
2104+
db.collection(COLLECTION_NAME).resetAccess("user1").get();
2105+
} finally {
2106+
arangoDB.deleteUser("user1").get();
2107+
}
2108+
}
2109+
2110+
@Test(expected = ExecutionException.class)
2111+
public void resetAccessUserNotFound() throws InterruptedException, ExecutionException {
2112+
db.collection(COLLECTION_NAME).resetAccess("user1").get();
2113+
}
2114+
20622115
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.arangodb.entity.LogEntity;
4545
import com.arangodb.entity.LogLevel;
4646
import com.arangodb.entity.LogLevelEntity;
47+
import com.arangodb.entity.Permissions;
4748
import com.arangodb.entity.UserEntity;
4849
import com.arangodb.model.LogOptions;
4950
import com.arangodb.model.LogOptions.SortOrder;
@@ -315,6 +316,28 @@ public void replaceUser() throws InterruptedException, ExecutionException {
315316
}
316317
}
317318

319+
@Test
320+
public void updateUserDefaultDatabaseAccess() throws InterruptedException, ExecutionException {
321+
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
322+
try {
323+
arangoDB.createUser(USER, PW).get();
324+
arangoDB.updateUserDefaultDatabaseAccess(USER, Permissions.RW).get();
325+
} finally {
326+
arangoDB.deleteUser(USER).get();
327+
}
328+
}
329+
330+
@Test
331+
public void updateUserDefaultCollectionAccess() throws InterruptedException, ExecutionException {
332+
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();
333+
try {
334+
arangoDB.createUser(USER, PW).get();
335+
arangoDB.updateUserDefaultCollectionAccess(USER, Permissions.RW).get();
336+
} finally {
337+
arangoDB.deleteUser(USER).get();
338+
}
339+
}
340+
318341
@Test
319342
public void authenticationFailPassword() throws InterruptedException, ExecutionException {
320343
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().password("no").build();

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,21 @@ public void revokeAccessUserNotFound() throws InterruptedException, ExecutionExc
384384
db.revokeAccess("user1").get();
385385
}
386386

387+
@Test
388+
public void resetAccess() throws InterruptedException, ExecutionException {
389+
try {
390+
arangoDB.createUser("user1", "1234", null).get();
391+
db.resetAccess("user1").get();
392+
} finally {
393+
arangoDB.deleteUser("user1").get();
394+
}
395+
}
396+
397+
@Test(expected = ExecutionException.class)
398+
public void resetAccessUserNotFound() throws InterruptedException, ExecutionException {
399+
db.resetAccess("user1").get();
400+
}
401+
387402
@Test
388403
public void query() throws InterruptedException, ExecutionException {
389404
try {

0 commit comments

Comments
 (0)