Search in sources :

Example 11 with HugeProject

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

the class AuthTest method makeProjectAndAddGraph.

private static Id makeProjectAndAddGraph(HugeGraph graph, String projectName, String graphName) {
    HugeProject project = makeProject(projectName, "");
    AuthManager authManager = graph.authManager();
    Id projectId = authManager.createProject(project);
    projectId = authManager.projectAddGraphs(projectId, ImmutableSet.of(graphName));
    Assert.assertNotNull(projectId);
    return projectId;
}
Also used : HugeProject(com.baidu.hugegraph.auth.HugeProject) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id)

Example 12 with HugeProject

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

the class AuthTest method clearAll.

@After
public void clearAll() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    for (HugeUser user : authManager.listAllUsers(-1)) {
        authManager.deleteUser(user.id());
    }
    for (HugeGroup group : authManager.listAllGroups(-1)) {
        authManager.deleteGroup(group.id());
    }
    for (HugeTarget target : authManager.listAllTargets(-1)) {
        authManager.deleteTarget(target.id());
    }
    for (HugeProject project : authManager.listAllProject(-1)) {
        if (!CollectionUtils.isEmpty(project.graphs())) {
            authManager.projectRemoveGraphs(project.id(), project.graphs());
        }
        authManager.deleteProject(project.id());
    }
    Assert.assertEquals(0, authManager.listAllAccess(-1).size());
    Assert.assertEquals(0, authManager.listAllBelong(-1).size());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeProject(com.baidu.hugegraph.auth.HugeProject) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) HugeUser(com.baidu.hugegraph.auth.HugeUser) After(org.junit.After)

Example 13 with HugeProject

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

the class AuthTest method testProjectRemoveGraph.

@Test
public void testProjectRemoveGraph() {
    Id projectId = makeProjectAndAddGraph(graph(), "test_project", "graph_test");
    AuthManager authManager = graph().authManager();
    Assert.assertNotNull(projectId);
    HugeProject project = authManager.getProject(projectId);
    Assert.assertNotNull(project);
    Assert.assertFalse(project.graphs().isEmpty());
    projectId = authManager.projectRemoveGraphs(project.id(), ImmutableSet.of("graph_test"));
    project = authManager.getProject(projectId);
    Assert.assertNotNull(project);
    Assert.assertTrue(project.graphs().isEmpty());
}
Also used : AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeProject(com.baidu.hugegraph.auth.HugeProject) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 14 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject 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

HugeProject (com.baidu.hugegraph.auth.HugeProject)14 AuthManager (com.baidu.hugegraph.auth.AuthManager)8 Id (com.baidu.hugegraph.backend.id.Id)8 Test (org.junit.Test)7 HugeGraph (com.baidu.hugegraph.HugeGraph)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)2 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)1 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)1 HugeUser (com.baidu.hugegraph.auth.HugeUser)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 After (org.junit.After)1