Search in sources :

Example 6 with HugeUser

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

Example 7 with HugeUser

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

Example 8 with HugeUser

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;
}
Also used : HugeUser(com.baidu.hugegraph.auth.HugeUser)

Example 9 with HugeUser

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeUser(com.baidu.hugegraph.auth.HugeUser) 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 10 with HugeUser

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

Aggregations

HugeUser (com.baidu.hugegraph.auth.HugeUser)19 HugeGraph (com.baidu.hugegraph.HugeGraph)13 AuthManager (com.baidu.hugegraph.auth.AuthManager)12 Test (org.junit.Test)12 Id (com.baidu.hugegraph.backend.id.Id)9 Timed (com.codahale.metrics.annotation.Timed)5 Produces (jakarta.ws.rs.Produces)5 GET (jakarta.ws.rs.GET)3 Path (jakarta.ws.rs.Path)3 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)2 UserWithRole (com.baidu.hugegraph.auth.UserWithRole)2 Consumes (jakarta.ws.rs.Consumes)2 HashMap (java.util.HashMap)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