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