Search in sources :

Example 1 with KettleSecurityException

use of org.pentaho.di.core.exception.KettleSecurityException in project pdi-platform-plugin by pentaho.

the class PdiAction method connectToRepository.

/**
 * Connects to the PDI repository
 *
 * @param logWriter
 * @return
 * @throws KettleException
 * @throws KettleSecurityException
 * @throws ActionExecutionException
 */
protected Repository connectToRepository(final LogWriter logWriter) throws KettleSecurityException, KettleException, ActionExecutionException {
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_META_REPOSITORY"));
    }
    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_POPULATING_META"));
    }
    boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
    "true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
    try {
        if (singleDiServerInstance) {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug("singleDiServerInstance=true, loading default repository");
            }
            // only load a default enterprise repository. If this option is set, then you cannot load
            // transformations or jobs from anywhere but the local server.
            String repositoriesXml = // $NON-NLS-1$
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><repositories>" + // $NON-NLS-1$
            "<repository><id>PentahoEnterpriseRepository</id>" + "<name>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</name>" + "<description>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</description>" + "<repository_location_url>" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + // $NON-NLS-1$ //$NON-NLS-2$
            "</repository_location_url>" + // $NON-NLS-1$
            "<version_comment_mandatory>N</version_comment_mandatory>" + // $NON-NLS-1$
            "</repository>" + // $NON-NLS-1$
            "</repositories>";
            ByteArrayInputStream sbis = new ByteArrayInputStream(repositoriesXml.getBytes("UTF8"));
            repositoriesMeta.readDataFromInputStream(sbis);
        } else {
            // TODO: add support for specified repositories.xml files...
            // Read from the default $HOME/.kettle/repositories.xml file.
            repositoriesMeta.readData();
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0018_META_REPOSITORY_NOT_POPULATED"), // $NON-NLS-1$
        e);
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_REPOSITORY"));
    }
    // Find the specified repository.
    RepositoryMeta repositoryMeta = null;
    try {
        if (singleDiServerInstance) {
            repositoryMeta = repositoriesMeta.findRepository(SINGLE_DI_SERVER_INSTANCE);
        } else {
            repositoryMeta = repositoriesMeta.findRepository(repositoryName);
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName), // $NON-NLS-1$
        e);
    }
    if (repositoryMeta == null) {
        if (log.isDebugEnabled()) {
            log.debug(pdiUserAppender.getBuffer().toString());
        }
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", // $NON-NLS-1$
        repositoryName));
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_REPOSITORY"));
    }
    Repository repository = null;
    try {
        repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
        repository.init(repositoryMeta);
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE"), // $NON-NLS-1$
        e);
    }
    // OK, now try the username and password
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_CONNECTING"));
    }
    // Two scenarios here: internal to server or external to server. If internal, you are already authenticated. If
    // external, you must provide a username and additionally specify that the IP address of the machine running this
    // code is trusted.
    repository.connect(PentahoSessionHolder.getSession().getName(), "password");
    // OK, the repository is open and ready to use.
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_DIRECTORY"));
    }
    return repository;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) FileNotFoundException(java.io.FileNotFoundException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 2 with KettleSecurityException

use of org.pentaho.di.core.exception.KettleSecurityException in project pentaho-kettle by pentaho.

the class PurRepository method getExporter.

@Override
public IRepositoryExporter getExporter() throws KettleException {
    final List<String> exportPerms = Arrays.asList(IAbsSecurityProvider.CREATE_CONTENT_ACTION, IAbsSecurityProvider.EXECUTE_CONTENT_ACTION);
    IAbsSecurityProvider securityProvider = purRepositoryServiceRegistry.getService(IAbsSecurityProvider.class);
    StringBuilder errorMessage = new StringBuilder("[");
    for (String perm : exportPerms) {
        if (securityProvider == null && PurRepositoryConnector.inProcess()) {
            return new PurRepositoryExporter(this);
        }
        if (securityProvider != null && securityProvider.isAllowed(perm)) {
            return new PurRepositoryExporter(this);
        }
        errorMessage.append(perm);
        errorMessage.append(", ");
    }
    errorMessage.setLength(errorMessage.length() - 2);
    errorMessage.append("]");
    throw new KettleSecurityException(BaseMessages.getString(PKG, "PurRepository.ERROR_0005_INCORRECT_PERMISSION", errorMessage.toString()));
}
Also used : IAbsSecurityProvider(org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Aggregations

KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)1 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)1 RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)1 IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1