Search in sources :

Example 6 with Project

use of com.thinkbiganalytics.metadata.api.project.Project in project kylo by Teradata.

the class JcrProjectProviderAccessControlTest method checkPermsAllowedProject3.

@Test(dependsOnMethods = "testCreateProject3")
public void checkPermsAllowedProject3() {
    logger.info("Running Test 'checkPermsAllowedProject3'");
    metadata.read(() -> {
        Optional<Project> u1Proj = this.projProvider.findProjectByName("Project3");
        assertThat(u1Proj.isPresent()).isTrue();
        Project Project3 = u1Proj.get();
        Project3.getAllowedActions().checkPermission(ProjectAccessControl.EDIT_PROJECT);
    }, TEST_USER1);
}
Also used : Project(com.thinkbiganalytics.metadata.api.project.Project) Test(org.testng.annotations.Test)

Example 7 with Project

use of com.thinkbiganalytics.metadata.api.project.Project in project kylo by Teradata.

the class JcrProjectProviderAccessControlTest method checkPermsDeniedProject3.

@Test(dependsOnMethods = "testCreateProject3", expectedExceptions = AccessControlException.class)
public void checkPermsDeniedProject3() {
    logger.info("Running Test 'checkPermsDeniedProject3'");
    metadata.read(() -> {
        Optional<Project> u1Proj = this.projProvider.findProjectByName("Project3");
        assertThat(u1Proj.isPresent()).isTrue();
        Project Project3 = u1Proj.get();
        Project3.getAllowedActions().checkPermission(ProjectAccessControl.EDIT_PROJECT);
    }, TEST_USER2);
}
Also used : Project(com.thinkbiganalytics.metadata.api.project.Project) Test(org.testng.annotations.Test)

Example 8 with Project

use of com.thinkbiganalytics.metadata.api.project.Project in project kylo by Teradata.

the class JcrProjectProviderAccessControlTest method testCreateProject3.

@Test
public void testCreateProject3() {
    logger.info("Running Test 'testCreateProject3'");
    // taken from: JcrFeedAllowedActionsTest createFeeds()
    String projectName = metadata.commit(() -> {
        /*
            actionsProvider.getAllowedActions(AllowedActions.PROJECTS).ifPresent(allowed -> allowed.enableAll(TEST_USER1));
            actionsProvider.getAllowedActions(AllowedActions.PROJECTS).ifPresent(allowed -> allowed.enableAll(TEST_USER2));

            this.roleProvider.createRole(SecurityRole.PROJECT, "testEditor", "Editor", "Can edit projects")
                .setPermissions(ProjectAccessControl.EDIT_PROJECT, FeedAccessControl.ENABLE_DISABLE, FeedAccessControl.EXPORT);
            this.roleProvider.createRole(SecurityRole.PROJECT, "testViewer", "Viewer", "Can view projects only")
                .setPermissions(ProjectAccessControl.ACCESS_PROJECT);
                */
        Project p3 = projProvider.ensureProject("Project3");
        p3.setProjectName("ProjectName3");
        p3.setContainerImage("kylo/nonExisentImage");
        // sets Access Control for user.
        // p3.getAllowedActions().enableAll(TEST_USER1);
        // p3.getAllowedActions().enable(TEST_USER2, ProjectAccessControl.ACCESS_PROJECT);
        // add User to the Role (new way of doing it)
        p3.getRoleMembership(ProjectAccessControl.ROLE_EDITOR).ifPresent(role -> role.addMember(TEST_USER1));
        p3.getRoleMembership(ProjectAccessControl.ROLE_READER).ifPresent(role -> role.addMember(TEST_USER2));
        return p3.getProjectName();
    }, JcrMetadataAccess.SERVICE);
}
Also used : Project(com.thinkbiganalytics.metadata.api.project.Project) Test(org.testng.annotations.Test)

Example 9 with Project

use of com.thinkbiganalytics.metadata.api.project.Project in project kylo by Teradata.

the class JcrNotebooksApp method main.

public static void main(String... args) throws RepositoryException, IOException {
    ModeShapeEngine engine = new ModeShapeEngine();
    engine.start();
    Repository repository = null;
    String repositoryName = null;
    URL url = JcrNotebooksApp.class.getClassLoader().getResource("sandbox/notebook-test-repository.json");
    RepositoryConfiguration config = RepositoryConfiguration.read(url);
    // Verify the configuration for the repository ...
    Problems problems = config.validate();
    if (problems.hasErrors()) {
        System.err.println("Problems starting the engine.");
        System.err.println(problems);
        System.exit(-1);
    }
    // Deploy the repository ...
    repository = engine.deploy(config);
    repositoryName = config.getName();
    Session session = null;
    JcrTools tools = new JcrTools();
    tools.setDebug(true);
    // get the repository
    repository = engine.getRepository(repositoryName);
    Project p;
    session = repository.login("default");
    // Create the '/files' node that is an 'nt:folder' ...
    Node root = session.getRootNode();
    /*
        Node filesNode = root.addNode("notebooks", "nt:folder");

        InputStream stream =
            new BufferedInputStream(new FileInputStream("/Users/th186036/filesystemconnector/hello.txt"));

        // Create an 'nt:file' node at the supplied path ...
        Node fileNode = filesNode.addNode("hello.txt", "nt:file");

        // Upload the file to that node ...
        Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
        Binary binary = session.getValueFactory().createBinary(stream);
        contentNode.setProperty("jcr:data", binary);

        session.save();
        */
    session = repository.login("default");
    Node project = JcrUtil.getOrCreateNode(root, "Project1", JcrProject.NODE_TYPE);
    List<Node> nodes = JcrUtil.getNodesOfType(root, JcrProject.NODE_TYPE);
    logger.debug("Node list {}", nodes);
    // List<JcrEntity> fileNodes = JcrUtil.getChildrenMatchingNodeType(root, JcrProject.NODE_TYPE, JcrEntity.class, null);
    // logger.debug("Node list {}", nodes );
    logger.debug("Modeshape subgraph");
    tools.printSubgraph(root);
    if (session != null) {
        session.logout();
    }
    logger.info("Shutting down engine ...");
    try {
        engine.shutdown().get();
        logger.info("Success!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Node(javax.jcr.Node) ModeShapeEngine(org.modeshape.jcr.ModeShapeEngine) URL(java.net.URL) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Problems(org.modeshape.common.collection.Problems) JcrProject(com.thinkbiganalytics.metadata.modeshape.project.JcrProject) Project(com.thinkbiganalytics.metadata.api.project.Project) Repository(org.modeshape.jcr.api.Repository) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) JcrTools(org.modeshape.jcr.api.JcrTools) Session(org.modeshape.jcr.api.Session)

Example 10 with Project

use of com.thinkbiganalytics.metadata.api.project.Project in project kylo by Teradata.

the class JcrProjectProvider method getProjectOwnerPlusRole.

private Set<UsernamePrincipal> getProjectOwnerPlusRole(String systemName, String accessControl) {
    Optional<Project> proj = findProjectByName(systemName);
    if (proj.isPresent()) {
        Project domain = proj.get();
        Set<UsernamePrincipal> result = getProjectMembersWithRole(domain, accessControl);
        // Owners can read...
        result.add((UsernamePrincipal) domain.getOwner());
        return result;
    } else {
        return ImmutableSet.of();
    }
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) JcrProject(com.thinkbiganalytics.metadata.modeshape.project.JcrProject) Project(com.thinkbiganalytics.metadata.api.project.Project)

Aggregations

Project (com.thinkbiganalytics.metadata.api.project.Project)11 Test (org.testng.annotations.Test)6 JcrProject (com.thinkbiganalytics.metadata.modeshape.project.JcrProject)4 UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)3 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 ProjectAccessControl (com.thinkbiganalytics.metadata.api.project.security.ProjectAccessControl)1 RoleMembership (com.thinkbiganalytics.metadata.api.security.RoleMembership)1 BaseJcrProvider (com.thinkbiganalytics.metadata.modeshape.BaseJcrProvider)1 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 JcrEntity (com.thinkbiganalytics.metadata.modeshape.common.JcrEntity)1 ProjectPaths (com.thinkbiganalytics.metadata.modeshape.project.ProjectPaths)1 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)1 JcrQueryUtil (com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil)1 JcrUtil (com.thinkbiganalytics.metadata.modeshape.support.JcrUtil)1 AccessController (com.thinkbiganalytics.security.AccessController)1 AllowedActions (com.thinkbiganalytics.security.action.AllowedActions)1