Package org.apache.chemistry.opencmis.commons.data

Examples of org.apache.chemistry.opencmis.commons.data.Acl


   
    private void getAcl(String objectId) {
        LOG.debug("getting Acl() " + objectId);

        // get old ACL first:
        Acl oldAcl = aclSvc.getAcl(repositoryId, objectId, true, null);

        // create a new ACL for the test doc
        List<Ace> aces = new ArrayList<Ace>();
        aces.add(objFactory.createAccessControlEntry("Alice", Collections.singletonList("cmis:read")));
        aces.add(objFactory.createAccessControlEntry("Bob", Collections.singletonList("cmis:write")));
        aces.add(objFactory.createAccessControlEntry("admin", Collections.singletonList("cmis:all")));
        Acl acl = objFactory.createAccessControlList(aces);

        // add the new ACL and remove the old one
        aclSvc.applyAcl(repositoryId, objectId, acl, oldAcl, AclPropagation.OBJECTONLY, null);
           
        aclSvc.getAcl(repositoryId, objectId, true, null);
View Full Code Here


            AllowableActions allowableActions = so.getAllowableActions(user);
            od.setAllowableActions(allowableActions);
        }

        if (null != includeACL && includeACL) {
            Acl acl = so instanceof DocumentVersion ? ((DocumentVersion) so).getParentDocument().getAcl() : so.getAcl();
            od.setAcl(acl);
        }
        od.setIsExactAcl(true);

        if (null != includePolicyIds && includePolicyIds) {
View Full Code Here

    @Test
    public void testCreateDocumentWithContentNoFileNameNoMimeType() {
        log.info("starting testCreateDocumentWithContent() ...");
        ContentStreamDataImpl contentStream = null;
        List<String> policies = null;
        Acl addACEs = null;
        Acl removeACEs = null;
        ExtensionsData extension = null;

        Properties props = createDocumentProperties(DOCUMENT_ID, DOCUMENT_TYPE_ID);

        contentStream = (ContentStreamDataImpl) createContent();
View Full Code Here

    private String createDocumentWithCustomType(String folderId, boolean withContent) {
        ContentStream contentStream = null;
        VersioningState versioningState = VersioningState.NONE;
        List<String> policies = null;
        Acl addACEs = null;
        Acl removeACEs = null;
        ExtensionsData extension = null;

        // create the properties:
        List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
        properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, MY_CUSTOM_NAME));
View Full Code Here

    private String createDocumentInheritedProperties(String folderId, boolean withContent) {
        ContentStream contentStream = null;
        VersioningState versioningState = VersioningState.NONE;
        List<String> policies = null;
        Acl addACEs = null;
        Acl removeACEs = null;
        ExtensionsData extension = null;

        // create the properties:
        List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
        properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, MY_CUSTOM_NAME));
View Full Code Here

    public static Acl convert(CmisACLType acl) {
        if (acl == null) {
            return null;
        }

        Acl result = convert(acl.getACL(), acl.isExact());

        // handle extensions
        convertExtension(acl, result);

        return result;
View Full Code Here

                // create folder and document
                Folder testFolder = createTestFolder(session);
                Document doc = createDocument(session, testFolder, "acltest.txt", "ACL test");

                // check if there is an ACL
                Acl acl = doc.getAcl();

                f = createResult(FAILURE, "ACLs are supported but newly created document has no ACL!");
                addResult(assertNotNull(acl, null, f));

                // check basic permissions
                Acl basicAcl = session.getAcl(doc, true);

                f = createResult(FAILURE,
                        "ACLs are supported but repository does not return a basic ACL for the newly created document!");
                addResult(assertNotNull(basicAcl, null, f));

                if (basicAcl != null) {
                    addResult(checkACL(session, basicAcl, "Basic ACL"));

                    if (basicAcl.getAces() != null) {
                        for (Ace ace : basicAcl.getAces()) {
                            if (ace.getPermissions() != null) {
                                for (String permission : ace.getPermissions()) {
                                    if (!"cmis:read".equals(permission) && !"cmis:write".equals(permission)
                                            && !"cmis:all".equals(permission)) {
                                        addResult(createResult(FAILURE, "ACE contains a non-basic permission: "
View Full Code Here

        assertEquals(DOROTHEE, ace.getPrincipalId());
        assertEquals(1, ace.getPermissions().size());
        assertEquals(EnumBasicPermissions.CMIS_ALL.value(), ace.getPermissions().get(0));
       
        InMemoryAcl acl = createDefaultAcl();
        Acl commonsAcl = acl.toCommonsAcl();
        assertEquals(4, commonsAcl.getAces().size());
        assertTrue(hasCommonsAce(commonsAcl, ANDREAS, ""));
        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_READ.value()));
        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_WRITE.value()));
        assertFalse(hasCommonsAce(commonsAcl, ANDREAS, EnumBasicPermissions.CMIS_ALL.value()));
        assertTrue(hasCommonsAce(commonsAcl, BERTA, EnumBasicPermissions.CMIS_READ.value()));
View Full Code Here

  public void testCreateObjectsWithAcl()
  {
    // create a document with initial ACL
    String docId = createDocumentWithAcls("complexDocument",  fRootFolderId, UnitTestTypeSystemCreator.COMPLEX_TYPE,
        addAcl, defaultAcl);
    Acl acl1 = fAclSvc.getAcl(fRepositoryId, docId, true, null);
    assertTrue(aclEquals(addAcl, acl1));
   
    // create a folder with initial ACL
    String folderId = createFolderWithAcls("folderWithAcl", fRootFolderId, BaseTypeId.CMIS_FOLDER.value(),
        addAcl, defaultAcl);
    Acl acl2 = fAclSvc.getAcl(fRepositoryId, folderId, true, null);
    assertTrue(aclEquals(addAcl, acl2));
   
    // add acl later
    String docId2 = createVersionedDocument("complexDocument2",  fRootFolderId);
        Acl acl = fAclSvc.applyAcl(fRepositoryId, docId2, addAcl, defaultAcl, AclPropagation.OBJECTONLY, null);
    assertTrue(aclEquals(addAcl, acl));
   
    String folderId2 = createFolder("folder2", fRootFolderId, "cmis:folder");
    acl2 = fAclSvc.applyAcl(fRepositoryId, folderId2, addAcl, defaultAcl, AclPropagation.OBJECTONLY, null);
    assertTrue(aclEquals(addAcl, acl2));
   
    // add a subfolder
    String subFolderId = createFolder("subFolder", folderId,  BaseTypeId.CMIS_FOLDER.value());
    // folder should inherit acl
    Acl subAcl = fAclSvc.getAcl(fRepositoryId, subFolderId, true, null);
    assertTrue(aclEquals(addAcl, subAcl));
   
    // add a document
    String subDocId = createVersionedDocument("subDoc", subFolderId);
    // document should inherit acl
    Acl subAclDoc = fAclSvc.getAcl(fRepositoryId, subDocId, true, null);
    assertTrue(aclEquals(addAcl, subAclDoc));
   
    // remove an ace, no permission is left for TestUser
    Acl removeAcl = createAcl("TestUser", EnumBasicPermissions.CMIS_WRITE);
    Acl acl3 = fAclSvc.applyAcl(fRepositoryId, docId2, null, removeAcl, AclPropagation.OBJECTONLY, null);
   
    List<Ace> compareRemoveACEs = new ArrayList<Ace>(3);
    compareRemoveACEs.add(createAce("TestAdmin", EnumBasicPermissions.CMIS_ALL));
    compareRemoveACEs.add(createAce("Writer", EnumBasicPermissions.CMIS_WRITE));
    compareRemoveACEs.add(createAce("Reader", EnumBasicPermissions.CMIS_READ));
    Acl compareRemoveAcl = fFactory.createAccessControlList(compareRemoveACEs);
   
    assertTrue(aclEquals(compareRemoveAcl, acl3));
   
    // addACE not propagated
    Acl addPropAcl = createAcl("TestUser", EnumBasicPermissions.CMIS_WRITE);
   
    Acl acl4 = fAclSvc.applyAcl(fRepositoryId, subFolderId, addPropAcl, null, AclPropagation.OBJECTONLY, null);
    Acl subAclDoc2 = fAclSvc.getAcl(fRepositoryId, subDocId, true, null);
    assertTrue(aclEquals(addAcl, subAclDoc2))// acl of doc did not change
   
    List<Ace> compareRemoveACEs2 = new ArrayList<Ace>(4);
    compareRemoveACEs2.add(createAce("TestAdmin", EnumBasicPermissions.CMIS_ALL));
    compareRemoveACEs2.add(createAce("Writer", EnumBasicPermissions.CMIS_WRITE));
    compareRemoveACEs2.add(createAce("TestUser", EnumBasicPermissions.CMIS_ALL));
    compareRemoveACEs2.add(createAce("Reader", EnumBasicPermissions.CMIS_READ));
    Acl compareRemoveAcl2 = fFactory.createAccessControlList(compareRemoveACEs2);
    assertTrue(aclEquals(compareRemoveAcl2, acl4));
   
    // addACE propagated
    Acl acl5 = fAclSvc.applyAcl(fRepositoryId, subFolderId, addPropAcl, null, AclPropagation.PROPAGATE, null);
    Acl subAclDoc3 = fAclSvc.getAcl(fRepositoryId, subDocId, true, null);
    assertTrue(aclEquals(compareRemoveAcl2, subAclDoc3))// acl of doc did change
    assertTrue(aclEquals(compareRemoveAcl2, acl5));
  }
View Full Code Here

  public void testAclServiceGeneralAccess()
  {
      List<Ace> initialACEs = new ArrayList<Ace>(4);
      initialACEs.addAll(standardACEs);
      initialACEs.add(createAce("Admin2", EnumBasicPermissions.CMIS_ALL));
        Acl initialAcl = fFactory.createAccessControlList(initialACEs);  
       
        List<Ace> expectedACEs = new ArrayList<Ace>(5);
        expectedACEs.addAll(initialACEs);
        expectedACEs.addAll(testUserACEs);
        Acl expectedAcl = fFactory.createAccessControlList(expectedACEs);  
       
      List<Ace> removeACEs = new ArrayList<Ace>(1);
        removeACEs.add(createAce("TestAdmin", EnumBasicPermissions.CMIS_ALL));
    Acl removeAcl = fFactory.createAccessControlList(removeACEs);
   
    List<Ace> removeACEs2 = new ArrayList<Ace>(2);
    removeACEs2.add(createAce("TestAdmin", EnumBasicPermissions.CMIS_ALL));
    removeACEs2.add(createAce("Reader", EnumBasicPermissions.CMIS_READ));
    Acl removeAcl2 = fFactory.createAccessControlList(removeACEs2);
   
    List<Ace> testUserACEs = new ArrayList<Ace>(1);
    testUserACEs.add(createAce("TestUser", EnumBasicPermissions.CMIS_WRITE));
    Acl testUserAcl = fFactory.createAccessControlList(testUserACEs);
   
    switchCallContext("TestAdmin");
    String docId = createDocumentWithAcls("doc",  fRootFolderId, "ComplexType",
            initialAcl, defaultAcl);
    String folderId = createFolderWithAcls("folder", fRootFolderId, "cmis:folder", initialAcl, defaultAcl);
    String subFolderId = createFolderWithAcls("subFolder", folderId, "cmis:folder", initialAcl, defaultAcl);
   
    // getAcl of a folder
    switchCallContext("TestUser");
    boolean exceptionThrown = false;
    try
    {
      Acl acl = fAclSvc.getAcl(fRepositoryId, folderId, null, null);
    }
    catch (CmisPermissionDeniedException e)
    {
      exceptionThrown = true;
    }
    if (!exceptionThrown)
      Assert.fail("TestUser has no permissions to get acl of folder");
   
    switchCallContext("Reader");
    Acl acl = fAclSvc.getAcl(fRepositoryId, folderId, null, null);
   
    // getAcl of a document
    switchCallContext("TestUser");
    exceptionThrown = false;
    try
    {
      Acl docAcl = fAclSvc.getAcl(fRepositoryId, docId, true, null);
    }
    catch (CmisPermissionDeniedException e)
    {
      exceptionThrown = true;
    }
    if (!exceptionThrown)
      Assert.fail("TestUser has no permissions to get acl of doc)");
   
    switchCallContext("Reader");
    Acl docAcl = fAclSvc.getAcl(fRepositoryId, docId, true, null);
   
    // applyAcl
    switchCallContext("Reader");
    exceptionThrown = false;
    try
    {
      Acl docAcl2 = fAclSvc.applyAcl(fRepositoryId, docId, initialAcl, null, AclPropagation.OBJECTONLY, null);
    }
    catch (CmisPermissionDeniedException e)
    {
      exceptionThrown = true;
    }
    if (!exceptionThrown)
      Assert.fail("TestUser has no permissions)");
   
//    switchCallContext("Writer");
        switchCallContext("TestAdmin");
    Acl docAcl2 = fAclSvc.applyAcl(fRepositoryId, docId, initialAcl, null, AclPropagation.OBJECTONLY, null);
   
    // applyAcl when not allowed to subItem
    switchCallContext("TestAdmin");
    Acl docAcl4 = fAclSvc.applyAcl(fRepositoryId, subFolderId, null, removeAcl, AclPropagation.OBJECTONLY, null);
   
//        switchCallContext("Writer");
        switchCallContext("TestAdmin");
        // apply an ACL where the current user has permission to modify ACL on folder but not on sub-folder:
    Acl docAcl5 = fAclSvc.applyAcl(fRepositoryId, folderId, testUserAcl, null, AclPropagation.PROPAGATE, null);
    switchCallContext("Admin");
    Acl docAcl6 = fAclSvc.getAcl(fRepositoryId, folderId, true, null);
    assertTrue(aclEquals(expectedAcl, docAcl6));
    Acl docAcl7 = fAclSvc.getAcl(fRepositoryId, subFolderId, true, null);
    assertTrue(aclEquals(standardAcl, docAcl7));
  }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.data.Acl

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.