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