Search in sources :

Example 1 with MockSecurityHelper

use of org.pentaho.test.platform.engine.security.MockSecurityHelper in project pentaho-platform by pentaho.

the class BaseTest method setUp.

@Override
public void setUp() {
    // used by test repository impl such as FileSystemRepositoryFileDao
    System.setProperty("solution.root.dir", getSolutionPath());
    messages = TestManager.getMessagesList();
    if (messages == null) {
        messages = new ArrayList<String>();
    }
    if (initOk) {
        return;
    }
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    if (PentahoSystem.getApplicationContext() == null) {
        // $NON-NLS-1$
        StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
        // set the base url assuming there is a running server on port 8080
        applicationContext.setFullyQualifiedServerURL(getFullyQualifiedServerURL());
        // $NON-NLS-1$ //$NON-NLS-2$
        String inContainer = System.getProperty("incontainer", "false");
        if (inContainer.equalsIgnoreCase("false")) {
            // $NON-NLS-1$
            // Setup simple-jndi for datasources
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.root", getSolutionPath() + "/system/simple-jndi");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.delimiter", "/");
        }
        ApplicationContext springApplicationContext = getSpringApplicationContext();
        IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
        pentahoObjectFactory.init(null, springApplicationContext);
        PentahoSystem.registerObjectFactory(pentahoObjectFactory);
        // force Spring to inject PentahoSystem, there has got to be a better way than this, perhaps an alternate way
        // of
        // initting spring's app context
        // $NON-NLS-1$
        springApplicationContext.getBean("pentahoSystemProxy");
        // Initialize SecurityHelper with a mock for testing
        SecurityHelper.setMockInstance(new MockSecurityHelper());
        initOk = PentahoSystem.init(applicationContext);
    } else {
        initOk = true;
    }
    // $NON-NLS-1$
    assertTrue(Messages.getInstance().getString("BaseTest.ERROR_0001_FAILED_INITIALIZATION"), initOk);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 2 with MockSecurityHelper

use of org.pentaho.test.platform.engine.security.MockSecurityHelper 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 3 with MockSecurityHelper

use of org.pentaho.test.platform.engine.security.MockSecurityHelper in project pentaho-platform by pentaho.

the class BackingRepositoryLifecycleManagerAuthenticationSuccessListenerTest method testOnApplicationEvent.

public void testOnApplicationEvent() throws Exception {
    final BackingRepositoryLifecycleManagerAuthenticationSuccessListener listener = new BackingRepositoryLifecycleManagerAuthenticationSuccessListener();
    // Test the getters and setters
    final int order = listener.getOrder() + 1;
    listener.setOrder(order);
    assertEquals(order, listener.getOrder());
    assertEquals(SecurityHelper.getInstance(), listener.getSecurityHelper());
    final MockSecurityHelper mockSecurityHelper = new MockSecurityHelper();
    listener.setSecurityHelper(mockSecurityHelper);
    assertEquals(mockSecurityHelper, listener.getSecurityHelper());
    final MockBackingRepositoryLifecycleManager mockLifecycleManager = new MockBackingRepositoryLifecycleManager(mockSecurityHelper);
    mockLifecycleManager.setThrowException(false);
    listener.setLifecycleManager(mockLifecycleManager);
    assertEquals(mockLifecycleManager, listener.getLifecycleManager());
    // Test that the "newTenant() method is executed as the system currentUser and the
    String principleName = usernamePrincipleUtils.getPrincipleId(new Tenant(CURRENT_TENANT, true), CURRENT_USER);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
    final List<MethodTrackingData> methodTrackerHistory1 = mockLifecycleManager.getMethodTrackerHistory();
    assertEquals(4, methodTrackerHistory1.size());
    assertEquals("newTenant", methodTrackerHistory1.get(0).getMethodName());
    assertEquals(2, methodTrackerHistory1.get(0).getParameters().size());
    assertEquals(principleName, methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER));
    assertEquals(CURRENT_TENANT, usernamePrincipleUtils.getTenant((String) methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER)).getId());
    assertEquals("newUser", methodTrackerHistory1.get(1).getMethodName());
    assertEquals(3, methodTrackerHistory1.get(1).getParameters().size());
    // Make sure both methods get called when exceptions are thrown
    mockLifecycleManager.resetCallHistory();
    mockLifecycleManager.setThrowException(true);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) MethodTrackingData(org.pentaho.test.platform.MethodTrackingData) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant)

Example 4 with MockSecurityHelper

use of org.pentaho.test.platform.engine.security.MockSecurityHelper in project data-access by pentaho.

the class SerializeMultiTableServiceIT method setUp.

@Before
public void setUp() throws Exception {
    manager = new MockBackingRepositoryLifecycleManager(new MockSecurityHelper());
    IAuthorizationPolicy mockAuthorizationPolicy = mock(IAuthorizationPolicy.class);
    when(mockAuthorizationPolicy.isAllowed(anyString())).thenReturn(true);
    IUserRoleListService mockUserRoleListService = mock(IUserRoleListService.class);
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
    booter = new MicroPlatform("target/test-classes/solution1");
    booter.define(ISolutionEngine.class, SolutionEngine.class, Scope.GLOBAL);
    booter.define(IUnifiedRepository.class, TestFileSystemBackedUnifiedRepository.class, Scope.GLOBAL);
    booter.define(IMondrianCatalogService.class, MondrianCatalogHelper.class, Scope.GLOBAL);
    booter.define("connection-SQL", SQLConnection.class);
    booter.define("connection-MDX", MDXConnection.class);
    booter.define("connection-MDXOlap4j", MDXOlap4jConnection.class);
    booter.define(IDBDatasourceService.class, JndiDatasourceService.class, Scope.GLOBAL);
    booter.define(MDXConnection.MDX_CONNECTION_MAPPER_KEY, MondrianOneToOneUserRoleListMapper.class, Scope.GLOBAL);
    booter.define(IDatasourceMgmtService.class, MockDatasourceMgmtService.class);
    booter.define(IClientRepositoryPathsStrategy.class, MockClientRepositoryPathsStrategy.class);
    booter.defineInstance(IMetadataDomainRepository.class, createMetadataDomainRepository());
    booter.define(ISecurityHelper.class, MockSecurityHelper.class);
    booter.define(UserDetailsService.class, MockUserDetailService.class);
    booter.define("singleTenantAdminUserName", new String("admin"));
    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(IUserRoleListService.class, mockUserRoleListService);
    booter.setSettingsProvider(new SystemSettings());
    booter.start();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) 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) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) Before(org.junit.Before)

Example 5 with MockSecurityHelper

use of org.pentaho.test.platform.engine.security.MockSecurityHelper in project data-access by pentaho.

the class SerializeServiceIT method setUp.

@Before
public void setUp() throws Exception {
    manager = new MockBackingRepositoryLifecycleManager(new MockSecurityHelper());
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
    booter = new MicroPlatform("target/test-classes/solution1");
    IAuthorizationPolicy mockAuthorizationPolicy = mock(IAuthorizationPolicy.class);
    when(mockAuthorizationPolicy.isAllowed(anyString())).thenReturn(true);
    IUserRoleListService mockUserRoleListService = mock(IUserRoleListService.class);
    booter.define(ISolutionEngine.class, SolutionEngine.class, Scope.GLOBAL);
    booter.define(IUnifiedRepository.class, TestFileSystemBackedUnifiedRepository.class, Scope.GLOBAL);
    booter.define(IMondrianCatalogService.class, MondrianCatalogHelper.class, Scope.GLOBAL);
    booter.define("connection-SQL", SQLConnection.class);
    booter.define("connection-MDX", MDXConnection.class);
    booter.define("connection-MDXOlap4j", MDXOlap4jConnection.class);
    booter.define(IDBDatasourceService.class, JndiDatasourceService.class, Scope.GLOBAL);
    booter.define(MDXConnection.MDX_CONNECTION_MAPPER_KEY, MondrianOneToOneUserRoleListMapper.class, Scope.GLOBAL);
    booter.define(IDatasourceMgmtService.class, MockDatasourceMgmtService.class);
    booter.define(IClientRepositoryPathsStrategy.class, MockClientRepositoryPathsStrategy.class);
    booter.defineInstance(IMetadataDomainRepository.class, createMetadataDomainRepository());
    booter.define(ISecurityHelper.class, MockSecurityHelper.class);
    booter.define(UserDetailsService.class, MockUserDetailService.class);
    booter.define("singleTenantAdminUserName", new String("admin"));
    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(IUserRoleListService.class, mockUserRoleListService);
    booter.setSettingsProvider(new SystemSettings());
    booter.start();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) 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) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PluginClassLoader(org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader) Before(org.junit.Before)

Aggregations

MockSecurityHelper (org.pentaho.test.platform.engine.security.MockSecurityHelper)6 Before (org.junit.Before)4 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)4 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)4 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)3 File (java.io.File)2 Expectations (org.jmock.Expectations)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)2 PluginClassLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader)2 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)2 Mockery (org.jmock.Mockery)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 ICacheManager (org.pentaho.platform.api.engine.ICacheManager)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 Tenant (org.pentaho.platform.core.mt.Tenant)1