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());
}
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")));
}
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);
}
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);
}
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);
});
}
Aggregations