用户与鉴权

权限分配与策略

创建策略

创建策略sales,赋予defaut图集QUERY权限

CreatePolicyRequest request = new CreatePolicyRequest();
request.setName("sales");
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("QUERY"));
request.setGraphPrivileges(Arrays.asList(privilege));
client.createPolicy(request);

创建策略sales1,赋予defaut图集INSERT权限,并拥有sales所有权限

CreatePolicyRequest request = new CreatePolicyRequest();
request.setName("sales1");
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("INSERT"));
request.setGraphPrivileges(Arrays.asList(privilege));
request.setPolicies(Arrays.asList("sales"));
client.createPolicy(request);

更新策略

修改salas,修改其拥有default图集权限QUERY,INSERT

UpdatePolicyRequest request = new UpdatePolicyRequest();
request.setName("sales");
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("QUERY", "UPDATE"));
request.setGraphPrivileges(Arrays.asList(privilege));
client.updatePolicy(request);

删除策略

删除sales1策略:

DeletePolicyRequest request = new DeletePolicyRequest();
request.setName("sales1");
client.deletePolicy(request);

列出所有策略

列出所有策略:

List<Table> tables = client.listPolicy();

查看策略详情

查看sales策略详情:

List<PairValue> values = client.getPolicy("sales");

分配权限和策略

给用户company分配defaut图集权限QUERY,UPDATE和策略sales:

GrantRequest request = new GrantRequest();
request.setUsername("company");
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("QUERY", "UPDATE"));
request.setGraphPrivileges(Arrays.asList(privilege));
request.setPolicies(Arrays.asList("sales"));
client.grant(request);

撤回权限和策略

RevokeRequest request = new RevokeRequest();
request.setUsername("company");
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("QUERY", "UPDATE"));
request.setGraphPrivileges(Arrays.asList(privilege));
request.setPolicies(Arrays.asList("sales"));
client.revoke(request);

列出权限表

List<Table> tables = client.listPrivilege();

用户信息管理

查看用户列表

List<Table> tables = client.listUser();

获取用户详细信息

List<PairValue> values = client.getUser(username);

获取当前登录的用户详细信息

List<PairValue> values = client.getSelfInfo();

创建用户

创建用户指定用户名和密码:

CreateUserRequest request = new CreateUserRequest();
request.setUsername(username);
request.setPassword(password);
client.createUser(request);

创建用户并赋予策略sales,default图集的QUERY与UPDATE权限:

CreateUserRequest request = new CreateUserRequest();
request.setUsername(username);
request.setPassword(password);
Privilege privilege = new Privilege();
privilege.setGraphName("default");
privilege.setPrivileges(Arrays.asList("QUERY", "UPDATE"));
request.setGraphPrivileges(Arrays.asList(privilege));
request.setPolicies(Arrays.asList("sales"));
client.createUser(request);

修改用户

修改密码:

UpdateUserRequest request = new UpdateUserRequest();
request.setUsername(username);
request.setPassword(newpassword);
client.updateUser(request);

删除用户

client.deleteUser(username);