Search in sources :

Example 6 with HugeResource

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

the class RolePermissionTest method testHugeResourceFilterUser.

@Test
public void testHugeResourceFilterUser() {
    HugeResource all = HugeResource.ALL;
    // user
    ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.USER_GROUP, NameObject.ANY);
    Assert.assertFalse(all.filter(r3));
    HugeResource user = new HugeResource(ResourceType.USER_GROUP, HugeResource.ANY, null);
    Assert.assertTrue(user.filter(r3));
    ResourceObject<?> r4 = ResourceObject.of("g1", new HugeUser("fake"));
    Assert.assertTrue(user.filter(r4));
    HugeResource user2 = new HugeResource(ResourceType.USER_GROUP, "bj-.*", null);
    Assert.assertTrue(user2.filter(r3));
    Assert.assertFalse(user2.filter(r4));
    HugeResource user3 = new HugeResource(ResourceType.USER_GROUP, "fa.*", null);
    Assert.assertTrue(user3.filter(r3));
    Assert.assertTrue(user3.filter(r4));
    ResourceObject<?> r5 = ResourceObject.of("g1", new HugeTarget("g", ""));
    Assert.assertFalse(user.filter(r5));
    HugeResource root = new HugeResource(ResourceType.ROOT, HugeResource.ANY, null);
    Assert.assertTrue(root.filter(r3));
    Assert.assertTrue(root.filter(r4));
    Assert.assertTrue(root.filter(r5));
}
Also used : HugeResource(com.baidu.hugegraph.auth.HugeResource) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) HugeUser(com.baidu.hugegraph.auth.HugeUser) Test(org.junit.Test)

Example 7 with HugeResource

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

the class RolePermissionTest method testHugeResourceFilterProject.

@Test
public void testHugeResourceFilterProject() {
    HugeResource all = HugeResource.ALL;
    ResourceObject<?> r1 = ResourceObject.of("hugegraph", new HugeProject("project1"));
    Assert.assertFalse(all.filter(r1));
    HugeResource project = new HugeResource(ResourceType.PROJECT, "project1", null);
    Assert.assertTrue(project.filter(r1));
    HugeResource root = new HugeResource(ResourceType.ROOT, HugeResource.ANY, null);
    Assert.assertTrue(root.filter(r1));
    ResourceObject<?> r2 = ResourceObject.of("hugegraph", new HugeProject("project2"));
    Assert.assertFalse(project.filter(r2));
}
Also used : HugeProject(com.baidu.hugegraph.auth.HugeProject) HugeResource(com.baidu.hugegraph.auth.HugeResource) Test(org.junit.Test)

Aggregations

HugeResource (com.baidu.hugegraph.auth.HugeResource)7 Test (org.junit.Test)7 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)2 HugeGraph (com.baidu.hugegraph.HugeGraph)1 AuthManager (com.baidu.hugegraph.auth.AuthManager)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)1 HugeUser (com.baidu.hugegraph.auth.HugeUser)1 RolePermission (com.baidu.hugegraph.auth.RolePermission)1 Id (com.baidu.hugegraph.backend.id.Id)1 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)1 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)1