Search in sources :

Example 1 with AccessDeniedException

use of org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException in project pentaho-kettle by pentaho.

the class PermissionsController method applyOnObjectOnly.

/**
 * applyOnObjectOnly is called to save acl for a file object only
 *
 * @param roList
 * @param hideDialog
 */
private void applyOnObjectOnly(List<UIRepositoryObject> roList, boolean hideDialog) {
    try {
        if (roList.get(0) instanceof UIRepositoryDirectory) {
            UIRepositoryDirectory rd = (UIRepositoryDirectory) roList.get(0);
            if (rd instanceof IAclObject) {
                ((IAclObject) rd).setAcls(viewAclsModel);
            } else {
                // $NON-NLS-1$
                throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
            }
        } else {
            UIRepositoryContent rc = (UIRepositoryContent) roList.get(0);
            if (rc instanceof ILockObject && ((ILockObject) rc).isLocked()) {
                // $NON-NLS-1$
                messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                // $NON-NLS-1$
                messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                // $NON-NLS-1$
                messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.LockedObjectWarning"));
                messageBox.open();
                viewAclsModel.setModelDirty(false);
                return;
            } else if (rc instanceof IAclObject) {
                ((IAclObject) rc).setAcls(viewAclsModel);
            } else {
                // $NON-NLS-1$
                throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
            }
        }
        /*
       * if (hideDialog) { applyAclConfirmationDialog.hide(); }
       */
        viewAclsModel.setModelDirty(false);
        // $NON-NLS-1$
        messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Success"));
        // $NON-NLS-1$
        messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
        // $NON-NLS-1$
        messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.PermissionAppliedSuccessfully"));
        messageBox.open();
    } catch (AccessDeniedException ade) {
        /*
       * if (hideDialog) { applyAclConfirmationDialog.hide(); }
       */
        if (mainController == null || !mainController.handleLostRepository(ade)) {
            // $NON-NLS-1$
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            messageBox.setMessage(ade.getLocalizedMessage());
            messageBox.open();
        }
    } catch (KettleException kex) {
        if (mainController == null || !mainController.handleLostRepository(kex)) {
            // $NON-NLS-1$
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            messageBox.setMessage(kex.getLocalizedMessage());
            messageBox.open();
        }
    }
}
Also used : UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) ILockObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)

Example 2 with AccessDeniedException

use of org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException in project pentaho-kettle by pentaho.

the class PermissionsController method createBindings.

protected void createBindings() {
    super.createBindings();
    // $NON-NLS-1$
    fileFolderLabel = (XulLabel) document.getElementById("file-folder-name");
    // $NON-NLS-1$
    aclDeck = (XulDeck) document.getElementById("acl-deck");
    // $NON-NLS-1$
    inheritParentPermissionCheckbox = (XulCheckbox) document.getElementById("inherit-from-parent-permission-checkbox");
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(List<UIRepositoryObject> ro) {
            if (ro == null) {
                return null;
            }
            if (ro.size() <= 0) {
                return null;
            }
            setSelectedRepositoryObject(ro);
            if (!hasManageAclAccess()) {
                // disable everything
                applyAclButton.setDisabled(true);
                addAclButton.setDisabled(true);
                removeAclButton.setDisabled(true);
                inheritParentPermissionCheckbox.setDisabled(true);
                manageAclCheckbox.setDisabled(true);
                deleteCheckbox.setDisabled(true);
                writeCheckbox.setDisabled(true);
                readCheckbox.setDisabled(true);
                viewAclsModel.setHasManageAclAccess(false);
            } else {
                applyAclButton.setDisabled(false);
                inheritParentPermissionCheckbox.setDisabled(false);
                viewAclsModel.setHasManageAclAccess(true);
            }
            viewAclsModel.setRemoveEnabled(false);
            List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
            // we've moved to a new file/folder; need to clear out what the model thinks is selected
            viewAclsModel.setSelectedAclList(selectedAclList);
            permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
            UIRepositoryObject repoObject = ro.get(0);
            try {
                if (repoObject instanceof IAclObject) {
                    ((IAclObject) repoObject).getAcls(viewAclsModel);
                } else {
                    // $NON-NLS-1$
                    throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
                }
                fileFolderLabel.setValue(// $NON-NLS-1$
                BaseMessages.getString(PKG, "AclTab.UserRolePermission", repoObject.getName()));
                bf.setBindingType(Binding.Type.ONE_WAY);
                // $NON-NLS-1$ //$NON-NLS-2$
                bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
                updateInheritFromParentPermission();
            } catch (AccessDeniedException ade) {
                if (mainController == null || !mainController.handleLostRepository(ade)) {
                    // $NON-NLS-1$
                    messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                    // $NON-NLS-1$
                    messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
                    ade.getLocalizedMessage()));
                    messageBox.open();
                }
            } catch (Exception e) {
                if (mainController == null || !mainController.handleLostRepository(e)) {
                    // $NON-NLS-1$
                    messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                    // $NON-NLS-1$
                    messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
                    e.getLocalizedMessage()));
                    messageBox.open();
                }
            }
            aclDeck.setSelectedIndex(ACL);
            return viewAclsModel.getAcls();
        }

        @Override
        public List<UIRepositoryObject> targetToSource(List<UIRepositoryObjectAcl> elements) {
            return null;
        }
    };
    // Binding between the selected repository objects and the user role list for acls
    securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(browseController, "repositoryObjects", userRoleList, "elements", securityBindingConverter);
    securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(browseController, "repositoryDirectories", userRoleList, "elements", securityBindingConverter);
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // Binding Add Remove button to the inherit check box. If the checkbox is checked that disable add remove
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(viewAclsModel, "entriesInheriting", inheritParentPermissionCheckbox, "checked");
    // Setting the default Deck to show no permission
    aclDeck.setSelectedIndex(NO_ACL);
    try {
        if (securityBinding != null) {
            securityBinding.fireSourceChanged();
        }
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            // convert to runtime exception so it bubbles up through the UI
            throw new RuntimeException(e);
        }
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) UIRepositoryObjectAcl(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) ArrayList(java.util.ArrayList) List(java.util.List) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Example 3 with AccessDeniedException

use of org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException in project pentaho-kettle by pentaho.

the class UIEEJobTest method testAcls.

@Test
public void testAcls() throws Exception {
    final String owner = "owner";
    final String role = "role";
    ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
    when(mockObjectRecipient.getName()).thenReturn(owner);
    ObjectAcl mockAcl = mock(ObjectAcl.class);
    when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
    when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
    uiJob.clearAcl();
    UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
    uiJob.getAcls(acls);
    verify(mockAclService).getAcl(mockObjectId, false);
    assertEquals(owner, acls.getOwner().getName());
    acls = new UIRepositoryObjectAcls();
    RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
    acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
    uiJob.setAcls(acls);
    verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
    when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
    uiJob.clearAcl();
    try {
        uiJob.getAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
    doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(RepositoryObjectAcl.class));
    try {
        uiJob.setAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Example 4 with AccessDeniedException

use of org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException in project pentaho-kettle by pentaho.

the class UIEETransformationTest method testAcls.

@Test
public void testAcls() throws Exception {
    final String owner = "owner";
    final String role = "role";
    ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
    when(mockObjectRecipient.getName()).thenReturn(owner);
    ObjectAcl mockAcl = mock(ObjectAcl.class);
    when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
    when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
    uiTransformation.clearAcl();
    UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
    uiTransformation.getAcls(acls);
    verify(mockAclService).getAcl(mockObjectId, false);
    assertEquals(owner, acls.getOwner().getName());
    acls = new UIRepositoryObjectAcls();
    RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
    acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
    uiTransformation.setAcls(acls);
    verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
    when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
    uiTransformation.clearAcl();
    try {
        uiTransformation.getAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
    doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(RepositoryObjectAcl.class));
    try {
        uiTransformation.setAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Example 5 with AccessDeniedException

use of org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException in project pentaho-kettle by pentaho.

the class UIEERepositoryDirectoryTest method testAcls.

@Test
public void testAcls() throws Exception {
    final String owner = "owner";
    final String role = "role";
    ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
    when(mockObjectRecipient.getName()).thenReturn(owner);
    ObjectAcl mockAcl = mock(ObjectAcl.class);
    when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
    when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
    uiRepDir.clearAcl();
    UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
    uiRepDir.getAcls(acls);
    verify(mockAclService, times(1)).getAcl(mockObjectId, false);
    assertEquals(owner, acls.getOwner().getName());
    acls = new UIRepositoryObjectAcls();
    uiRepDir.getAcls(acls, false);
    verify(mockAclService, times(2)).getAcl(mockObjectId, false);
    assertEquals(owner, acls.getOwner().getName());
    acls = new UIRepositoryObjectAcls();
    RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
    acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
    uiRepDir.setAcls(acls);
    verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
    when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
    uiRepDir.clearAcl();
    try {
        uiRepDir.getAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
    when(mockAclService.getAcl(mockObjectId, true)).thenThrow(new KettleException(""));
    uiRepDir.clearAcl();
    try {
        uiRepDir.getAcls(acls, true);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
    doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(ObjectAcl.class));
    uiRepDir.clearAcl();
    try {
        uiRepDir.setAcls(acls);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
    // Test Succeeded if here
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Aggregations

AccessDeniedException (org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException)7 KettleException (org.pentaho.di.core.exception.KettleException)5 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)4 Test (org.junit.Test)3 ObjectId (org.pentaho.di.repository.ObjectId)3 ObjectRecipient (org.pentaho.di.repository.ObjectRecipient)3 ObjectAcl (org.pentaho.di.repository.pur.model.ObjectAcl)3 RepositoryObjectAcl (org.pentaho.di.repository.pur.model.RepositoryObjectAcl)3 RepositoryObjectRecipient (org.pentaho.di.repository.pur.model.RepositoryObjectRecipient)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UIRepositoryObjectAcl (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl)2 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)2 UIDatabaseConnection (org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection)2 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)2 ILockObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject)1 UIRepositoryContent (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)1 UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)1 UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1