use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class SolutionImportHandlerIT method init.
@Before
public void init() throws PlatformInitializationException, SchedulerException {
MicroPlatform mp = new MicroPlatform();
mp.define("IScheduler", TestQuartzScheduler.class);
mp.define(IUserRoleListService.class, StubUserRoleListService.class);
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
mp.defineInstance(IAuthorizationPolicy.class, policy);
mp.start();
scheduler = PentahoSystem.get(IScheduler.class);
scheduler.start();
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pdi-platform-plugin by pentaho.
the class PdiAction method execute.
/**
* Execute the specified transformation in the chosen repository.
*/
public void execute() throws Exception {
// Reset the flag
transPrepExecutionFailure = false;
IAuthorizationPolicy authorizationPolicy = PentahoSystem.get(IAuthorizationPolicy.class, PentahoSessionHolder.getSession());
if (!authorizationPolicy.isAllowed(RepositoryExecuteAction.NAME)) {
throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
"PdiAction.ERROR_0010_NO_PERMISSION_TO_EXECUTE"));
}
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_START"));
}
validate();
TransMeta transMeta = null;
JobMeta jobMeta = null;
// $NON-NLS-1$
LogWriter logWriter = LogWriter.getInstance("Kettle-pentaho", false);
// initialize environment variables
KettleSystemListener.environmentInit(PentahoSessionHolder.getSession());
pdiUserAppender = KettleLogStore.getAppender();
Repository repository = connectToRepository(logWriter);
LoggingBufferAppender loggingBufferAppender = new LoggingBufferAppender(pdiUserAppender);
logWriter.addAppender(loggingBufferAppender);
try {
if (transformation != null) {
// to populate available databases, etc in "standard" kettle fashion
try {
transMeta = createTransMetaJCR(repository);
} catch (Throwable t) {
// ignored
}
if (transMeta == null) {
transMeta = createTransMeta(repository, logWriter);
}
if (transMeta == null) {
throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
"PdiAction.ERROR_0004_FAILED_TRANSMETA_CREATION"));
}
executeTransformation(transMeta, logWriter);
} else if (job != null) {
// to populate available databases, etc in "standard" kettle fashion
try {
jobMeta = createJobMetaJCR(repository);
} catch (Throwable t) {
// ignored
}
if (jobMeta == null) {
jobMeta = createJobMeta(repository, logWriter);
}
if (jobMeta == null) {
throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
"PdiAction.ERROR_0005_FAILED_JOBMETA_CREATION"));
}
executeJob(jobMeta, repository, logWriter);
}
} finally {
logWriter.removeAppender(loggingBufferAppender);
if (repository != null) {
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
}
repository.disconnect();
}
}
XMLHandlerCache.getInstance().clear();
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project data-access by pentaho.
the class MetadataDatasourceServiceTest method setUp.
@Before
public void setUp() throws Exception {
Mockery context = new JUnit4Mockery();
manager = new MockBackingRepositoryLifecycleManager(new MockSecurityHelper());
booter = new MicroPlatform("test-res");
// Clear up the cache
final ICacheManager cacheMgr = PentahoSystem.getCacheManager(null);
cacheMgr.clearRegionCache(MondrianCatalogHelper.MONDRIAN_CATALOG_CACHE_REGION);
// Define a repository for testing
repository = new MockUnifiedRepository(new MockUserProvider());
repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder("metadata").folder(true).build(), "initialization");
final IAuthorizationPolicy policy = context.mock(IAuthorizationPolicy.class);
booter.defineInstance(IAuthorizationPolicy.class, policy);
booter.defineInstance(IUnifiedRepository.class, repository);
booter.start();
logout();
manager.startup();
context.checking(new Expectations() {
{
oneOf(policy);
will(returnValue(true));
oneOf(policy);
will(returnValue(true));
oneOf(policy);
will(returnValue(true));
}
});
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project data-access by pentaho.
the class ConnectionServiceImplIT method setUpClass.
@BeforeClass
public static void setUpClass() throws PlatformInitializationException, DuplicateDatasourceException, DatasourceMgmtServiceException {
MockDataSourceService dataSourceService = new MockDataSourceService(false);
IAuthorizationPolicy mockAuthorizationPolicy = mock(IAuthorizationPolicy.class);
when(mockAuthorizationPolicy.isAllowed(anyString())).thenReturn(true);
booter = new MicroPlatform("target/test-classes/solution1");
booter.define(IPentahoConnection.class, SQLConnection.class);
booter.defineInstance(IDBDatasourceService.class, dataSourceService);
booter.defineInstance(IAuthorizationPolicy.class, mockAuthorizationPolicy);
booter.defineInstance(IPluginResourceLoader.class, new PluginResourceLoader() {
protected PluginClassLoader getOverrideClassloader() {
return new PluginClassLoader(new File(".", "target/test-classes/solution1/system/simple-jndi"), this);
}
});
booter.defineInstance(IDatasourceMgmtService.class, mgmtService);
booter.start();
PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
connectionServiceImpl = new ConnectionServiceImpl();
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project data-access by pentaho.
the class DatasourceResourceIT method setUp.
@BeforeClass
public static void setUp() throws Exception {
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
mp = new MicroPlatform("target/test-classes/solution1");
IAuthorizationPolicy mockAuthorizationPolicy = mock(IAuthorizationPolicy.class);
when(mockAuthorizationPolicy.isAllowed(anyString())).thenReturn(true);
IUserRoleListService mockUserRoleListService = mock(IUserRoleListService.class);
IDataAccessPermissionHandler mockDataAccessPermHandler = mock(IDataAccessPermissionHandler.class);
when(mockDataAccessPermHandler.hasDataAccessPermission(any(IPentahoSession.class))).thenReturn(true);
mp.define(ISolutionEngine.class, SolutionEngine.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
mp.define(IUnifiedRepository.class, TestFileSystemBackedUnifiedRepository.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
mp.define(IMondrianCatalogService.class, MondrianCatalogHelper.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
mp.define("connection-SQL", SQLConnection.class);
mp.define("connection-MDX", MDXConnection.class);
mp.define("connection-MDXOlap4j", MDXOlap4jConnection.class);
mp.define(IDBDatasourceService.class, JndiDatasourceService.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
mp.define(MDXConnection.MDX_CONNECTION_MAPPER_KEY, MondrianOneToOneUserRoleListMapper.class, IPentahoDefinableObjectFactory.Scope.GLOBAL);
mp.define(IDatasourceMgmtService.class, MockDatasourceMgmtService.class);
mp.define(IClientRepositoryPathsStrategy.class, MockClientRepositoryPathsStrategy.class);
mp.define(ISecurityHelper.class, MockSecurityHelper.class);
mp.define(UserDetailsService.class, MockUserDetailService.class);
mp.define("singleTenantAdminUserName", "admin");
mp.defineInstance(IMetadataDomainRepository.class, createMetadataDomainRepository());
mp.defineInstance(IAuthorizationPolicy.class, mockAuthorizationPolicy);
mp.defineInstance(IPluginResourceLoader.class, new PluginResourceLoader() {
protected PluginClassLoader getOverrideClassloader() {
return new PluginClassLoader(new File(".", "target/test-classes/solution1/system/simple-jndi"), this);
}
});
mp.defineInstance(IUserRoleListService.class, mockUserRoleListService);
mp.defineInstance(IDataAccessPermissionHandler.class, mockDataAccessPermHandler);
mp.setSettingsProvider(new SystemSettings());
mp.start();
PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Aggregations