Skip to content

Commit 4e4ed43

Browse files
author
Mark
committed
User Post changed (-database), new User-Methode grantDatabaseAccess
1 parent f445ef5 commit 4e4ed43

File tree

6 files changed

+240
-230
lines changed

6 files changed

+240
-230
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ public DefaultEntity createUser(
28592859
final String passwd,
28602860
final Boolean active,
28612861
final Map<String, Object> extra) throws ArangoException {
2862-
return usersDriver.createUser(getDefaultDatabase(), username, passwd, active, extra);
2862+
return usersDriver.createUser(username, passwd, active, extra);
28632863
}
28642864

28652865
/**
@@ -2881,7 +2881,7 @@ public DefaultEntity replaceUser(
28812881
final String passwd,
28822882
final Boolean active,
28832883
final Map<String, Object> extra) throws ArangoException {
2884-
return usersDriver.replaceUser(getDefaultDatabase(), username, passwd, active, extra);
2884+
return usersDriver.replaceUser(username, passwd, active, extra);
28852885
}
28862886

28872887
/**
@@ -2903,7 +2903,7 @@ public DefaultEntity updateUser(
29032903
final String passwd,
29042904
final Boolean active,
29052905
final Map<String, Object> extra) throws ArangoException {
2906-
return usersDriver.updateUser(getDefaultDatabase(), username, passwd, active, extra);
2906+
return usersDriver.updateUser(username, passwd, active, extra);
29072907
}
29082908

29092909
/**
@@ -2915,7 +2915,7 @@ public DefaultEntity updateUser(
29152915
* @throws ArangoException
29162916
*/
29172917
public DefaultEntity deleteUser(final String username) throws ArangoException {
2918-
return usersDriver.deleteUser(getDefaultDatabase(), username);
2918+
return usersDriver.deleteUser(username);
29192919
}
29202920

29212921
/**
@@ -2927,7 +2927,20 @@ public DefaultEntity deleteUser(final String username) throws ArangoException {
29272927
* @throws ArangoException
29282928
*/
29292929
public UserEntity getUser(final String username) throws ArangoException {
2930-
return usersDriver.getUser(getDefaultDatabase(), username);
2930+
return usersDriver.getUser(username);
2931+
}
2932+
2933+
/**
2934+
* Grants the User access to the given database.
2935+
*
2936+
* @param username
2937+
* the username as string
2938+
* @param database
2939+
* @return
2940+
* @throws ArangoException
2941+
*/
2942+
public DefaultEntity grantDatabaseAccess(String username, String database) throws ArangoException {
2943+
return usersDriver.grantDatabaseAccess(username, database);
29312944
}
29322945

29332946
/**

src/main/java/com/arangodb/BaseArangoDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ protected String createEndpointUrl(String database, String str, Object... paths)
407407
return createEndpointUrl(database, newPaths);
408408
}
409409

410-
protected String createUserEndpointUrl(String database, Object... paths) throws ArangoException {
411-
return createEndpointUrl(database, "/_api/user", paths);
410+
protected String createUserEndpointUrl(Object... paths) throws ArangoException {
411+
return createEndpointUrl(null, "/_api/user", paths);
412412
}
413413

414414
protected String createJobEndpointUrl(String database, Object... paths) throws ArangoException {

src/main/java/com/arangodb/InternalUsersDriver.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010
/**
1111
* Created by fbartels on 10/27/14.
1212
*/
13-
public interface InternalUsersDriver extends BaseDriverInterface {
14-
DefaultEntity createUser(String database, String username, String passwd, Boolean active,
15-
Map<String, Object> extra) throws ArangoException;
13+
public interface InternalUsersDriver extends BaseDriverInterface {
14+
DefaultEntity createUser(String username, String passwd, Boolean active, Map<String, Object> extra)
15+
throws ArangoException;
1616

17-
DefaultEntity deleteUser(String database, String username) throws ArangoException;
17+
DefaultEntity deleteUser(String username) throws ArangoException;
1818

19-
UserEntity getUser(String database, String username) throws ArangoException;
19+
UserEntity getUser(String username) throws ArangoException;
2020

21-
UsersEntity getUsers(String database) throws ArangoException;
21+
UsersEntity getUsers() throws ArangoException;
2222

23-
DefaultEntity replaceUser(String database, String username, String passwd, Boolean active,
24-
Map<String, Object> extra) throws ArangoException;
23+
DefaultEntity replaceUser(String username, String passwd, Boolean active, Map<String, Object> extra)
24+
throws ArangoException;
2525

26-
DefaultEntity updateUser(String database, String username, String passwd, Boolean active,
27-
Map<String, Object> extra) throws ArangoException;
26+
DefaultEntity updateUser(String username, String passwd, Boolean active, Map<String, Object> extra)
27+
throws ArangoException;
28+
29+
DefaultEntity grantDatabaseAccess(final String username, final String database) throws ArangoException;
2830
}

src/main/java/com/arangodb/impl/InternalUsersDriverImpl.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,80 +38,77 @@ public class InternalUsersDriverImpl extends BaseArangoDriverImpl implements com
3838
private static final String EXTRA = "extra";
3939
private static final String ACTIVE = "active";
4040
private static final String PW = "passwd";
41-
private static final String USERNAME = "username";
41+
private static final String USERNAME = "user";
42+
private static final String GRANT = "grant";
43+
private static final String DATABASE = "database";
44+
private static final String READ_WRITE = "rw";
4245

4346
InternalUsersDriverImpl(ArangoConfigure configure, HttpManager httpManager) {
4447
super(configure, httpManager);
4548
}
4649

4750
@Override
48-
public DefaultEntity createUser(
49-
String database,
50-
String username,
51-
String passwd,
52-
Boolean active,
53-
Map<String, Object> extra) throws ArangoException {
54-
55-
HttpResponseEntity res = httpManager.doPost(createUserEndpointUrl(database), null, EntityFactory.toJsonString(
51+
public DefaultEntity createUser(String username, String passwd, Boolean active, Map<String, Object> extra)
52+
throws ArangoException {
53+
54+
HttpResponseEntity res = httpManager.doPost(createUserEndpointUrl(), null, EntityFactory.toJsonString(
5655
new MapBuilder().put(USERNAME, username).put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get()));
5756

5857
return createEntity(res, DefaultEntity.class);
5958
}
6059

6160
@Override
62-
public DefaultEntity deleteUser(String database, String username) throws ArangoException {
61+
public DefaultEntity deleteUser(String username) throws ArangoException {
6362

64-
HttpResponseEntity res = httpManager.doDelete(createUserEndpointUrl(database, StringUtils.encodeUrl(username)),
65-
null);
63+
HttpResponseEntity res = httpManager.doDelete(createUserEndpointUrl(StringUtils.encodeUrl(username)), null);
6664

6765
return createEntity(res, DefaultEntity.class);
6866
}
6967

7068
@Override
71-
public UserEntity getUser(String database, String username) throws ArangoException {
69+
public UserEntity getUser(String username) throws ArangoException {
7270

73-
HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(database, StringUtils.encodeUrl(username)),
74-
null);
71+
HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(StringUtils.encodeUrl(username)), null);
7572

7673
return createEntity(res, UserEntity.class);
7774
}
7875

7976
@Override
80-
public UsersEntity getUsers(String database) throws ArangoException {
77+
public UsersEntity getUsers() throws ArangoException {
8178

82-
HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(database), null);
79+
HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(), null);
8380

8481
return createEntity(res, UsersEntity.class);
8582
}
8683

8784
@Override
88-
public DefaultEntity replaceUser(
89-
String database,
90-
String username,
91-
String passwd,
92-
Boolean active,
93-
Map<String, Object> extra) throws ArangoException {
94-
95-
HttpResponseEntity res = httpManager.doPut(createUserEndpointUrl(database, StringUtils.encodeUrl(username)),
96-
null,
85+
public DefaultEntity replaceUser(String username, String passwd, Boolean active, Map<String, Object> extra)
86+
throws ArangoException {
87+
88+
HttpResponseEntity res = httpManager.doPut(createUserEndpointUrl(StringUtils.encodeUrl(username)), null,
9789
EntityFactory.toJsonString(new MapBuilder().put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get()));
9890

9991
return createEntity(res, DefaultEntity.class);
10092
}
10193

10294
@Override
103-
public DefaultEntity updateUser(
104-
String database,
105-
String username,
106-
String passwd,
107-
Boolean active,
108-
Map<String, Object> extra) throws ArangoException {
109-
110-
HttpResponseEntity res = httpManager.doPatch(createUserEndpointUrl(database, StringUtils.encodeUrl(username)),
111-
null,
95+
public DefaultEntity updateUser(String username, String passwd, Boolean active, Map<String, Object> extra)
96+
throws ArangoException {
97+
98+
HttpResponseEntity res = httpManager.doPatch(createUserEndpointUrl(StringUtils.encodeUrl(username)), null,
11299
EntityFactory.toJsonString(new MapBuilder().put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get()));
113100

114101
return createEntity(res, DefaultEntity.class);
115102
}
116103

104+
@Override
105+
public DefaultEntity grantDatabaseAccess(String username, String database) throws ArangoException {
106+
107+
final HttpResponseEntity res = httpManager.doPut(
108+
createUserEndpointUrl(StringUtils.encodeUrl(username), DATABASE, StringUtils.encodeUrl(database)), null,
109+
EntityFactory.toJsonString(new MapBuilder().put(GRANT, READ_WRITE).get()));
110+
111+
return createEntity(res, DefaultEntity.class);
112+
}
113+
117114
}

0 commit comments

Comments
 (0)