use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.
the class AccessAPI method list.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") String group, @QueryParam("target") String target, @QueryParam("limit") @DefaultValue("100") long limit) {
LOG.debug("Graph [{}] list belongs by group {} or target {}", graph, group, target);
E.checkArgument(group == null || target == null, "Can't pass both group and target at the same time");
HugeGraph g = graph(manager, graph);
List<HugeAccess> belongs;
if (group != null) {
Id id = UserAPI.parseId(group);
belongs = manager.authManager().listAccessByGroup(id, limit);
} else if (target != null) {
Id id = UserAPI.parseId(target);
belongs = manager.authManager().listAccessByTarget(id, limit);
} else {
belongs = manager.authManager().listAllAccess(limit);
}
return manager.serializer(g).writeAuthElements("accesses", belongs);
}
use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.
the class AccessAPI method update.
@PUT
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id, JsonAccess jsonAccess) {
LOG.debug("Graph [{}] update access: {}", graph, jsonAccess);
checkUpdatingBody(jsonAccess);
HugeGraph g = graph(manager, graph);
HugeAccess access;
try {
access = manager.authManager().getAccess(UserAPI.parseId(id));
} catch (NotFoundException e) {
throw new IllegalArgumentException("Invalid access id: " + id);
}
access = jsonAccess.build(access);
manager.authManager().updateAccess(access);
return manager.serializer(g).writeAuthElement(access);
}
use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.
the class AccessAPI method get.
@GET
@Timed
@Path("{id}")
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) {
LOG.debug("Graph [{}] get access: {}", graph, id);
HugeGraph g = graph(manager, graph);
HugeAccess access = manager.authManager().getAccess(UserAPI.parseId(id));
return manager.serializer(g).writeAuthElement(access);
}
use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.
the class AuthTest method testListAllAccess.
@Test
public void testListAllAccess() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id group = authManager.createGroup(makeGroup("group1"));
Id target1 = authManager.createTarget(makeTarget("graph1", "url1"));
Id target2 = authManager.createTarget(makeTarget("graph2", "url2"));
authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
List<HugeAccess> access = authManager.listAllAccess(-1);
Assert.assertEquals(2, access.size());
Assert.assertEquals(ImmutableSet.of(target1, target2), ImmutableSet.of(access.get(0).target(), access.get(1).target()));
Assert.assertEquals(0, authManager.listAllAccess(0).size());
Assert.assertEquals(1, authManager.listAllAccess(1).size());
Assert.assertEquals(2, authManager.listAllAccess(2).size());
Assert.assertEquals(2, authManager.listAllAccess(3).size());
}
use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.
the class AuthTest method testDeleteAccess.
@Test
public void testDeleteAccess() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id group = authManager.createGroup(makeGroup("group1"));
Id target1 = authManager.createTarget(makeTarget("graph1", "url1"));
Id target2 = authManager.createTarget(makeTarget("graph2", "url2"));
Id id1 = authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
Id id2 = authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
Assert.assertEquals(2, authManager.listAllAccess(-1).size());
HugeAccess access = authManager.deleteAccess(id1);
Assert.assertEquals(target1, access.target());
Assert.assertEquals(1, authManager.listAllAccess(-1).size());
Assert.assertEquals(1, authManager.listAllAccess(2).size());
access = authManager.deleteAccess(id2);
Assert.assertEquals(target2, access.target());
Assert.assertEquals(0, authManager.listAllAccess(-1).size());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
Id belong = authManager.createBelong(makeBelong(user, group));
authManager.deleteAccess(belong);
});
}
Aggregations