Search in sources :

Example 6 with AuthManager

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

the class AuthTest method testListProject.

@Test
public void testListProject() {
    AuthManager authManager = graph().authManager();
    authManager.createProject(makeProject("test_project1", ""));
    authManager.createProject(makeProject("test_project2", ""));
    authManager.createProject(makeProject("test_project3", ""));
    List<HugeProject> projects = authManager.listAllProject(1);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 1);
    projects = authManager.listAllProject(-1);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(3);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(4);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(2);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 2);
}
Also used : AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeProject(com.baidu.hugegraph.auth.HugeProject) Test(org.junit.Test)

Example 7 with AuthManager

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

the class AuthTest method testListBelong.

@Test
public void testListBelong() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id user = authManager.createUser(makeUser("tom", "pass1"));
    Id group1 = authManager.createGroup(makeGroup("group1"));
    Id group2 = authManager.createGroup(makeGroup("group2"));
    Id id1 = authManager.createBelong(makeBelong(user, group1));
    Id id2 = authManager.createBelong(makeBelong(user, group2));
    List<HugeBelong> belongs = authManager.listBelong(ImmutableList.of(id1, id2));
    Assert.assertEquals(2, belongs.size());
    Assert.assertEquals(user, belongs.get(0).source());
    Assert.assertEquals(user, belongs.get(1).source());
    Assert.assertEquals(group1, belongs.get(0).target());
    Assert.assertEquals(group2, belongs.get(1).target());
    belongs = authManager.listBelong(ImmutableList.of(id1, id2, id2));
    Assert.assertEquals(3, belongs.size());
    belongs = authManager.listBelong(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
    Assert.assertEquals(2, belongs.size());
    belongs = authManager.listBelongByUser(user, -1);
    Assert.assertEquals(2, belongs.size());
    Assert.assertEquals(user, belongs.get(0).source());
    Assert.assertEquals(user, belongs.get(1).source());
    belongs = authManager.listBelongByGroup(group1, -1);
    Assert.assertEquals(1, belongs.size());
    Assert.assertEquals(user, belongs.get(0).source());
    Assert.assertEquals(group1, belongs.get(0).target());
    belongs = authManager.listBelongByGroup(group2, -1);
    Assert.assertEquals(1, belongs.size());
    Assert.assertEquals(user, belongs.get(0).source());
    Assert.assertEquals(group2, belongs.get(0).target());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeBelong(com.baidu.hugegraph.auth.HugeBelong) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 8 with AuthManager

use of com.baidu.hugegraph.auth.AuthManager 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 9 with AuthManager

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

the class AuthTest method testDeleteBelong.

@Test
public void testDeleteBelong() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id user = authManager.createUser(makeUser("tom", "pass1"));
    Id group1 = authManager.createGroup(makeGroup("group1"));
    Id group2 = authManager.createGroup(makeGroup("group2"));
    Id id1 = authManager.createBelong(makeBelong(user, group1));
    Id id2 = authManager.createBelong(makeBelong(user, group2));
    Assert.assertEquals(2, authManager.listAllBelong(-1).size());
    HugeBelong belong = authManager.deleteBelong(id1);
    Assert.assertEquals(group1, belong.target());
    Assert.assertEquals(1, authManager.listAllBelong(-1).size());
    Assert.assertEquals(1, authManager.listAllBelong(2).size());
    belong = authManager.deleteBelong(id2);
    Assert.assertEquals(group2, belong.target());
    Assert.assertEquals(0, authManager.listAllBelong(-1).size());
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id target = authManager.createTarget(makeTarget("graph1", ""));
        Id access = authManager.createAccess(makeAccess(group1, target, HugePermission.READ));
        authManager.deleteBelong(access);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeBelong(com.baidu.hugegraph.auth.HugeBelong) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 10 with AuthManager

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

the class AuthTest method testGetBelong.

@Test
public void testGetBelong() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id user = authManager.createUser(makeUser("tom", "pass1"));
    Id group1 = authManager.createGroup(makeGroup("group1"));
    Id group2 = authManager.createGroup(makeGroup("group2"));
    Id id1 = authManager.createBelong(makeBelong(user, group1));
    Id id2 = authManager.createBelong(makeBelong(user, group2));
    HugeBelong belong1 = authManager.getBelong(id1);
    Assert.assertEquals(group1, belong1.target());
    HugeBelong belong2 = authManager.getBelong(id2);
    Assert.assertEquals(group2, belong2.target());
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getBelong(IdGenerator.of("fake"));
    });
    Assert.assertThrows(NotFoundException.class, () -> {
        authManager.getBelong(null);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id target = authManager.createTarget(makeTarget("graph1", ""));
        Id access = authManager.createAccess(makeAccess(group1, target, HugePermission.READ));
        authManager.getBelong(access);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeBelong(com.baidu.hugegraph.auth.HugeBelong) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Aggregations

AuthManager (com.baidu.hugegraph.auth.AuthManager)46 Test (org.junit.Test)43 Id (com.baidu.hugegraph.backend.id.Id)39 HugeGraph (com.baidu.hugegraph.HugeGraph)36 HugeUser (com.baidu.hugegraph.auth.HugeUser)12 HugeProject (com.baidu.hugegraph.auth.HugeProject)8 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)8 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)7 HugeAccess (com.baidu.hugegraph.auth.HugeAccess)6 HugeBelong (com.baidu.hugegraph.auth.HugeBelong)6 HashMap (java.util.HashMap)6 Date (java.util.Date)5 UserWithRole (com.baidu.hugegraph.auth.UserWithRole)2 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 RolePermission (com.baidu.hugegraph.auth.RolePermission)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 Timed (com.codahale.metrics.annotation.Timed)1 Consumes (jakarta.ws.rs.Consumes)1 PUT (jakarta.ws.rs.PUT)1 Path (jakarta.ws.rs.Path)1