修改密码

请输入密码
请输入密码 请输入8-64长度密码 和 email 地址不相同 至少包括数字、大写字母、小写字母、半角符号中的 3 个
请输入密码
提交

修改昵称

当前昵称:
提交

申请证书

证书详情

Please complete this required field.

  • Ultipa Graph V4

Standalone

Please complete this required field.

Please complete this required field.

服务器的MAC地址

Please complete this required field.

Please complete this required field.

取消
申请
ID
产品
状态
核数
申请天数
审批时间
过期时间
MAC地址
申请理由
审核信息
关闭
基础信息
  • 用户昵称:
  • 手机号:
  • 公司名称:
  • 公司邮箱:
  • 地区:
  • 语言:
修改密码
申请证书

当前未申请证书.

申请证书
Certificate Issued at Valid until Serial No. File
Serial No. Valid until File

Not having one? Apply now! >>>

ProductName CreateTime ID Price File
ProductName CreateTime ID Price File

No Invoice

搜索

      访问管理

      本节为您介绍如何使用Connection对象的方法管理对实例和其中图集的访问,包括权限、策略和用户。

      每个示例主要展示如何使用所列方法。点击完整示例查看完整代码示例。

      权限

      showPrivilege()

      获取全部系统权限和图权限,也就是基于操作范围分类的嬴图GQL命令名称。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • Privilege:全部系统权限和图权限。

      // 获取全部系统权限和图权限
      
      Privilege privilege = client.showPrivilege();
      System.out.println("System privileges: " + privilege.getSystemPrivileges());
      System.out.println("Graph privileges: " + privilege.getGraphPrivileges());
      

      System privileges: [TRUNCATE, COMPACT, CREATE_GRAPH, SHOW_GRAPH, DROP_GRAPH, ALTER_GRAPH, MOUNT_GRAPH, UNMOUNT_GRAPH, TOP, KILL, STAT, SHOW_POLICY, CREATE_POLICY, DROP_POLICY, ALTER_POLICY, SHOW_USER, CREATE_USER, DROP_USER, ALTER_USER, GRANT, REVOKE, SHOW_PRIVILEGE]
      Graph privileges: [TEMPLATE, KHOP, AB, SPREAD, AUTONET, FIND, FIND_NODE, FIND_EDGE, INSERT, EXPORT, UPSERT, UPDATE, DELETE, DELETE_NODE, DELETE_EDGE, CREATE_SCHEMA, DROP_SCHEMA, ALTER_SCHEMA, SHOW_SCHEMA, CREATE_TRIGGER, DROP_TRIGGER, SHOW_TRIGGER, CREATE_BACKUP, RESTORE_BACKUP, SHOW_BACKUP, CREATE_PROPERTY, DROP_PROPERTY, ALTER_PROPERTY, SHOW_PROPERTY, CREATE_FULLTEXT, DROP_FULLTEXT, SHOW_FULLTEXT, CREATE_INDEX, DROP_INDEX, SHOW_INDEX, LTE, UFE, CLEAR_TASK, STOP_TASK, PAUSE_TASK, RESUME_TASK, SHOW_TASK, ALGO, SHOW_ALGO]
      

      策略

      showPolicy()

      获取实例上的全部策略。策略包括系统权限、图权限、属性权限和其他策略。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • List<Policy>:实例上的全部策略列表。

      // 获取全部策略并打印其信息
      
      List<Policy> policyList = client.showPolicy();
      for (Policy policy : policyList) {
          System.out.println("Policy '" + policy.getName() + "' include:");
          System.out.println("- System privileges: " + policy.getSystemPrivileges());
          System.out.println("- Graph privileges: " + policy.getGraphPrivileges());
          System.out.println("- Property privileges: " + policy.getPropertyPrivileges());
          System.out.println("- Policies: " + policy.getPolicies());
      }
      

      Policy 'manager' include:
      - System privileges: [DROP_POLICY, COMPACT]
      - Graph privileges: {*=[CREATE_INDEX, DROP_TRIGGER, CREATE_FULLTEXT]}
      - Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[], deny=[]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[]))
      - Policies: [operator]
      Policy 'operator' include:
      - System privileges: [MOUNT_GRAPH, TRUNCATE, SHOW_GRAPH]
      - Graph privileges: {miniCircle=[UPDATE, INSERT, TEMPLATE, UPSERT, AUTONET]}
      - Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=account, propertyName=*)], deny=[]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[]))
      - Policies: []
      

      getPolicy()

      根据名称获取实例上的策略。

      参数:

      • String:策略名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • Policy:获取到的策略。

      // 获取策略operator并打印其信息
      
      Policy policy = client.getPolicy("operator");
      System.out.println("Policy '" + policy.getName() + "' include:");
      System.out.println("- System privileges: " + policy.getSystemPrivileges());
      System.out.println("- Graph privileges: " + policy.getGraphPrivileges());
      System.out.println("- Property privileges: " + policy.getPropertyPrivileges());
      System.out.println("- Policies: " + policy.getPolicies());
      

      Policy 'operator' include:
      - System privileges: [MOUNT_GRAPH, TRUNCATE, SHOW_GRAPH]
      - Graph privileges: {miniCircle=[UPDATE, INSERT, TEMPLATE, UPSERT, AUTONET]}
      - Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=account, propertyName=*)], deny=[]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[]))
      - Policies: []
      

      createPolicy()

      在实例中创建一个策略。

      参数:

      • Policy:待创建的策略;必须设置name字段,systemPrivileges字段、graphPrivileges字段、propertyPrivilege字段和policies字段可选。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 新建策略sales并获取该策略
      
      Policy policy = new Policy();
      policy.setName("sales");
      
      // 系统权限
      policy.setSystemPrivileges(Lists.newArrayList("SHOW_GRAPH","TRUNCATE"));
      
      // 图权限
      Map<String,List<String>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList("FIND","SPREAD","AUTONET","AB","TEMPLATE","KHOP"));
      graphPrivileges.put("lcc", Lists.newArrayList("UPDATE","INSERT","DELETE","UPSERT"));
      policy.setGraphPrivileges(graphPrivileges);
      
      // 属性权限
      PropertyPrivilege propertyPrivilege = new PropertyPrivilege();
      
      PropertyPrivilegeElement node = new PropertyPrivilegeElement();
      PropertyPrivilegeValue nodeValue1 = new PropertyPrivilegeValue();
      nodeValue1.setGraphName("miniCircle");
      nodeValue1.setSchemaName("account");
      PropertyPrivilegeValue nodeValue2 = new PropertyPrivilegeValue();
      nodeValue2.setGraphName("miniCircle");
      nodeValue2.setSchemaName("movie");
      nodeValue2.setPropertyName("name");
      PropertyPrivilegeValue nodeValue3 = new PropertyPrivilegeValue();
      nodeValue3.setGraphName("lcc");
      nodeValue3.setSchemaName("*");
      nodeValue3.setPropertyName("*");
      node.setRead(Lists.newArrayList(nodeValue1,nodeValue2));
      node.setWrite(Lists.newArrayList(nodeValue3));
      propertyPrivilege.setNode(node);
      
      PropertyPrivilegeElement edge = new PropertyPrivilegeElement();
      PropertyPrivilegeValue edgeValue1 = new PropertyPrivilegeValue();
      edgeValue1.setGraphName("*");
      PropertyPrivilegeValue edgeValue2 = new PropertyPrivilegeValue();
      edgeValue2.setGraphName("miniCircle");
      edgeValue2.setSchemaName("*");
      edgeValue2.setPropertyName("*");
      edge.setRead(Lists.newArrayList(edgeValue1));
      edge.setWrite(Lists.newArrayList(edgeValue2));
      propertyPrivilege.setEdge(edge);
      
      policy.setPropertyPrivileges(propertyPrivilege);
      
      // 策略
      policy.setPolicies(Lists.newArrayList("manager", "operator"));
      
      Response response = client.createPolicy(policy);
      System.out.println(response.getStatus().getErrorCode());
      
      Thread.sleep(3000);
      
      Policy policy1 = client.getPolicy("sales");
      System.out.println("Policy '" + policy1.getName() + "' include:");
      System.out.println("- System privileges: " + policy1.getSystemPrivileges());
      System.out.println("- Graph privileges: " + policy1.getGraphPrivileges());
      System.out.println("- Property privileges: " + policy1.getPropertyPrivileges());
      System.out.println("- Policies: " + policy1.getPolicies());
      

      SUCCESS
      Policy 'sales' include:
      - System privileges: [SHOW_GRAPH, TRUNCATE]
      - Graph privileges: {miniCircle=[FIND, SPREAD, AUTONET, AB, TEMPLATE, KHOP], lcc=[UPDATE, INSERT, DELETE, UPSERT]}
      - Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=account, propertyName=*), PropertyPrivilegeValue(graphName=miniCircle, schemaName=movie, propertyName=name)], write=[PropertyPrivilegeValue(graphName=lcc, schemaName=*, propertyName=*)], deny=[]), edge=PropertyPrivilegeElement(read=[PropertyPrivilegeValue(graphName=*, schemaName=*, propertyName=*)], write=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=*, propertyName=*)], deny=[]))
      - Policies: [manager, operator]
      

      alterPolicy()

      根据名称,修改实例中已有策略的系统权限、图权限、属性权限和其他策略。

      参数:

      • Policy:待修改的策略;必须设置name 字段,systemPrivileges字段、graphPrivileges字段、propertyPrivilege字段和policies字段可选。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 修改策略sales并获取该策略
      
      Policy policy = new Policy();
      policy.setName("sales");
      
      // 系统权限
      policy.setSystemPrivileges(Lists.newArrayList("SHOW_GRAPH"));
      
      // 图权限
      Map<String,List<String>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList("FIND"));
      graphPrivileges.put("lcc", Lists.newArrayList("UPDATE"));
      policy.setGraphPrivileges(graphPrivileges);
      
      // 策略
      policy.setPolicies(Lists.newArrayList("operator"));
      
      Response response = client.alterPolicy(policy);
      System.out.println(response.getStatus().getErrorCode());
      
      Thread.sleep(3000);
      
      Policy policy1 = client.getPolicy("sales");
      System.out.println("Policy '" + policy1.getName() + "' include:");
      System.out.println("- System privileges: " + policy1.getSystemPrivileges());
      System.out.println("- Graph privileges: " + policy1.getGraphPrivileges());
      System.out.println("- Property privileges: " + policy1.getPropertyPrivileges());
      System.out.println("- Policies: " + policy1.getPolicies());
      

      SUCCESS
      Policy 'sales' include:
      - System privileges: [SHOW_GRAPH]
      - Graph privileges: {miniCircle=[FIND], lcc=[UPDATE]}
      - Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=account, propertyName=*), PropertyPrivilegeValue(graphName=miniCircle, schemaName=movie, propertyName=name)], write=[PropertyPrivilegeValue(graphName=lcc, schemaName=*, propertyName=*)], deny=[]), edge=PropertyPrivilegeElement(read=[PropertyPrivilegeValue(graphName=*, schemaName=*, propertyName=*)], write=[PropertyPrivilegeValue(graphName=miniCircle, schemaName=*, propertyName=*)], deny=[]))
      - Policies: [operator]
      

      dropPolicy()

      根据名称删除实例中的一个策略。

      参数:

      • String:策略名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 删除策略sales并打印错误代码
      
      Response response = client.dropPolicy("sales");
      System.out.println(response.getStatus().getErrorCode());
      

      SUCCESS
      

      用户

      showUser()

      获取实例上的全部数据库用户。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • List<User>:实例上的全部用户列表。

      // 获取全部用户并打印第一个返回的用户访问信息
      
      List<User> userList = client.showUser();
      System.out.println("Username: " + userList.get(0).getUsername());
      System.out.println("Created on: " + userList.get(0).getCreate());
      System.out.println("System privileges: " + userList.get(0).getSystemPrivileges());
      System.out.println("Graph privileges: " + userList.get(0).getGraphPrivileges());
      System.out.println("Property privileges: " + userList.get(0).getPropertyPrivileges());
      System.out.println("Policies: " + userList.get(0).getPolicies());
      

      Username: test006
      Created on: Fri Sep 01 14:37:56 CST 2023
      System privileges: [SHOW_PRIVILEGE, ALTER_USER, DROP_USER, CREATE_USER, SHOW_GRAPH, ALTER_GRAPH, DROP_GRAPH, COMPACT, MOUNT_GRAPH, TOP, CREATE_GRAPH, STAT, UNMOUNT_GRAPH, SHOW_POLICY, TRUNCATE, KILL, ALTER_POLICY, CREATE_POLICY, DROP_POLICY, SHOW_USER]
      Graph privileges: {miniCircle831=[SHOW_ALGO, DROP_SCHEMA, ALTER_PROPERTY, ALGO, CREATE_PROPERTY, SHOW_SCHEMA, FIND, DROP_PROPERTY, RESUME_TASK, UPDATE, EXPORT, KHOP, SHOW_INDEX, TEMPLATE, CREATE_SCHEMA, SHOW_TASK, ALTER_SCHEMA, AUTONET, SHOW_TRIGGER, LTE, CREATE_TRIGGER, UFE, DROP_TRIGGER, UPSERT, SHOW_PROPERTY, DELETE, CREATE_FULLTEXT, SPREAD, DROP_FULLTEXT, INSERT, CREATE_INDEX, DROP_INDEX, CLEAR_TASK, SHOW_FULLTEXT, STOP_TASK, AB, PAUSE_TASK]}
      Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[], deny=[PropertyPrivilegeValue(graphName=*, schemaName=*, propertyName=*)]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[PropertyPrivilegeValue(graphName=*, schemaName=*, propertyName=*)]))
      Policies: [operator]
      

      getUser()

      根据用户名获取实例上的数据库用户。

      参数:

      • String:用户名。
      • RequestConfig(可选):配置请求。

      返回值:

      • User:获取到的用户。

      // 获取用户test005并打印其访问信息
      
      User user = client.getUser("test005");
      System.out.println("Username: " + user.getUsername());
      System.out.println("Created on: " + user.getCreate());
      System.out.println("System privileges: " + user.getSystemPrivileges());
      System.out.println("Graph privileges: " + user.getGraphPrivileges());
      System.out.println("Property privileges: " + user.getPropertyPrivileges());
      System.out.println("Policies: " + user.getPolicies());
      

      Username: test005
      Created on: Thu Aug 31 17:15:59 CST 2023
      System privileges: [SHOW_PRIVILEGE, ALTER_USER, DROP_USER, CREATE_USER, SHOW_GRAPH, ALTER_GRAPH, DROP_GRAPH, COMPACT, MOUNT_GRAPH, TOP, CREATE_GRAPH, STAT, UNMOUNT_GRAPH, SHOW_POLICY, TRUNCATE, KILL, ALTER_POLICY, CREATE_POLICY, DROP_POLICY, SHOW_USER]
      Graph privileges: {miniCircle831=[SHOW_ALGO, DROP_SCHEMA, ALTER_PROPERTY, ALGO, CREATE_PROPERTY, SHOW_SCHEMA, FIND, DROP_PROPERTY, RESUME_TASK, UPDATE, EXPORT, KHOP, SHOW_INDEX, TEMPLATE, CREATE_SCHEMA, SHOW_TASK, ALTER_SCHEMA, AUTONET, SHOW_TRIGGER, LTE, CREATE_TRIGGER, UFE, DROP_TRIGGER, UPSERT, SHOW_PROPERTY, DELETE, CREATE_FULLTEXT, SPREAD, DROP_FULLTEXT, INSERT, CREATE_INDEX, DROP_INDEX, CLEAR_TASK, SHOW_FULLTEXT, STOP_TASK, AB, PAUSE_TASK]}
      Property privileges: PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[], deny=[]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[]))
      Policies: [operator]
      

      createUser()

      在实例上创建一个数据库用户。

      参数:

      • CreateUser:待创建的用户;必须设定username字段和password字段,systemPrivileges字段、graphPrivileges字段、propertyPrivilege字段和policies字段可选。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 创建用户javaUser并打印错误代码
      
      CreateUser createUser = new CreateUser();
      createUser.setUsername("javaUser");
      createUser.setPassword("@#javaUser");
      // 系统权限
      createUser.setSystemPrivileges(Lists.newArrayList(SystemPrivilege.SHOW_GRAPH, SystemPrivilege.TRUNCATE));
      // 图权限
      Map<String,List<GraphPrivilege>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList(GraphPrivilege.FIND, GraphPrivilege.SPREAD, GraphPrivilege.AUTONET, GraphPrivilege.AB, GraphPrivilege.TEMPLATE, GraphPrivilege.KHOP));
      graphPrivileges.put("lcc", Lists.newArrayList(GraphPrivilege.UPDATE, GraphPrivilege.INSERT, GraphPrivilege.DELETE, GraphPrivilege.UPSERT));
      createUser.setGraphPrivileges(graphPrivileges);
      // 属性权限
      PropertyPrivilege propertyPrivilege = new PropertyPrivilege();
      PropertyPrivilegeElement node = new PropertyPrivilegeElement();
      PropertyPrivilegeValue nodeValue1 = new PropertyPrivilegeValue();
      nodeValue1.setGraphName("miniCircle");
      nodeValue1.setSchemaName("account");
      PropertyPrivilegeValue nodeValue2 = new PropertyPrivilegeValue();
      nodeValue2.setGraphName("miniCircle");
      nodeValue2.setSchemaName("movie");
      nodeValue2.setPropertyName("name");
      PropertyPrivilegeValue nodeValue3 = new PropertyPrivilegeValue();
      nodeValue3.setGraphName("lcc");
      nodeValue3.setSchemaName("*");
      nodeValue3.setPropertyName("*");
      node.setRead(Lists.newArrayList(nodeValue1,nodeValue2));
      node.setWrite(Lists.newArrayList(nodeValue3));
      propertyPrivilege.setNode(node);
      PropertyPrivilegeElement edge = new PropertyPrivilegeElement();
      PropertyPrivilegeValue edgeValue1 = new PropertyPrivilegeValue();
      edgeValue1.setGraphName("*");
      PropertyPrivilegeValue edgeValue2 = new PropertyPrivilegeValue();
      edgeValue2.setGraphName("miniCircle");
      edgeValue2.setSchemaName("*");
      edgeValue2.setPropertyName("*");
      edge.setRead(Lists.newArrayList(edgeValue1));
      edge.setWrite(Lists.newArrayList(edgeValue2));
      propertyPrivilege.setEdge(edge);
      createUser.setPropertyPrivileges(propertyPrivilege);
      // 策略
      createUser.setPolicies(Lists.newArrayList("manager"));
      
      Response response = client.createUser(createUser);
      System.out.println(response.getStatus().getErrorCode());
      

      SUCCESS
      

      alterUser()

      根据用户名,修改实例中已有数据库用户的密码、系统权限、图权限、属性权限和策略。

      参数:

      • AlterUser:待修改的用户;必须设定username字段和password字段,systemPrivileges字段、graphPrivileges字段、propertyPrivilege字段和policies字段可选。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 修改用户javaUser并打印错误代码
      
      AlterUser alterUser = new AlterUser();
      alterUser.setUsername("javaUser");
      alterUser.setPassword("!!@#javaUser");
      // 系统权限
      alterUser.setSystemPrivileges(Lists.newArrayList(SystemPrivilege.SHOW_GRAPH));
      // 图权限
      Map<String,List<GraphPrivilege>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList(GraphPrivilege.FIND));
      graphPrivileges.put("lcc", Lists.newArrayList(GraphPrivilege.UPDATE));
      alterUser.setGraphPrivileges(graphPrivileges);
      // 策略
      alterUser.setPolicies(Lists.newArrayList("operator"));
      
      Response response = client.alterUser(alterUser);
      System.out.println(response.getStatus().getErrorCode());
      

      SUCCESS
      

      dropUser()

      根据用户名从实例中删除数据库用户。

      参数:

      • String:用户名。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 删除用户javaUser并打印错误代码
      
      Response response = client.dropUser("javaUser");
      System.out.println(response.getStatus().getErrorCode());
      

      SUCCESS
      

      grantPolicy()

      为实例中的数据库用户授予系统权限、图权限、属性权限和策略。

      参数:

      • String:用户名。
      • Map<String,List<GraphPrivilege>>:待授予的图权限;设定为null可跳过图权限授予。
      • List<SystemPrivilege>:待授予的系统权限;设定为null可跳过系统权限授予。
      • PropertyPrivilege:待授予的属性权限;设定为null可跳过属性权限授予。
      • List<String>:待授予的策略;设定为null可跳过策略授予。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 图权限
      Map<String,List<GraphPrivilege>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList(GraphPrivilege.FIND,GraphPrivilege.SPREAD,GraphPrivilege.AUTONET,GraphPrivilege.AB,GraphPrivilege.TEMPLATE,GraphPrivilege.KHOP));
      graphPrivileges.put("default", Lists.newArrayList(GraphPrivilege.UPDATE,GraphPrivilege.INSERT,GraphPrivilege.DELETE,GraphPrivilege.UPSERT));
      
      // 系统权限
      List<SystemPrivilege> systemPrivileges = Lists.newArrayList(SystemPrivilege.SHOW_GRAPH,SystemPrivilege.TRUNCATE);
      
      // 属性权限
      PropertyPrivilege propertyPrivilege = new PropertyPrivilege();
      PropertyPrivilegeElement node = new PropertyPrivilegeElement();
      PropertyPrivilegeValue nodeValue1 = new PropertyPrivilegeValue();
      nodeValue1.setGraphName("miniCircle");
      nodeValue1.setSchemaName("account");
      PropertyPrivilegeValue nodeValue2 = new PropertyPrivilegeValue();
      nodeValue2.setGraphName("miniCircle");
      nodeValue2.setSchemaName("movie");
      nodeValue2.setPropertyName("name");
      PropertyPrivilegeValue nodeValue3 = new PropertyPrivilegeValue();
      nodeValue3.setGraphName("default");
      nodeValue3.setSchemaName("*");
      nodeValue3.setPropertyName("*");
      node.setRead(Lists.newArrayList(nodeValue1, nodeValue2));
      node.setWrite(Lists.newArrayList(nodeValue3));
      propertyPrivilege.setNode(node);
      PropertyPrivilegeElement edge = new PropertyPrivilegeElement();
      PropertyPrivilegeValue edgeValue1 = new PropertyPrivilegeValue();
      edgeValue1.setGraphName("*");
      PropertyPrivilegeValue edgeValue2 = new PropertyPrivilegeValue();
      edgeValue2.setGraphName("miniCircle");
      edgeValue2.setSchemaName("*");
      edgeValue2.setPropertyName("*");
      edge.setRead(Lists.newArrayList(edgeValue1));
      edge.setWrite(Lists.newArrayList(edgeValue2));
      propertyPrivilege.setEdge(edge);
      
      // 策略
      List<String> policyList = Arrays.asList("operator", "manager");
      
      Response response1 = client.grantPolicy("johndoe", graphPrivileges,null,null,null);
      System.out.println(response1.getStatus().getErrorCode());
      
      Response response2 = client.grantPolicy("Tester", null,systemPrivileges,propertyPrivilege,policyList);
      System.out.println(response2.getStatus().getErrorCode());
      

      SUCCESS
      SUCCESS
      

      revokePolicy()

      撤销实例中的数据库用户的系统权限、图权限、属性权限和策略。

      参数:

      • String:用户名。
      • Map<String,List<GraphPrivilege>>:待撤销的图权限;设定为null可跳过图权限撤销。
      • List<SystemPrivilege>:待撤销的系统权限;设定为null可跳过系统权限撤销。
      • PropertyPrivilege:待撤销的属性权限;设定为null可跳过属性权限撤销。
      • List<String>:待撤销的策略;设定为null可跳过策略撤销。
      • RequestConfig(可选):配置请求。

      返回值:

      • Response:请求的结果。

      // 图权限
      Map<String,List<GraphPrivilege>> graphPrivileges = new HashMap<>();
      graphPrivileges.put("miniCircle", Lists.newArrayList(GraphPrivilege.FIND,GraphPrivilege.SPREAD,GraphPrivilege.AUTONET,GraphPrivilege.AB,GraphPrivilege.TEMPLATE,GraphPrivilege.KHOP));
      graphPrivileges.put("default", Lists.newArrayList(GraphPrivilege.UPDATE,GraphPrivilege.INSERT,GraphPrivilege.DELETE,GraphPrivilege.UPSERT));
      
      // 系统权限
      List<SystemPrivilege> systemPrivileges = Lists.newArrayList(SystemPrivilege.SHOW_GRAPH,SystemPrivilege.TRUNCATE);
      
      // 属性权限
      PropertyPrivilege propertyPrivilege = new PropertyPrivilege();
      PropertyPrivilegeElement node = new PropertyPrivilegeElement();
      PropertyPrivilegeValue nodeValue1 = new PropertyPrivilegeValue();
      nodeValue1.setGraphName("miniCircle");
      nodeValue1.setSchemaName("account");
      PropertyPrivilegeValue nodeValue2 = new PropertyPrivilegeValue();
      nodeValue2.setGraphName("miniCircle");
      nodeValue2.setSchemaName("movie");
      nodeValue2.setPropertyName("name");
      PropertyPrivilegeValue nodeValue3 = new PropertyPrivilegeValue();
      nodeValue3.setGraphName("default");
      nodeValue3.setSchemaName("*");
      nodeValue3.setPropertyName("*");
      node.setRead(Lists.newArrayList(nodeValue1, nodeValue2));
      node.setWrite(Lists.newArrayList(nodeValue3));
      propertyPrivilege.setNode(node);
      PropertyPrivilegeElement edge = new PropertyPrivilegeElement();
      PropertyPrivilegeValue edgeValue1 = new PropertyPrivilegeValue();
      edgeValue1.setGraphName("*");
      PropertyPrivilegeValue edgeValue2 = new PropertyPrivilegeValue();
      edgeValue2.setGraphName("miniCircle");
      edgeValue2.setSchemaName("*");
      edgeValue2.setPropertyName("*");
      edge.setRead(Lists.newArrayList(edgeValue1));
      edge.setWrite(Lists.newArrayList(edgeValue2));
      propertyPrivilege.setEdge(edge);
      
      // 策略
      List<String> policyList = Arrays.asList("operator", "manager");
      
      Response response1 = client.revokePolicy("johndoe", graphPrivileges,null,null,null);
      System.out.println(response1.getStatus().getErrorCode());
      
      Response response2 = client.revokePolicy("Tester", null,systemPrivileges,propertyPrivilege,policyList);
      System.out.println(response2.getStatus().getErrorCode());
      

      SUCCESS
      SUCCESS
      

      完整示例

      package com.ultipa.www.sdk.api;
      
      import com.ultipa.sdk.connect.Connection;
      import com.ultipa.sdk.connect.conf.RequestConfig;
      import com.ultipa.sdk.connect.conf.UltipaConfiguration;
      import com.ultipa.sdk.connect.driver.UltipaClientDriver;
      import com.ultipa.sdk.operate.entity.*;
      import java.util.*;
      
      public class Main {
          public static void main(String[] args) {
              // 设置连接
              UltipaConfiguration myConfig = UltipaConfiguration.config()
                  // URI示例: .hosts("mqj4zouys.us-east-1.cloud.ultipa.com:60010")
                  .hosts("192.168.1.85:60611,192.168.1.87:60611,192.168.1.88:60611")
                  .username("<username>")
                  .password("<password>");
      
              UltipaClientDriver driver = null;
              try {
                  // 建立与数据库的连接
                  driver = new UltipaClientDriver(myConfig);
                  Connection client = driver.getConnection();
      
                  Thread.sleep(3000);
                
                  // 配置请求
                  RequestConfig requestConfig = new RequestConfig();
                  requestConfig.setUseMaster(true);
      
                  // 获取全部策略并打印其信息
      
                  List<Policy> policyList = client.showPolicy(requestConfig);
                  for (Policy policy : policyList) {
                      System.out.println("Policy '" + policy.getName() + "' include:");
                      System.out.println("- System privileges: " + policy.getSystemPrivileges());
                      System.out.println("- Graph privileges: " + policy.getGraphPrivileges());
                      System.out.println("- Property privileges: " + policy.getPropertyPrivileges());
                      System.out.println("- Policies: " + policy.getPolicies());
                  }                      
              } catch (InterruptedException e) {
                  throw new RuntimeException(e);
              } finally {
                  if (driver != null) {
                      driver.close();
                  }
              }
          }
      }
      
      请完成以下信息后可下载此书
      *
      公司名称不能为空
      *
      公司邮箱必须填写
      *
      你的名字必须填写
      *
      你的电话必须填写
      *
      你的电话必须填写