Search in sources :

Example 11 with HugeAccess

use of com.baidu.hugegraph.auth.HugeAccess in project incubator-hugegraph by apache.

the class AuthTest method testGetAccess.

@Test
public void testGetAccess() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id group = authManager.createGroup(makeGroup("group1"));
    Id target1 = authManager.createTarget(makeTarget("graph1", "url1"));
    Id target2 = authManager.createTarget(makeTarget("graph2", "url2"));
    Id id1 = authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
    Id id2 = authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
    HugeAccess access1 = authManager.getAccess(id1);
    Assert.assertEquals(target1, access1.target());
    HugeAccess access2 = authManager.getAccess(id2);
    Assert.assertEquals(target2, access2.target());
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getAccess(IdGenerator.of("fake"));
    });
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getAccess(null);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id user = authManager.createUser(makeUser("tom", "pass1"));
        Id belong = authManager.createBelong(makeBelong(user, group));
        authManager.getAccess(belong);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Aggregations

HugeAccess (com.baidu.hugegraph.auth.HugeAccess)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Id (com.baidu.hugegraph.backend.id.Id)7 AuthManager (com.baidu.hugegraph.auth.AuthManager)6 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1