use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class UserAPI method create.
@POST
@Timed
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonUser jsonUser) {
LOG.debug("Graph [{}] create user: {}", graph, jsonUser);
checkCreatingBody(jsonUser);
HugeGraph g = graph(manager, graph);
HugeUser user = jsonUser.build();
user.id(manager.authManager().createUser(user));
return manager.serializer(g).writeAuthElement(user);
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class UserAPI 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 user: {}", graph, id);
HugeGraph g = graph(manager, graph);
HugeUser user = manager.authManager().getUser(IdGenerator.of(id));
return manager.serializer(g).writeAuthElement(user);
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class UserAPI method role.
@GET
@Timed
@Path("{id}/role")
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String role(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) {
LOG.debug("Graph [{}] get user role: {}", graph, id);
// just check if the graph exists
@SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
HugeUser user = manager.authManager().getUser(IdGenerator.of(id));
return manager.authManager().rolePermission(user).toJson();
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testLogin.
@Test
public void testLogin() throws AuthenticationException {
AuthManager authManager = graph().authManager();
HugeUser user = makeUser("test", StringEncoding.hashPassword("pass"));
authManager.createUser(user);
// Login
authManager.loginUser("test", "pass");
// Invalid username or password
Assert.assertThrows(AuthenticationException.class, () -> {
authManager.loginUser("huge", "graph");
}, e -> {
Assert.assertContains("Incorrect username or password", e.getMessage());
});
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testDeleteUser.
@Test
public void testDeleteUser() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createUser(makeUser("tom", "pass1"));
Id id2 = authManager.createUser(makeUser("james", "pass2"));
Assert.assertEquals(2, authManager.listAllUsers(-1).size());
HugeUser user = authManager.deleteUser(id1);
Assert.assertEquals("tom", user.name());
Assert.assertEquals(1, authManager.listAllUsers(-1).size());
user = authManager.deleteUser(id2);
Assert.assertEquals("james", user.name());
Assert.assertEquals(0, authManager.listAllUsers(-1).size());
}
Aggregations