Search in sources :

Example 6 with ISecurityHelper

use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-platform by pentaho.

the class PentahoXmlaServletTest method testInvalidDataSourceInfo.

@Test
public void testInvalidDataSourceInfo() throws Exception {
    ISecurityHelper securityHelper = mock(ISecurityHelper.class);
    SecurityHelper.setMockInstance(securityHelper);
    when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<DataSources>\n" + "<DataSource>\n" + "<DataSourceName>Pentaho</DataSourceName>\n" + "<DataSourceDescription>Pentaho BI Platform Datasources</DataSourceDescription>\n" + "<URL>http://localhost:8080/pentaho/Xmla</URL>\n" + "<DataSourceInfo>Provider=mondrian</DataSourceInfo>\n" + "<ProviderName>PentahoXMLA</ProviderName>\n" + "<ProviderType>MDP</ProviderType>\n" + "<AuthenticationMode>Unauthenticated</AuthenticationMode>\n" + "<Catalogs>\n" + "<Catalog name=\"SampleData\">\n" + "<DataSourceInfo></DataSourceInfo>\n" + "<Definition>mondrian:/SampleData</Definition>\n" + "</Catalog>\n" + "</Catalogs>\n" + "</DataSource>\n" + "</DataSources>\n");
    try {
        // should throw
        new PentahoXmlaServlet().makeContentFinder("fakeurl").getContent();
    } catch (MondrianException e) {
        assertTrue(e.getCause().getCause().getMessage().contains("DataSourceInfo not defined for SampleData"));
        return;
    }
    fail("Did not throw expected exception.");
}
Also used : ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) MondrianException(mondrian.olap.MondrianException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with ISecurityHelper

use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-engineering-samples by pentaho.

the class PentahoSamlAuthenticationSuccessHandler method createUserHomeFolder.

private void createUserHomeFolder(final String username) {
    final ITenant tenantName = JcrTenantUtils.getTenant(username, true);
    final ISecurityHelper securityHelper = PentahoSystem.get(ISecurityHelper.class) != null ? PentahoSystem.get(ISecurityHelper.class) : SecurityHelper.getInstance();
    final IBackingRepositoryLifecycleManager lifecycleManager = PentahoSystem.get(IBackingRepositoryLifecycleManager.class);
    if (tenantName == null || securityHelper == null || lifecycleManager == null) {
        logger.error("null " + (tenantName == null ? "ITenant" : securityHelper == null ? "ISecurityHelper" : "IBackingRepositoryLifecycleManager"));
        return;
    }
    try {
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // Execute new tenant with the tenant id from the logged in user
                lifecycleManager.newTenant(tenantName);
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // Execute new tenant with the tenant id from the logged in user
                lifecycleManager.newUser(tenantName, username);
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        // The newTenant() call should be executed as the system (or more correctly the tenantAdmin)
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                lifecycleManager.newTenant();
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        // run as user to populate SecurityContextHolder and PentahoSessionHolder since Spring Security events are
        // fired before SecurityContextHolder is set
        securityHelper.runAsUser(username, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                lifecycleManager.newUser();
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) ServletException(javax.servlet.ServletException) ProxyException(org.pentaho.platform.proxy.impl.ProxyException) IOException(java.io.IOException) IBackingRepositoryLifecycleManager(org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager)

Example 8 with ISecurityHelper

use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testGetJobInfoError.

@Test
public void testGetJobInfoError() throws Exception {
    String jobId = "jobId";
    Job mockJob = mock(Job.class);
    doReturn(mockJob).when(schedulerService).getJob(jobId);
    ISecurityHelper mockSecurityHelper = mock(ISecurityHelper.class);
    doReturn(mockSecurityHelper).when(schedulerService).getSecurityHelper();
    IPentahoSession mockPentahoSession = mock(IPentahoSession.class);
    doReturn(mockPentahoSession).when(schedulerService).getSession();
    doReturn(false).when(schedulerService).canAdminister(mockPentahoSession);
    String sessionName = "sessionName";
    doReturn(sessionName).when(mockPentahoSession).getName();
    String username = "username";
    doReturn(username).when(mockJob).getUserName();
    try {
        schedulerService.getJobInfo(jobId);
        fail();
    } catch (RuntimeException e) {
    // Expected
    }
}
Also used : ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Aggregations

ISecurityHelper (org.pentaho.platform.api.engine.ISecurityHelper)8 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Serializable (java.io.Serializable)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HashMap (java.util.HashMap)2 MondrianException (mondrian.olap.MondrianException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)2 Job (org.pentaho.platform.api.scheduler2.Job)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 ServletConfig (javax.servlet.ServletConfig)1 ServletException (javax.servlet.ServletException)1