Search in sources :

Example 6 with HugeTarget

use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.

the class AuthTest method testUpdateTarget.

@Test
public void testUpdateTarget() throws InterruptedException {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    HugeTarget target = makeTarget("target1", "url1");
    Id id = authManager.createTarget(target);
    target = authManager.getTarget(id);
    Assert.assertEquals("target1", target.name());
    Assert.assertEquals("url1", target.url());
    Assert.assertEquals(target.create(), target.update());
    Date oldUpdateTime = target.update();
    Thread.sleep(1L);
    target.url("url2");
    authManager.updateTarget(target);
    HugeTarget target2 = authManager.getTarget(id);
    Assert.assertEquals("target1", target2.name());
    Assert.assertEquals("url2", target2.url());
    Assert.assertEquals(oldUpdateTime, target2.create());
    Assert.assertNotEquals(oldUpdateTime, target2.update());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Date(java.util.Date) Test(org.junit.Test)

Example 7 with HugeTarget

use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.

the class AuthTest method testCreateTargetWithRess.

@Test
public void testCreateTargetWithRess() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    String ress = "[{\"type\": \"VERTEX\", \"label\": \"person\", " + "\"properties\":{\"city\": \"Beijing\"}}, " + "{\"type\": \"EDGE\", \"label\": \"transfer\"}]";
    HugeTarget target = makeTarget("graph1", "127.0.0.1:8080");
    target.resources(ress);
    Id id = authManager.createTarget(target);
    target = authManager.getTarget(id);
    Assert.assertEquals("graph1", target.name());
    Assert.assertEquals("127.0.0.1:8080", target.url());
    Assert.assertEquals(target.create(), target.update());
    String expect = "[{\"type\":\"VERTEX\",\"label\":\"person\"," + "\"properties\":{\"city\":\"Beijing\"}}," + "{\"type\":\"EDGE\",\"label\":\"transfer\"," + "\"properties\":null}]";
    Assert.assertEquals(expect, JsonUtil.toJson(target.asMap().get("target_resources")));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Example 8 with HugeTarget

use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.

the class TargetAPI 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, JsonTarget jsonTarget) {
    LOG.debug("Graph [{}] update target: {}", graph, jsonTarget);
    checkUpdatingBody(jsonTarget);
    HugeGraph g = graph(manager, graph);
    HugeTarget target;
    try {
        target = manager.authManager().getTarget(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid target id: " + id);
    }
    target = jsonTarget.build(target);
    manager.authManager().updateTarget(target);
    return manager.serializer(g).writeAuthElement(target);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) 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 9 with HugeTarget

use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.

the class TargetAPI 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 target: {}", graph, id);
    HugeGraph g = graph(manager, graph);
    HugeTarget target = manager.authManager().getTarget(UserAPI.parseId(id));
    return manager.serializer(g).writeAuthElement(target);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 10 with HugeTarget

use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.

the class AuthTest method testGetTarget.

@Test
public void testGetTarget() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id id = authManager.createTarget(makeTarget("target-test", "url1"));
    HugeTarget target = authManager.getTarget(id);
    Assert.assertEquals("target-test", target.name());
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getTarget(IdGenerator.of("fake"));
    });
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getTarget(null);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id user = authManager.createUser(makeUser("tom", "pass1"));
        authManager.getTarget(user);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Aggregations

HugeTarget (com.baidu.hugegraph.auth.HugeTarget)15 HugeGraph (com.baidu.hugegraph.HugeGraph)12 AuthManager (com.baidu.hugegraph.auth.AuthManager)8 Test (org.junit.Test)8 Id (com.baidu.hugegraph.backend.id.Id)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 HugeUser (com.baidu.hugegraph.auth.HugeUser)2 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 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeResource (com.baidu.hugegraph.auth.HugeResource)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