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;
}
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()));
}
Aggregations