Search in sources :

Example 16 with IAuthorizationPolicy

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();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Before(org.junit.Before)

Example 17 with IAuthorizationPolicy

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();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) JobMeta(org.pentaho.di.job.JobMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) LogWriter(org.pentaho.di.core.logging.LogWriter) TransMeta(org.pentaho.di.trans.TransMeta)

Example 18 with IAuthorizationPolicy

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));
        }
    });
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Before(org.junit.Before)

Example 19 with IAuthorizationPolicy

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();
}
Also used : PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) MockDataSourceService(org.pentaho.platform.engine.services.MockDataSourceService) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) BeforeClass(org.junit.BeforeClass)

Example 20 with IAuthorizationPolicy

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);
}
Also used : PluginResourceLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) BeforeClass(org.junit.BeforeClass)

Aggregations

IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)40 Test (org.junit.Test)18 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)11 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)7 Serializable (java.io.Serializable)6 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)6 File (java.io.File)5 Before (org.junit.Before)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 FileNotFoundException (java.io.FileNotFoundException)4 HashMap (java.util.HashMap)4 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)4 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)4 PluginClassLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader)4 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)4 InputStream (java.io.InputStream)3 Matchers.anyString (org.mockito.Matchers.anyString)3 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)3 MockSecurityHelper (org.pentaho.test.platform.engine.security.MockSecurityHelper)3 OutputStream (java.io.OutputStream)2