Search in sources :

Example 6 with RepositorySecurityProvider

use of org.pentaho.di.repository.RepositorySecurityProvider in project pentaho-kettle by pentaho.

the class Spoon method checkIsVersioningEnabledOnServer.

private static boolean checkIsVersioningEnabledOnServer(Repository rep, EngineMetaInterface jobTransMeta) {
    boolean versioningEnabled = true;
    String fullPath = getJobTransfFullPath(jobTransMeta);
    RepositorySecurityProvider repositorySecurityProvider = rep != null && rep.getSecurityProvider() != null ? rep.getSecurityProvider() : null;
    if (repositorySecurityProvider != null && fullPath != null) {
        versioningEnabled = repositorySecurityProvider.isVersioningEnabled(fullPath);
    }
    return versioningEnabled;
}
Also used : RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 7 with RepositorySecurityProvider

use of org.pentaho.di.repository.RepositorySecurityProvider in project pentaho-kettle by pentaho.

the class Spoon method saveToRepositoryConfirmed.

public boolean saveToRepositoryConfirmed(EngineMetaInterface meta) throws KettleException {
    if (!Utils.isEmpty(meta.getName()) && rep != null) {
        ObjectId existingId = null;
        if (meta instanceof TransMeta) {
            existingId = rep.getTransformationID(meta.getName(), meta.getRepositoryDirectory());
        }
        if (meta instanceof JobMeta) {
            existingId = rep.getJobId(meta.getName(), meta.getRepositoryDirectory());
        }
        boolean saved = false;
        if (meta.getObjectId() == null) {
            meta.setObjectId(existingId);
        }
        try {
            shell.setCursor(cursor_hourglass);
            // created and or modified...
            if (meta.getCreatedDate() == null) {
                meta.setCreatedDate(new Date());
                if (capabilities.supportsUsers()) {
                    meta.setCreatedUser(rep.getUserInfo().getLogin());
                }
            }
            // Keep info on who & when this transformation was
            // changed...
            meta.setModifiedDate(new Date());
            if (capabilities.supportsUsers()) {
                meta.setModifiedUser(rep.getUserInfo().getLogin());
            }
            boolean versioningEnabled = true;
            boolean versionCommentsEnabled = true;
            String fullPath = getJobTransfFullPath(meta);
            RepositorySecurityProvider repositorySecurityProvider = rep != null && rep.getSecurityProvider() != null ? rep.getSecurityProvider() : null;
            if (repositorySecurityProvider != null && fullPath != null) {
                versioningEnabled = repositorySecurityProvider.isVersioningEnabled(fullPath);
                versionCommentsEnabled = repositorySecurityProvider.allowsVersionComments(fullPath);
            }
            // Finally before saving, ask for a version comment (if
            // applicable)
            // 
            String versionComment = null;
            boolean versionOk;
            if (!versioningEnabled || !versionCommentsEnabled) {
                versionOk = true;
                versionComment = "";
            } else {
                versionOk = false;
            }
            while (!versionOk) {
                versionComment = RepositorySecurityUI.getVersionComment(shell, rep, meta.getName(), fullPath, false);
                // if the version comment is null, the user hit cancel, exit.
                if (rep != null && rep.getSecurityProvider() != null && rep.getSecurityProvider().allowsVersionComments(fullPath) && versionComment == null) {
                    return false;
                }
                if (Utils.isEmpty(versionComment) && rep.getSecurityProvider().isVersioningEnabled(fullPath) && rep.getSecurityProvider().isVersionCommentMandatory()) {
                    if (!RepositorySecurityUI.showVersionCommentMandatoryDialog(shell)) {
                        // no, I don't want to enter a
                        return false;
                    // version comment and yes,
                    // it's mandatory.
                    }
                } else {
                    versionOk = true;
                }
            }
            if (versionOk) {
                SaveProgressDialog spd = new SaveProgressDialog(shell, rep, meta, versionComment);
                if (spd.open()) {
                    saved = true;
                    if (!props.getSaveConfirmation()) {
                        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "Spoon.Message.Warning.SaveOK"), null, BaseMessages.getString(PKG, "Spoon.Message.Warning.TransformationWasStored"), MessageDialog.QUESTION, new String[] { BaseMessages.getString(PKG, "Spoon.Message.Warning.OK") }, 0, BaseMessages.getString(PKG, "Spoon.Message.Warning.NotShowThisMessage"), props.getSaveConfirmation());
                        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
                        md.open();
                        props.setSaveConfirmation(md.getToggleState());
                    }
                    // Handle last opened files...
                    props.addLastFile(meta.getFileType(), meta.getName(), meta.getRepositoryDirectory().getPath(), true, getRepositoryName(), getUsername(), null);
                    saveSettings();
                    addMenuLast();
                    setShellText();
                }
            }
        } finally {
            shell.setCursor(null);
        }
        return saved;
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        // "There is no repository connection available."
        mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Message"));
        // "No repository available."
        mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Title"));
        mb.open();
    }
    return false;
}
Also used : RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) JobMeta(org.pentaho.di.job.JobMeta) SaveProgressDialog(org.pentaho.di.ui.spoon.dialog.SaveProgressDialog) ObjectId(org.pentaho.di.repository.ObjectId) TransMeta(org.pentaho.di.trans.TransMeta) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Date(java.util.Date) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 8 with RepositorySecurityProvider

use of org.pentaho.di.repository.RepositorySecurityProvider in project pentaho-kettle by pentaho.

the class AbstractPermissionsController method init.

protected void init(Repository rep) throws Exception {
    if (rep != null && rep.hasService(RepositorySecurityProvider.class)) {
        service = (RepositorySecurityProvider) rep.getService(RepositorySecurityProvider.class);
    } else {
        throw new ControllerInitializationException(BaseMessages.getString(PKG, "PermissionsController.ERROR_0001_UNABLE_TO_INITIAL_REPOSITORY_SERVICE", // $NON-NLS-1$
        RepositorySecurityManager.class));
    }
    // $NON-NLS-1$
    messageBox = (XulMessageBox) document.createElement("messagebox");
    viewAclsModel = new UIRepositoryObjectAcls();
    manageAclsModel = new UIRepositoryObjectAclModel(viewAclsModel);
    bf = new DefaultBindingFactory();
    bf.setDocument(this.getXulDomContainer().getDocumentRoot());
    mainController = (MainController) this.getXulDomContainer().getEventHandler("mainController");
    // $NON-NLS-1$
    confirmBox = (XulConfirmBox) document.createElement("confirmbox");
    // $NON-NLS-1$
    confirmBox.setTitle(BaseMessages.getString(PKG, "PermissionsController.RemoveAclWarning"));
    // $NON-NLS-1$
    confirmBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.RemoveAclWarningText"));
    // $NON-NLS-1$
    confirmBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
    // $NON-NLS-1$
    confirmBox.setCancelLabel(BaseMessages.getString(PKG, "Dialog.Cancel"));
    confirmBox.addDialogCallback(new XulDialogCallback<Object>() {

        public void onClose(XulComponent sender, Status returnCode, Object retVal) {
            if (returnCode == Status.ACCEPT) {
                viewAclsModel.removeSelectedAcls();
            }
        }

        public void onError(XulComponent sender, Throwable t) {
        }
    });
}
Also used : UIRepositoryObjectAcls(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcls) RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) DefaultBindingFactory(org.pentaho.ui.xul.binding.DefaultBindingFactory) RepositorySecurityManager(org.pentaho.di.repository.RepositorySecurityManager) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject) XulComponent(org.pentaho.ui.xul.XulComponent) UIRepositoryObjectAclModel(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAclModel)

Example 9 with RepositorySecurityProvider

use of org.pentaho.di.repository.RepositorySecurityProvider in project pentaho-kettle by pentaho.

the class PurRepository method connect.

@Override
public void connect(final String username, final String password) throws KettleException {
    connected = false;
    if (isTest()) {
        connected = true;
        purRepositoryServiceRegistry.registerService(IRevisionService.class, new UnifiedRepositoryRevisionService(pur, getRootRef()));
        purRepositoryServiceRegistry.registerService(ILockService.class, new UnifiedRepositoryLockService(pur));
        purRepositoryServiceRegistry.registerService(IAclService.class, new UnifiedRepositoryConnectionAclService(pur));
        metaStore = new PurRepositoryMetaStore(this);
        try {
            metaStore.createNamespace(PentahoDefaults.NAMESPACE);
        } catch (MetaStoreException e) {
            log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
        }
        this.user = new EEUserInfo(username, password, username, "test user", true);
        this.jobDelegate = new JobDelegate(this, pur);
        this.transDelegate = new TransDelegate(this, pur);
        this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
        return;
    }
    try {
        if (log != null && purRepositoryConnector != null && purRepositoryConnector.getLog() != null) {
            purRepositoryConnector.getLog().setLogLevel(log.getLogLevel());
        }
        RepositoryConnectResult result = purRepositoryConnector.connect(username, password);
        this.user = result.getUser();
        this.connected = result.isSuccess();
        this.securityProvider = result.getSecurityProvider();
        this.securityManager = result.getSecurityManager();
        IUnifiedRepository r = result.getUnifiedRepository();
        try {
            this.pur = (IUnifiedRepository) Proxy.newProxyInstance(r.getClass().getClassLoader(), new Class<?>[] { IUnifiedRepository.class }, new UnifiedRepositoryInvocationHandler<IUnifiedRepository>(r));
            if (this.securityProvider != null) {
                this.securityProvider = (RepositorySecurityProvider) Proxy.newProxyInstance(this.securityProvider.getClass().getClassLoader(), new Class<?>[] { RepositorySecurityProvider.class }, new UnifiedRepositoryInvocationHandler<RepositorySecurityProvider>(this.securityProvider));
            }
        } catch (Throwable th) {
            if (log.isError()) {
                log.logError("Failed to setup repository connection", th);
            }
            connected = false;
        }
        this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
        this.connectMessage = result.getConnectMessage();
        this.purRepositoryServiceRegistry = result.repositoryServiceRegistry();
        this.transDelegate = new TransDelegate(this, pur);
        this.jobDelegate = new JobDelegate(this, pur);
    } finally {
        if (connected) {
            if (log.isBasic()) {
                log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.Create.Message"));
            }
            metaStore = new PurRepositoryMetaStore(this);
            // Create the default Pentaho namespace if it does not exist
            try {
                metaStore.createNamespace(PentahoDefaults.NAMESPACE);
                if (log.isBasic()) {
                    log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateSuccess.Message", PentahoDefaults.NAMESPACE));
                }
            } catch (MetaStoreNamespaceExistsException e) {
            // Ignore this exception, we only use it to save a call to check if the namespace exists, as the
            // createNamespace()
            // call will do the check for us and throw this exception.
            } catch (MetaStoreException e) {
                log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
            }
            if (log.isBasic()) {
                log.logBasic(BaseMessages.getString(PKG, "PurRepository.ConnectSuccess.Message"));
            }
        }
    }
}
Also used : EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) PurRepositoryMetaStore(org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

RepositorySecurityProvider (org.pentaho.di.repository.RepositorySecurityProvider)9 Repository (org.pentaho.di.repository.Repository)4 TransMeta (org.pentaho.di.trans.TransMeta)4 Test (org.junit.Test)3 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)3 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)3 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 Date (java.util.Date)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Shell (org.eclipse.swt.widgets.Shell)1 JobMeta (org.pentaho.di.job.JobMeta)1 ObjectId (org.pentaho.di.repository.ObjectId)1 ObjectRevision (org.pentaho.di.repository.ObjectRevision)1 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)1 RepositorySecurityManager (org.pentaho.di.repository.RepositorySecurityManager)1 PurRepositoryMetaStore (org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore)1 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)1 EnterStringDialog (org.pentaho.di.ui.core.dialog.EnterStringDialog)1