Search in sources :

Example 1 with IAbsSecurityProvider

use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.

the class EESpoonPluginTest method setUp.

@Before
public void setUp() throws KettleException {
    IAbsSecurityProvider provider = mock(IAbsSecurityProvider.class);
    doReturn(provider).when(repository).getService(eq(IAbsSecurityProvider.class));
    doReturn(repository).when(spoon).getRepository();
    doCallRealMethod().when(eeSpoonPlugin).onEvent(any());
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) Before(org.junit.Before)

Example 2 with IAbsSecurityProvider

use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.

the class EESpoonPlugin method doOnSecurityUpdate.

/**
 * Override UI elements to reflect the users capabilities as described by their permission levels
 */
private void doOnSecurityUpdate() throws KettleException {
    initMainSpoonContainer();
    Repository repository = getSpoonInstance().getRepository();
    // Repository User
    if (repository != null && repository.hasService(IRoleSupportSecurityManager.class)) {
        UIObjectRegistry.getInstance().registerUIRepositoryUserClass(UIEERepositoryUser.class);
    } else {
        UIObjectRegistry.getInstance().registerUIRepositoryUserClass(UIObjectRegistry.DEFAULT_UIREPOSITORYUSER_CLASS);
    }
    // Repository Directory
    if (repository != null && repository.hasService(IAclService.class)) {
        UIObjectRegistry.getInstance().registerUIRepositoryDirectoryClass(UIEERepositoryDirectory.class);
        UIObjectRegistry.getInstance().registerUIDatabaseConnectionClass(UIEEDatabaseConnection.class);
    } else {
        UIObjectRegistry.getInstance().registerUIRepositoryDirectoryClass(UIObjectRegistry.DEFAULT_UIDIR_CLASS);
    }
    // Repository Role
    if (repository != null && repository.hasService(IAbsSecurityProvider.class)) {
        UIEEObjectRegistery.getInstance().registerUIRepositoryRoleClass(UIAbsRepositoryRole.class);
        IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
        enablePermission(securityProvider);
    }
    // Job & Transformation =
    if (repository.hasService(ILockService.class)) {
        UIObjectRegistry.getInstance().registerUIJobClass(UIEEJob.class);
        UIObjectRegistry.getInstance().registerUITransformationClass(UIEETransformation.class);
        SpoonDelegateRegistry.getInstance().registerSpoonJobDelegateClass(SpoonEEJobDelegate.class);
        SpoonDelegateRegistry.getInstance().registerSpoonTransDelegateClass(SpoonEETransformationDelegate.class);
    } else {
        UIObjectRegistry.getInstance().registerUIJobClass(UIObjectRegistry.DEFAULT_UIJOB_CLASS);
        UIObjectRegistry.getInstance().registerUITransformationClass(UIObjectRegistry.DEFAULT_UITRANS_CLASS);
        SpoonDelegateRegistry.getInstance().registerSpoonJobDelegateClass(SpoonDelegateRegistry.DEFAULT_SPOONJOBDELEGATE_CLASS);
        SpoonDelegateRegistry.getInstance().registerSpoonTransDelegateClass(SpoonDelegateRegistry.DEFAULT_SPOONTRANSDELEGATE_CLASS);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) PurRepository(org.pentaho.di.repository.pur.PurRepository) Repository(org.pentaho.di.repository.Repository) IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) IAclService(org.pentaho.di.ui.repository.pur.services.IAclService)

Example 3 with IAbsSecurityProvider

use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.

the class EESpoonPlugin method warnClosingOfOpenTabsBasedOnPerms.

private void warnClosingOfOpenTabsBasedOnPerms(Spoon spoon) throws KettleException {
    Class<PurRepositoryDialog> PKG = PurRepositoryDialog.class;
    // Check to see if there are any open jobs/trans
    Repository repository = spoon.getRepository();
    if (spoon.getActiveMeta() == null) {
        return;
    }
    String warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Title");
    String warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
    String additionalWarningText = "";
    int buttons = SWT.OK;
    IAbsSecurityProvider absSecurityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
    if (absSecurityProvider != null) {
        boolean createPerms = false;
        boolean executePerms = false;
        boolean readPerms = false;
        try {
            createPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
            executePerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
            readPerms = absSecurityProvider.isAllowed(IAbsSecurityProvider.READ_CONTENT_ACTION);
        } catch (KettleException e) {
        // No nothing - we are just checking perms
        }
        // Check to see if display of warning dialog has been disabled
        if (readPerms && createPerms && executePerms) {
            warningTitle = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Title");
            warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Message");
            buttons = SWT.YES | SWT.NO | SWT.ICON_INFORMATION;
        } else {
            warningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Message");
            if (createPerms) {
                additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllForceAdditional.Connect.Message");
                buttons = SWT.YES | SWT.NO | SWT.ICON_WARNING;
            } else {
                additionalWarningText = BaseMessages.getString(PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message");
                buttons = SWT.OK | SWT.ICON_WARNING;
            }
        }
    }
    MessageBox mb = new MessageBox(spoon.getShell(), buttons);
    mb.setMessage(additionalWarningText.length() != 0 ? warningText + "\n\n" + additionalWarningText : warningText);
    mb.setText(warningTitle);
    final int isCloseAllFiles = mb.open();
    // Otherwise, we force close the tabs
    if ((isCloseAllFiles == SWT.YES) || (isCloseAllFiles == SWT.OK)) {
        spoon.closeAllFiles();
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) KettleException(org.pentaho.di.core.exception.KettleException) PurRepository(org.pentaho.di.repository.pur.PurRepository) Repository(org.pentaho.di.repository.Repository) PurRepositoryDialog(org.pentaho.di.ui.repository.pur.PurRepositoryDialog) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 4 with IAbsSecurityProvider

use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.

the class EESpoonPlugin method applyToContainer.

public void applyToContainer(String category, XulDomContainer container) throws XulException {
    container.registerClassLoader(getClass().getClassLoader());
    if (category.equals("spoon")) {
        // $NON-NLS-1$
        // register the two controllers, note that the lock controller must come
        // after the abs controller so the biz logic between the two hold.
        // Register the ABS Menu controller
        getSpoonInstance().addSpoonMenuController(new SpoonMenuABSController());
        // Register the SpoonMenuLockController to modify the main Spoon Menu structure
        getSpoonInstance().addSpoonMenuController(new SpoonMenuLockController());
    } else if (category.equals("trans-graph") || category.equals("job-graph")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        if ((getSpoonInstance() != null) && (getSpoonInstance().getRepository() != null) && (getSpoonInstance().getRepository() instanceof PurRepository)) {
            // $NON-NLS-1$
            container.getDocumentRoot().addOverlay("org/pentaho/di/ui/repository/pur/xul/spoon-lock-overlay.xul");
            container.addEventHandler(new SpoonLockController());
        }
        try {
            Repository repository = getSpoonInstance().getRepository();
            if (repository != null) {
                IAbsSecurityProvider securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
                if (securityProvider != null) {
                    enablePermission(securityProvider);
                }
            }
        } catch (KettleException e) {
            e.printStackTrace();
        }
    } else if (category.equals("repository-explorer")) {
        // $NON-NLS-1$
        try {
            Repository repository = getSpoonInstance().getRepository();
            IAbsSecurityProvider securityProvider = null;
            if (repository != null) {
                securityProvider = (IAbsSecurityProvider) repository.getService(IAbsSecurityProvider.class);
            }
            if (securityProvider != null) {
                boolean createPermitted = securityProvider.isAllowed(IAbsSecurityProvider.CREATE_CONTENT_ACTION);
                boolean executePermitted = securityProvider.isAllowed(IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
                // Disable export if user can not create or execute content (prevents execution outside of this repo)
                container.getDocumentRoot().getElementById("folder-context-export").setDisabled(!createPermitted || !executePermitted);
            }
        } catch (KettleException e) {
            e.printStackTrace();
        }
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) SpoonMenuLockController(org.pentaho.di.ui.repository.pur.controller.SpoonMenuLockController) KettleException(org.pentaho.di.core.exception.KettleException) PurRepository(org.pentaho.di.repository.pur.PurRepository) Repository(org.pentaho.di.repository.Repository) PurRepository(org.pentaho.di.repository.pur.PurRepository) SpoonLockController(org.pentaho.di.ui.repository.pur.controller.SpoonLockController) SpoonMenuABSController(org.pentaho.di.ui.repository.pur.repositoryexplorer.abs.controller.SpoonMenuABSController)

Example 5 with IAbsSecurityProvider

use of org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider in project pentaho-kettle by pentaho.

the class SpoonLockController method init.

protected void init() {
    try {
        if ((Spoon.getInstance().getRepository() != null) && (Spoon.getInstance().getRepository().hasService(IAbsSecurityProvider.class))) {
            IAbsSecurityProvider securityService = (IAbsSecurityProvider) Spoon.getInstance().getRepository().getService(IAbsSecurityProvider.class);
            setCreateAllowed(allowedActionsContains(securityService, IAbsSecurityProvider.CREATE_CONTENT_ACTION));
        }
        shell = (((Spoon) SpoonFactory.getInstance()).getShell());
        XulDomContainer container = getXulDomContainer();
        bindingFactory = new DefaultBindingFactory();
        bindingFactory.setDocument(container.getDocumentRoot());
        bindingFactory.setBindingType(Type.ONE_WAY);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "activeMetaUnlocked", "lock-context-locknotes", "disabled");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        bindingFactory.createBinding(this, "lockingNotAllowed", "lock-context-lock", "disabled");
        // Try transformation
        if (container.getEventHandlers().containsKey("transgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((TransGraph) container.getEventHandler("transgraph")).getMeta();
        } else if (container.getEventHandlers().containsKey("jobgraph")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            workingMeta = ((JobGraph) container.getEventHandler("jobgraph")).getMeta();
        }
        RepositoryLock repoLock = fetchRepositoryLock(workingMeta);
        if (repoLock != null) {
            // $NON-NLS-1$
            XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
            lockMenuItem.setSelected(true);
            // Permit locking/unlocking if the user owns the lock
            if (Spoon.getInstance().getRepository() instanceof PurRepository) {
                setLockingAllowed(new UnifiedRepositoryLockService(((PurRepository) Spoon.getInstance().getRepository()).getUnderlyingRepository()).canUnlockFileById(workingMeta.getObjectId()));
            } else {
                setLockingAllowed(repoLock.getLogin().equalsIgnoreCase(Spoon.getInstance().getRepository().getUserInfo().getLogin()));
            }
        } else {
            setLockingAllowed(true);
        }
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        firePropertyChange("activeMetaUnlocked", null, repoLock == null);
    } catch (Exception e) {
        // $NON-NLS-1$
        log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), e);
        new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), e.getMessage(), // $NON-NLS-1$
        e);
    }
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) PurRepository(org.pentaho.di.repository.pur.PurRepository) UnifiedRepositoryLockService(org.pentaho.di.repository.pur.UnifiedRepositoryLockService) Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)7 PurRepository (org.pentaho.di.repository.pur.PurRepository)5 Repository (org.pentaho.di.repository.Repository)4 KettleException (org.pentaho.di.core.exception.KettleException)3 Spoon (org.pentaho.di.ui.spoon.Spoon)2 JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)2 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)2 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Before (org.junit.Before)1 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)1 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)1 JobMeta (org.pentaho.di.job.JobMeta)1 UnifiedRepositoryLockService (org.pentaho.di.repository.pur.UnifiedRepositoryLockService)1 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)1 TransMeta (org.pentaho.di.trans.TransMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 PurRepositoryDialog (org.pentaho.di.ui.repository.pur.PurRepositoryDialog)1 SpoonLockController (org.pentaho.di.ui.repository.pur.controller.SpoonLockController)1 SpoonMenuLockController (org.pentaho.di.ui.repository.pur.controller.SpoonMenuLockController)1 SpoonMenuABSController (org.pentaho.di.ui.repository.pur.repositoryexplorer.abs.controller.SpoonMenuABSController)1