Search in sources :

Example 96 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pdi-platform-plugin by pentaho.

the class PdiContentGenerator method execute.

public void execute() throws Exception {
    String pdiPath = repositoryFile.getPath();
    // Test
    pdiComponent.setDirectory(FilenameUtils.getPathNoEndSeparator(pdiPath));
    // see if we are running a transformation or job
    if (repositoryFile.getName().toLowerCase().endsWith(".ktr")) {
        // $NON-NLS-1$
        pdiComponent.setTransformation(FilenameUtils.getBaseName(pdiPath));
    } else if (repositoryFile.getName().toLowerCase().endsWith(".kjb")) {
        // $NON-NLS-1$
        pdiComponent.setJob(FilenameUtils.getBaseName(pdiPath));
    }
    IPentahoSession session = PentahoSessionHolder.getSession();
    long start = System.currentTimeMillis();
    try {
        AuditHelper.audit(session.getId(), session.getName(), pdiPath, getObjectName(), this.getClass().getName(), MessageTypes.INSTANCE_START, instanceId, "", 0, // $NON-NLS-1$
        this);
        // now execute
        pdiComponent.execute();
        AuditHelper.audit(session.getId(), session.getName(), pdiPath, getObjectName(), this.getClass().getName(), MessageTypes.INSTANCE_END, instanceId, "", ((float) (System.currentTimeMillis() - start) / 1000), // $NON-NLS-1$
        this);
    } catch (Exception ex) {
        AuditHelper.audit(session.getId(), session.getName(), pdiPath, getObjectName(), this.getClass().getName(), MessageTypes.INSTANCE_FAILED, instanceId, "", ((float) (System.currentTimeMillis() - start) / 1000), // $NON-NLS-1$
        this);
        logger.error(ex);
        clearOutputBuffer();
        throw ex;
    }
    // Verify if the transformation prepareExecution failed or if there is any error in execution, as this exception is logged
    // and not thrown back
    org.pentaho.platform.plugin.kettle.messages.Messages pdiPluginMessages = org.pentaho.platform.plugin.kettle.messages.Messages.getInstance();
    if (!pdiComponent.isExecutionSuccessful()) {
        clearOutputBuffer();
        String errorMessage = Messages.getInstance().getErrorString("Kettle.ERROR_0011_TRANSFORMATION_PREPARATION_FAILED");
        AuditHelper.audit(session.getId(), session.getName(), pdiPath, getObjectName(), this.getClass().getName(), MessageTypes.INSTANCE_FAILED, instanceId, errorMessage, ((float) (System.currentTimeMillis() - start) / 1000), // $NON-NLS-1$
        this);
        String heading = pdiComponent.isTransPrepareExecutionFailed() ? pdiPluginMessages.getString("PdiAction.STATUS_NOT_RUN_HEADING") : pdiPluginMessages.getString("PdiAction.STATUS_ERRORS_HEADING");
        String description = pdiComponent.isTransPrepareExecutionFailed() ? pdiPluginMessages.getString("PdiAction.STATUS_NOT_RUN_DESC") : pdiPluginMessages.getString("PdiAction.STATUS_ERRORS_DESC");
        outputStringBuilder = formatMessage("content/pdi-platform-plugin/resources/images/alert.svg", heading, description);
        out.write(outputStringBuilder.toString().getBytes());
        return;
    }
    /**
     * Earlier after the execution is completed, code would display the content of LoggingBuffer. But the logs in the
     * LoggingBuffer is not limited to the specified transformation that is being executed and can contains the logging
     * for other transformations that are being executed by other users. To resolve this, the code is modified to
     * display the string "Action Successful" when transformation is executed successfully and display a generic error
     * page in case of exception. The detailed logging will continue to go to the log file
     */
    outputStringBuilder = formatMessage("content/pdi-platform-plugin/resources/images/success.svg", pdiPluginMessages.getString("PdiAction.STATUS_SUCCESS_HEADING"), pdiPluginMessages.getString("PdiAction.STATUS_SUCCESS_DESC"));
    out.write(outputStringBuilder.toString().getBytes());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 97 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pdi-platform-plugin by pentaho.

the class PdiActionTest method init.

@Before
public void init() throws SchedulerException, PlatformInitializationException {
    // $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", SOLUTION_REPOSITORY);
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.delimiter", "/");
    // $NON-NLS-2$
    System.setProperty("PENTAHO_SYS_CFG_PATH", new File(SOLUTION_REPOSITORY + "/pentaho.xml").getAbsolutePath());
    IPentahoSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    scheduler = new QuartzScheduler();
    scheduler.start();
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailService.class);
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.setSettingsProvider(new PathBasedSystemSettings());
    mp.defineInstance(IScheduler.class, scheduler);
    mp.define(ISolutionEngine.class, SolutionEngine.class);
    FileSystemBackedUnifiedRepository repo = new FileSystemBackedUnifiedRepository(SOLUTION_REPOSITORY);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.start();
    SecurityHelper.getInstance().becomeUser(TEST_USER);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) File(java.io.File) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Example 98 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pdi-platform-plugin by pentaho.

the class PdiContentGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    // $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", SOLUTION_REPOSITORY);
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.delimiter", "/");
    // $NON-NLS-2$
    System.setProperty("PENTAHO_SYS_CFG_PATH", new File(SOLUTION_REPOSITORY + "/pentaho.xml").getAbsolutePath());
    IPentahoSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    pdiContentGenerator = new PdiContentGenerator();
    pdiAction = new PdiAction();
    pdiAction.setRepositoryName(KettleFileRepositoryMeta.REPOSITORY_TYPE_ID);
    pdiContentGenerator.setPdiAction(pdiAction);
    outputStream = mock(OutputStream.class);
    repositoryFile = mock(RepositoryFile.class);
    pdiContentGenerator.setOutputStream(outputStream);
    pdiContentGenerator.setRepositoryFile(repositoryFile);
    scheduler = new QuartzScheduler();
    scheduler.start();
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailService.class);
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.defineInstance(IScheduler.class, scheduler);
    mp.define(ISolutionEngine.class, SolutionEngine.class);
    FileSystemBackedUnifiedRepository repo = new FileSystemBackedUnifiedRepository(SOLUTION_REPOSITORY);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.start();
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Example 99 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pdi-platform-plugin by pentaho.

the class UserParametersTest method init.

@Before
public void init() throws PlatformInitializationException {
    System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
    System.setProperty("org.osjava.sj.root", "test-src/simple-jndi");
    System.setProperty("org.osjava.sj.delimiter", "/");
    System.setProperty("PENTAHO_SYS_CFG_PATH", new File(SOLUTION_REPOSITORY + "/pentaho.xml").getAbsolutePath());
    IPentahoSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    mp.define(IUserRoleListService.class, StubUserRoleListService.class);
    mp.define(UserDetailsService.class, StubUserDetailService.class);
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.setSettingsProvider(new PathBasedSystemSettings());
    mp.define(ISolutionEngine.class, SolutionEngine.class);
    FileSystemBackedUnifiedRepository repo = new FileSystemBackedUnifiedRepository(SOLUTION_REPOSITORY);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.start();
    SecurityHelper.getInstance().becomeUser(TEST_USER);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) File(java.io.File) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) Before(org.junit.Before)

Example 100 with IPentahoSession

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

the class PentahoSamlAuthenticationSuccessHandler method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
    try {
        if (authentication instanceof ExpiringUsernameAuthenticationToken) {
            // since no expiration date is passed, this token's behaviour is the same as UsernamePasswordAuthenticationToken
            // also, we would have a hard time supporting a supporting a saml-specific token like this
            // ExpiringUsernameAuthenticationToken in ss2-proxies / ss4-proxies
            // 
            // http://docs.spring.io/spring-security-saml/docs/current/api/org/springframework/security/providers/ExpiringUsernameAuthenticationToken.html
            authentication = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), authentication.getAuthorities());
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }
        // legacy spring ( i.e. non-osgi spring.framework ) SecurityContext storing
        IProxyFactory factory = PentahoSystem.get(IProxyFactory.class);
        Object securityContextProxy = null;
        if (requireProxyWrapping) {
            securityContextProxy = factory.createProxy(SecurityContextHolder.getContext());
            request.setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContextProxy);
        } else {
            request.setAttribute(SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
        }
        // pentaho auth storing
        // $NON-NLS-1$
        logger.info("synchronizing current IPentahoSession with SecurityContext");
        IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
        Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
        pentahoSession.setAuthenticated(authentication.getName());
        // Note: spring-security 2 expects an *array* of GrantedAuthorities ( ss4 uses a list )
        pentahoSession.setAttribute(IPentahoSession.SESSION_ROLES, requireProxyWrapping ? proxyGrantedAuthorities(factory, authentication.getAuthorities()) : authentication.getAuthorities());
        // time to create this user's home folder
        createUserHomeFolder(authentication.getName());
        super.onAuthenticationSuccess(request, new SamlOnRedirectUpdateSessionResponseWrapper(response, request, true, 0, requireProxyWrapping ? securityContextProxy : SecurityContextHolder.getContext(), authentication), authentication);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}
Also used : IProxyFactory(org.pentaho.platform.proxy.api.IProxyFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ExpiringUsernameAuthenticationToken(org.springframework.security.providers.ExpiringUsernameAuthenticationToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SamlOnRedirectUpdateSessionResponseWrapper(org.pentaho.platform.spring.security.saml.responsewrapper.SamlOnRedirectUpdateSessionResponseWrapper) ServletException(javax.servlet.ServletException) ProxyException(org.pentaho.platform.proxy.impl.ProxyException) IOException(java.io.IOException)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10