Search in sources :

Example 1 with HugeUser

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

Example 2 with HugeUser

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

Example 3 with HugeUser

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

Example 4 with HugeUser

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

Example 5 with HugeUser

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

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