Skip to content

Commit 0644284

Browse files
author
mpv1989
committed
Add resetAccess(String) in ArangoDatabase & ArangoCollection
1 parent bc6bf99 commit 0644284

File tree

7 files changed

+84
-0
lines changed

7 files changed

+84
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ v4.2.2 (xxxx-xx-xx)
22
---------------------------
33
* added ArangoDatabase.grantAccess(String, Permissions)
44
* added ArangoCollection.grantAccess(String, Permissions)
5+
* added ArangoDatabase.resetAccess(String)
6+
* added ArangoCollection.resetAccess(String)
57
* added ArangoCollection.getDocuments(Collection<String>, Class)
68

79
v4.2.1 (2017-06-20)

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,33 @@ public void grantAccess(final String user, final Permissions permissions) throws
842842
executor.execute(grantAccessRequest(user, permissions), Void.class);
843843
}
844844

845+
/**
846+
* Revokes access to the collection for user user. You need permission to the _system database in order to execute
847+
* this call.
848+
*
849+
* @see <a href=
850+
* "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-collection-access"> API
851+
* Documentation</a>
852+
* @param user
853+
* The name of the user
854+
* @throws ArangoDBException
855+
*/
856+
public void revokeAccess(final String user) throws ArangoDBException {
857+
executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
858+
}
859+
860+
/**
861+
* Clear the collection access level, revert back to the default access level.
862+
*
863+
* @see <a href=
864+
* "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-collection-access"> API
865+
* Documentation</a>
866+
* @param user
867+
* The name of the user
868+
* @throws ArangoDBException
869+
*/
870+
public void resetAccess(final String user) throws ArangoDBException {
871+
executor.execute(resetAccessRequest(user), Void.class);
872+
}
873+
845874
}

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ public void revokeAccess(final String user) throws ArangoDBException {
258258
executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class);
259259
}
260260

261+
/**
262+
* Clear the database access level, revert back to the default access level.
263+
*
264+
* @see <a href= "https://docs.arangodb.com/current/HTTP/UserManagement/index.html#grant-or-revoke-database-access">
265+
* API Documentation</a>
266+
* @param user
267+
* The name of the user
268+
* @throws ArangoDBException
269+
*/
270+
public void resetAccess(final String user) throws ArangoDBException {
271+
executor.execute(resetAccessRequest(user), Void.class);
272+
}
273+
261274
/**
262275
* Create a cursor and return the first results
263276
*

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,4 +688,9 @@ protected Request grantAccessRequest(final String user, final Permissions permis
688688
.setBody(
689689
util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions.toString())));
690690
}
691+
692+
protected Request resetAccessRequest(final String user) {
693+
return new Request(ArangoDBConstants.SYSTEM, RequestType.DELETE, executor
694+
.createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, db.name(), name));
695+
}
691696
}

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ protected Request grantAccessRequest(final String user, final Permissions permis
138138
util().serialize(OptionsBuilder.build(new UserAccessOptions(), permissions.toString())));
139139
}
140140

141+
protected Request resetAccessRequest(final String user) {
142+
return new Request(ArangoDBConstants.SYSTEM, RequestType.DELETE,
143+
executor.createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name));
144+
}
145+
141146
protected Request queryRequest(
142147
final String query,
143148
final Map<String, Object> bindVars,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,4 +1884,19 @@ public void revokeAccessUserNotFound() {
18841884
db.collection(COLLECTION_NAME).grantAccess("user1", Permissions.NONE);
18851885
}
18861886

1887+
@Test
1888+
public void resetAccess() {
1889+
try {
1890+
arangoDB.createUser("user1", "1234", null);
1891+
db.collection(COLLECTION_NAME).resetAccess("user1");
1892+
} finally {
1893+
arangoDB.deleteUser("user1");
1894+
}
1895+
}
1896+
1897+
@Test(expected = ArangoDBException.class)
1898+
public void resetAccessUserNotFound() {
1899+
db.collection(COLLECTION_NAME).resetAccess("user1");
1900+
}
1901+
18871902
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,21 @@ public void revokeAccessUserNotFound() {
363363
db.revokeAccess("user1");
364364
}
365365

366+
@Test
367+
public void resetAccess() {
368+
try {
369+
arangoDB.createUser("user1", "1234", null);
370+
db.resetAccess("user1");
371+
} finally {
372+
arangoDB.deleteUser("user1");
373+
}
374+
}
375+
376+
@Test(expected = ArangoDBException.class)
377+
public void resetAccessUserNotFound() {
378+
db.resetAccess("user1");
379+
}
380+
366381
@Test
367382
public void query() {
368383
try {

0 commit comments

Comments
 (0)