use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testCreateUserWithDetailsInfo.
@Test
public void testCreateUserWithDetailsInfo() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
HugeUser user = new HugeUser("james");
user.password("pass2");
user.phone("13812345678");
user.email("test@hugegraph.com");
user.avatar("http://image.hugegraph.com/image1");
user.creator("admin");
Id id = authManager.createUser(user);
user = authManager.getUser(id);
Assert.assertEquals("james", user.name());
Assert.assertEquals("pass2", user.password());
Assert.assertEquals(user.create(), user.update());
Assert.assertEquals("13812345678", user.phone());
Assert.assertEquals("test@hugegraph.com", user.email());
Assert.assertEquals("http://image.hugegraph.com/image1", user.avatar());
Map<String, Object> expected = new HashMap<>();
expected.put("user_name", "james");
expected.put("user_password", "pass2");
expected.put("user_creator", "admin");
expected.put("user_create", user.create());
expected.put("user_update", user.update());
expected.put("user_phone", user.phone());
expected.put("user_email", user.email());
expected.put("user_avatar", user.avatar());
expected.put("id", user.id());
Assert.assertEquals(expected, user.asMap());
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testGetUser.
@Test
public void testGetUser() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id = authManager.createUser(makeUser("tom", "pass1"));
HugeUser user = authManager.getUser(id);
Assert.assertEquals("tom", user.name());
Assert.assertEquals("pass1", user.password());
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getUser(IdGenerator.of("fake"));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getUser(null);
});
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method makeUser.
private static HugeUser makeUser(String name, String password) {
HugeUser user = new HugeUser(name);
user.password(password);
user.creator("admin");
return user;
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class UserAPI 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, JsonUser jsonUser) {
LOG.debug("Graph [{}] update user: {}", graph, jsonUser);
checkUpdatingBody(jsonUser);
HugeGraph g = graph(manager, graph);
HugeUser user;
try {
user = manager.authManager().getUser(UserAPI.parseId(id));
} catch (NotFoundException e) {
throw new IllegalArgumentException("Invalid user id: " + id);
}
user = jsonUser.build(user);
manager.authManager().updateUser(user);
return manager.serializer(g).writeAuthElement(user);
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class UserAPI method list.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("limit") @DefaultValue("100") long limit) {
LOG.debug("Graph [{}] list users", graph);
HugeGraph g = graph(manager, graph);
List<HugeUser> users = manager.authManager().listAllUsers(limit);
return manager.serializer(g).writeAuthElements("users", users);
}
Aggregations