Search in sources :

Example 6 with HugeAccess

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 7 with HugeAccess

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(jakarta.ws.rs.PUT)

Example 8 with HugeAccess

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 9 with HugeAccess

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 10 with HugeAccess

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);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Aggregations

HugeAccess (com.baidu.hugegraph.auth.HugeAccess)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Id (com.baidu.hugegraph.backend.id.Id)7 AuthManager (com.baidu.hugegraph.auth.AuthManager)6 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1