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