Search in sources :

Example 46 with AccessDeniedException

use of org.alfresco.repo.security.permissions.AccessDeniedException in project records-management by Alfresco.

the class ReadPermissionsOnTransferFolderTest method testReadPermissionsOnTransferFolder.

public void testReadPermissionsOnTransferFolder() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(testUser1) {

        // Records folder
        private NodeRef recordsFolder = null;

        // Transfer folder
        private NodeRef transferFolder = null;

        /**
         * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#given()
         */
        @Override
        public void given() {
            runAs(new RunAsWork<Void>() {

                public Void doWork() {
                    // Create category
                    NodeRef category = filePlanService.createRecordCategory(filePlan, generate());
                    // Give filing permissions for the test users on the category
                    filePlanPermissionService.setPermission(category, testUser1, FILING);
                    filePlanPermissionService.setPermission(category, testUser2, FILING);
                    // Create disposition schedule
                    utils.createDispositionSchedule(category, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_AUTHORITY, false, true, true);
                    // Create folder
                    recordsFolder = recordFolderService.createRecordFolder(category, generate());
                    // Make eligible for cut off
                    Map<String, Serializable> params = new HashMap<String, Serializable>(1);
                    params.put(PARAM_EVENT_NAME, DEFAULT_EVENT_NAME);
                    rmActionService.executeRecordsManagementAction(recordsFolder, CompleteEventAction.NAME, params);
                    // Cut off folder
                    rmActionService.executeRecordsManagementAction(recordsFolder, CutOffAction.NAME);
                    return null;
                }
            }, getAdminUserName());
            // FIXME: This step should be executed in "when()".
            // See RM-3931
            transferFolder = (NodeRef) rmActionService.executeRecordsManagementAction(recordsFolder, TransferAction.NAME).getValue();
        }

        /**
         * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#when()
         */
        @Override
        public void when() {
            // FIXME: If the transfer step is executed here the test fails. See RM-3931
            // transferFolder = (NodeRef) rmActionService.executeRecordsManagementAction(recordsFolder, TransferAction.NAME).getValue();
            // Give testUser2 read permissions on transfer folder
            filePlanPermissionService.setPermission(transferFolder, testUser2, READ_RECORDS);
        }

        /**
         * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#then()
         */
        @Override
        public void then() {
            // Check transfer folder
            assertNotNull(transferFolder);
            // testUser1 should have read permissions on the transfers container
            assertEquals(ALLOWED, permissionService.hasPermission(transfersContainer, READ_RECORDS));
            // Check if testUser1 has filing permissions on the transfer folder
            assertEquals(ALLOWED, permissionService.hasPermission(transferFolder, FILING));
            runAs(new RunAsWork<Void>() {

                public Void doWork() {
                    // Check transfer folder
                    assertNotNull(transferFolder);
                    // testUser2 should have read permissions on the transfers container
                    assertEquals(ALLOWED, permissionService.hasPermission(transfersContainer, READ_RECORDS));
                    // Check if testUser2 has read permissions on the transfer folder
                    assertEquals(ALLOWED, permissionService.hasPermission(transferFolder, READ_RECORDS));
                    // Check if testUser2 filing permissions on the transfer folder
                    assertEquals(DENIED, permissionService.hasPermission(transferFolder, FILING));
                    // Try to execute transfer complete action as testUser2 who has no filing permissions on the transfer folder
                    try {
                        rmActionService.executeRecordsManagementAction(transferFolder, TransferCompleteAction.NAME);
                    } catch (AccessDeniedException ade) {
                    // Expected
                    }
                    return null;
                }
            }, testUser2);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) HashMap(java.util.HashMap)

Aggregations

AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)30 HashMap (java.util.HashMap)17 IOException (java.io.IOException)8 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)8 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)8 ArrayList (java.util.ArrayList)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 FacesContext (javax.faces.context.FacesContext)6 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)6 JSONObject (org.json.simple.JSONObject)6 Serializable (java.io.Serializable)5 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)5 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)5 SocketException (java.net.SocketException)4 Map (java.util.Map)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)4 QName (org.alfresco.service.namespace.QName)4 ResourceBundle (java.util.ResourceBundle)3