Package org.exoplatform.services.jcr.core

Examples of org.exoplatform.services.jcr.core.ExtendedNode


    * Here we check that if add the mixin types exo:owneable and exo:privilegeable and the sub node is already
    * exo:owneable and exo:privilegeable, so nothing will be inherited
    */
   public void testPermissionInheritance4() throws Exception
   {
      ExtendedNode rootEn = (ExtendedNode)sessionWS1.getRootNode();
      Node rootNode = sessionWS1.getRootNode().addNode("testPermissionInheritance4");
      sessionWS1.save();
      Node subNode = rootNode.addNode("subNode");
      sessionWS1.save();
      subNode.addNode("subNode2");
      sessionWS1.save();

      Repository repository = repositoryService.getRepository("db2");
      Credentials credentialsAdmin = new CredentialsImpl("admin", "admin".toCharArray());

      Session s = (SessionImpl)repository.login(credentialsAdmin, "ws1");
      ExtendedNode en = (ExtendedNode)s.getItem("/testPermissionInheritance4");
      assertEquals(rootEn.getACL().getOwner(), en.getACL().getOwner());
      assertEquals(rootEn.getACL().getPermissionsSize(), en.getACL().getPermissionsSize());
      assertEquals(4, en.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(0, en.getACL().getPermissions("mary").size());
      ExtendedNode enSub = (ExtendedNode)en.getNode("subNode");
      assertEquals(rootEn.getACL().getOwner(), enSub.getACL().getOwner());
      assertEquals(rootEn.getACL().getPermissionsSize(), enSub.getACL().getPermissionsSize());
      assertEquals(4, enSub.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(0, enSub.getACL().getPermissions("mary").size());
      ExtendedNode enSub2 = (ExtendedNode)enSub.getNode("subNode2");
      assertEquals(rootEn.getACL().getOwner(), enSub2.getACL().getOwner());
      assertEquals(rootEn.getACL().getPermissionsSize(), enSub2.getACL().getPermissionsSize());
      assertEquals(4, enSub2.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(0, enSub2.getACL().getPermissions("mary").size());
      en.addMixin("exo:owneable");
      s.save();
      s.logout();
      Credentials credentialsMary = new CredentialsImpl("mary", "exo".toCharArray());
      s = (SessionImpl)repository.login(credentialsMary, "ws1");
      en = (ExtendedNode)s.getItem("/testPermissionInheritance4/subNode");
      en.addMixin("exo:owneable");
      en.addMixin("exo:privilegeable");
      en.setPermission("*:/platform/administrators", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
      en.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
      en.removePermission(SystemIdentity.ANY);
      s.save();
      s.logout();

      s = (SessionImpl)repository.login(credentialsAdmin, "ws1");
      en = (ExtendedNode)s.getItem("/testPermissionInheritance4");
      assertEquals("admin", en.getACL().getOwner());
      assertEquals(rootEn.getACL().getPermissionsSize(), en.getACL().getPermissionsSize());
      assertEquals(4, en.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(0, en.getACL().getPermissions("mary").size());
      assertEquals(0, en.getACL().getPermissions("*:/platform/administrators").size());
      enSub = (ExtendedNode)en.getNode("subNode");
      assertEquals("mary", enSub.getACL().getOwner());
      assertEquals(4, enSub.getACL().getPermissionsSize());
      assertEquals(0, enSub.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(2, enSub.getACL().getPermissions("mary").size());
      assertEquals(2, enSub.getACL().getPermissions("*:/platform/administrators").size());
      enSub2 = (ExtendedNode)enSub.getNode("subNode2");
      assertEquals("mary", enSub2.getACL().getOwner());
      assertEquals(4, enSub2.getACL().getPermissionsSize());
      assertEquals(0, enSub2.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(2, enSub2.getACL().getPermissions("mary").size());
      assertEquals(2, enSub2.getACL().getPermissions("*:/platform/administrators").size());
      en.addMixin("exo:privilegeable");
      en.setPermission("*:/platform/administrators", PermissionType.ALL);
      en.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY, PermissionType.ADD_NODE});
      en.removePermission(SystemIdentity.ANY);
      en.save();
      s.logout();

      s = (SessionImpl)repository.login(credentialsAdmin, "ws1");
      en = (ExtendedNode)s.getItem("/testPermissionInheritance4");
      assertEquals("admin", en.getACL().getOwner());
      assertEquals(7, en.getACL().getPermissionsSize());
      assertEquals(0, en.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(3, en.getACL().getPermissions("mary").size());
      assertEquals(4, en.getACL().getPermissions("*:/platform/administrators").size());
      enSub = (ExtendedNode)en.getNode("subNode");
      assertEquals("mary", enSub.getACL().getOwner());
      assertEquals(4, enSub.getACL().getPermissionsSize());
      assertEquals(0, enSub.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(2, enSub.getACL().getPermissions("mary").size());
      assertEquals(2, enSub.getACL().getPermissions("*:/platform/administrators").size());
      enSub2 = (ExtendedNode)enSub.getNode("subNode2");
      assertEquals("mary", enSub2.getACL().getOwner());
      assertEquals(4, enSub2.getACL().getPermissionsSize());
      assertEquals(0, enSub2.getACL().getPermissions(SystemIdentity.ANY).size());
      assertEquals(2, enSub2.getACL().getPermissions("mary").size());
      assertEquals(2, enSub2.getACL().getPermissions("*:/platform/administrators").size());
      s.logout();
   }
View Full Code Here


   /**
    *  Unit test for https://jira.exoplatform.org/browse/JCR-1832
    */
   public void testGetFileFromFolder() throws Exception
   {
      ExtendedNode folderA = (ExtendedNode)session.getRootNode().addNode("folderA", "nt:folder");
      folderA.addMixin("exo:privilegeable");
      folderA.setPermission("john", PermissionType.ALL);
      folderA.removePermission(IdentityConstants.ANY);
      session.save();
     
      assertEquals(4, folderA.getACL().getPermissionEntries().size());
      assertEquals("john read", folderA.getACL().getPermissionEntries().get(0).getAsString());
      assertEquals("john add_node", folderA.getACL().getPermissionEntries().get(1).getAsString());
      assertEquals("john set_property", folderA.getACL().getPermissionEntries().get(2).getAsString());
      assertEquals("john remove", folderA.getACL().getPermissionEntries().get(3).getAsString());
     
     
      Session sessJohn = repository.login(new CredentialsImpl("john", "exo".toCharArray()), "ws");
     
      ExtendedNode folderB = (ExtendedNode)sessJohn.getRootNode().getNode("folderA").addNode("folderB", "nt:folder");
     
      folderB.addMixin("exo:privilegeable");
      folderB.setPermission("any", new String[]{"read"});
      sessJohn.save();
     
      assertEquals(5, folderB.getACL().getPermissionEntries().size());
      assertEquals("john read", folderB.getACL().getPermissionEntries().get(0).getAsString());
      assertEquals("john add_node", folderB.getACL().getPermissionEntries().get(1).getAsString());
      assertEquals("john set_property", folderB.getACL().getPermissionEntries().get(2).getAsString());
      assertEquals("john remove", folderB.getACL().getPermissionEntries().get(3).getAsString());
      assertEquals("any read", folderB.getACL().getPermissionEntries().get(4).getAsString());
     
      // Login as anonim.
      // Tthis session use on server side, thank SessionProvider.
      repository.login(new CredentialsImpl(IdentityConstants.ANONIM, "exo".toCharArray()), "ws");

View Full Code Here

   {
      for (int i = 0; i < TEST_NODES_COUNT; i++)
      {
         Node subnode = testRoot.addNode("TestNode" + String.format("%07d", i));
         subnode.setProperty("val", i);
         ExtendedNode subnode2 = (ExtendedNode)testRoot.addNode("TestNode2-" + String.format("%07d", i));
         subnode2.setProperty("val", i);
         subnode2.addMixin("exo:privilegeable");
         HashMap<String, String[]> perm = new HashMap<String, String[]>();
         perm.put("admin", PermissionType.ALL);
         subnode2.setPermissions(perm);
      }

   }
View Full Code Here

    * @throws Exception
    */
   public void testOwneable() throws Exception
   {

      ExtendedNode node = (ExtendedNode)session.getRootNode().addNode("testACNode");
      node.addMixin("exo:owneable");
      AccessControlList acl = node.getACL();
      assertEquals(session.getUserID(), acl.getOwner());
      assertEquals(PermissionType.ALL.length, acl.getPermissionEntries().size());
      assertEquals(PermissionType.ALL[0], acl.getPermissionEntries().get(0).getPermission());

   }
View Full Code Here

    * @throws Exception
    */
   public void testPrivilegeable() throws Exception
   {

      ExtendedNode node = (ExtendedNode)session.getRootNode().addNode("testACNode");
      node.addMixin("exo:privilegeable");
      AccessControlList acl = node.getACL();
      assertEquals(SystemIdentity.SYSTEM, acl.getOwner());
      assertEquals(PermissionType.ALL.length, acl.getPermissionEntries().size());
      assertEquals(PermissionType.ALL[0], acl.getPermissionEntries().get(0).getPermission());
   }
View Full Code Here

    * @throws Exception
    */
   public void testDefaultAccessControllable() throws Exception
   {

      ExtendedNode node = (ExtendedNode)session.getRootNode().addNode("testACNode");
      // node.addMixin("exo:accessControllable");
      node.addMixin("exo:owneable");
      node.addMixin("exo:privilegeable");

      AccessControlList acl = node.getACL();
      assertEquals(session.getUserID(), acl.getOwner());

      assertEquals(PermissionType.ALL.length, acl.getPermissionEntries().size());
      assertEquals(PermissionType.ALL[0], acl.getPermissionEntries().get(0).getPermission());

      // the same after save() and re-retrieve
      session.save();
      node = (ExtendedNode)session.getRootNode().getNode("testACNode");

      Session session1 = repository.login(new CredentialsImpl("mary", "exo".toCharArray()));
      session1.getRootNode().getNode("testACNode");

      acl = node.getACL();
      assertEquals(session.getUserID(), acl.getOwner());

      assertEquals(PermissionType.ALL.length, acl.getPermissionEntries().size());
      assertEquals(PermissionType.ALL[0], acl.getPermissionEntries().get(0).getPermission());

View Full Code Here

   public void testAddNode() throws Exception
   {
      // ExtendedNode node =
      // (ExtendedNode)session.getRootNode().addNode("testAddNode");
      ExtendedNode node = (ExtendedNode)accessTestRoot.addNode("testAddNode");
      // node.addMixin("exo:accessControllable");
      node.addMixin("exo:owneable");
      node.addMixin("exo:privilegeable");

      HashMap<String, String[]> perm = new HashMap<String, String[]>();
      // perm.put("john", PermissionType.ALL);
      perm.put("john", new String[]{PermissionType.ADD_NODE, PermissionType.READ});
      perm.put("mary", new String[]{PermissionType.READ});
      node.setPermissions(perm);
      session.save();

      // ACL is:
      // Owner = exo
      // READ, ADD_NODE permissions for john
View Full Code Here

  public void testAddAuditHistoryAction() throws Exception {
    // Should not be autocreated

    NodeImpl rootNode = (NodeImpl) session.getRootNode().getNode(ROOT_PATH);

    ExtendedNode node = (ExtendedNode) rootNode.addNode("deep");
    // node.addMixin("exo:auditable");
    session.save();
    String auditHistoryUUID = node.getProperty("exo:auditHistory").getString();
    Node auditHistory = session.getNodeByUUID(auditHistoryUUID);

    assertTrue(auditHistory.isNodeType("exo:auditHistory"));

    // pointed to target node
    assertEquals(auditHistory.getProperty("exo:targetNode").getString(), node.getUUID());

    assertEquals("1", auditHistory.getProperty("exo:lastRecord").getString());

    assertEquals(1, auditHistory.getNodes().getSize());

    session.save();
    service.removeHistory(node);
    node.remove();
    session.save();

    try {
      session.getNodeByUUID(auditHistoryUUID);
      fail("History should be removed");
View Full Code Here

   */
  public void testAddAuditHistoryMixinAction() throws Exception {
    NodeImpl rootNode = (NodeImpl) session.getRootNode().getNode(ROOT_PATH);

    // Should not be autocreated
    ExtendedNode node = (ExtendedNode) rootNode.addNode("mixin", "nt:unstructured");
    node.addMixin("exo:auditable");

    String auditHistoryUUID = node.getProperty("exo:auditHistory").getString();
    Node auditHistory = session.getNodeByUUID(auditHistoryUUID);

    // under audit
    node.setProperty("test", "testValue");

    assertTrue(auditHistory.isNodeType("exo:auditHistory"));

    // pointed to target node
    assertEquals(auditHistory.getProperty("exo:targetNode").getString(), node.getUUID());

    assertEquals("2", auditHistory.getProperty("exo:lastRecord").getString());

    assertEquals(2, auditHistory.getNodes().getSize());

    session.save();
    service.removeHistory(node);
    node.remove();
    session.save();

    try {
      session.getNodeByUUID(auditHistoryUUID);
      fail("History should be removed");
View Full Code Here

   *
   * @throws RepositoryException
   */
  public void testAddInfoToAuditStorage() throws RepositoryException {

    ExtendedNode node = null;
    try {
      node = (ExtendedNode) session.getRootNode().getNode(ROOT_PATH).addNode("testaudit");
      node.addMixin("exo:auditable");
      if (!service.hasHistory(node))
        service.createHistory(node);
      session.save();
    } catch (RepositoryException e) {
      e.printStackTrace();
      fail("Fail to init AuditStorage" + e.getLocalizedMessage());
    }
    Property property1 = node.setProperty("property1", "value1");
    service.addRecord(null, node, Event.NODE_ADDED);
    service.addRecord(null, property1, Event.PROPERTY_ADDED);

    Node auditHistory = session.getNodeByUUID(node.getProperty("exo:auditHistory").getString());
    assertNotNull(auditHistory);
    assertEquals(2, auditHistory.getNodes().getSize());

    assertTrue(service.hasHistory(node));
    assertNotNull(service.getHistory(node));
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.core.ExtendedNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.