use of org.pentaho.platform.engine.core.system.UserSession in project pentaho-platform by pentaho.
the class SecurityHelper method becomeUser.
/**
* Hi-jacks the system for the named user. <p/> <p> This is for unit tests only. </p>
*/
@Override
public void becomeUser(final String principalName, final IParameterProvider paramProvider) {
UserSession session = null;
tenantedUserNameUtils = getTenantedUserNameUtils();
if (tenantedUserNameUtils != null) {
session = new UserSession(principalName, null, false, paramProvider);
ITenant tenant = tenantedUserNameUtils.getTenant(principalName);
session.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
session.setAuthenticated(tenant.getId(), principalName);
} else {
session = new UserSession(principalName, null, false, paramProvider);
session.setAuthenticated(principalName);
}
PentahoSessionHolder.setSession(session);
Authentication auth = createAuthentication(principalName);
// TODO We need to figure out how to inject this
// Get the tenant id from the principle name and set it as an attribute of the pentaho session
// Clearing the SecurityContext to force the subsequent call to getContext() to generate a new SecurityContext.
// This prevents us from modifying the Authentication on a SecurityContext isntance which may be shared between
// threads.
PentahoSessionHolder.getSession().setAttribute(IPentahoSession.SESSION_ROLES, auth.getAuthorities());
SecurityContextHolder.clearContext();
SecurityContextHolder.getContext().setAuthentication(auth);
PentahoSystem.sessionStartup(PentahoSessionHolder.getSession(), paramProvider);
}
use of org.pentaho.platform.engine.core.system.UserSession in project pentaho-platform by pentaho.
the class SessionIT method testUserSessionWithAuthentication.
public void testUserSessionWithAuthentication() {
startTest();
SimpleParameterProvider parameters = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
parameters.setParameter("actionname", "ViewAction");
// $NON-NLS-1$
UserSession usession = new UserSession("Admin", Locale.US, true, parameters);
usession.setActionName("ViewAction");
usession.doStartupActions(parameters);
// $NON-NLS-1$
assertEquals(usession.getActionName(), "ViewAction");
finishTest();
}
use of org.pentaho.platform.engine.core.system.UserSession in project pentaho-platform by pentaho.
the class ProxyTrustingFilter method becomeUser.
// cloned from SecurityHelper and adapted to add a default location to the session
protected void becomeUser(final String principalName) {
UserSession session = null;
Locale locale = Locale.getDefault();
ITenantedPrincipleNameResolver tenantedUserNameUtils = PentahoSystem.get(ITenantedPrincipleNameResolver.class, "tenantedUserNameUtils", null);
if (tenantedUserNameUtils != null) {
session = new UserSession(principalName, locale, false, null);
ITenant tenant = tenantedUserNameUtils.getTenant(principalName);
session.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
session.setAuthenticated(tenant.getId(), principalName);
} else {
session = new UserSession(principalName, locale, false, null);
session.setAuthenticated(principalName);
}
PentahoSessionHolder.setSession(session);
Authentication auth = SecurityHelper.getInstance().createAuthentication(principalName);
SecurityContextHolder.getContext().setAuthentication(auth);
PentahoSystem.sessionStartup(PentahoSessionHolder.getSession(), null);
}
use of org.pentaho.platform.engine.core.system.UserSession in project pentaho-platform by pentaho.
the class ChartIT method runCategoryChartTest.
/*
* public void testChartComponent_AreaChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "area"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Area", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_BarChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Bar", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_BubbleChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "bubble"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Bubble", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session =
* new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_BarLineComboChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "barline"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_BarLineCombo", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession
* session = new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*
* public void testChartComponent_DialChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "dial"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Dial", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_LineChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "line"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Line", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_PieChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "pie"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_Pie", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_PieGridChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "piegrid"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_PieGrid", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session =
* new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/samples/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testChartComponent_TimeSeriesChart() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "timeseries"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_TimeSeries", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session
* = new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testTimeSeriesChartCollection() { SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
* outputStream = getOutputStream(SOLUTION_PATH, "Chart_TimeSeries", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
/*
* public void testXYZChart() { SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
* parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream(SOLUTION_PATH, "Chart_XYZ", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("chart_type", "xy"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
* StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
* SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
* //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
* }
*/
public void runCategoryChartTest(int chartType, String path, String testName) {
// $NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
ArrayList messages = new ArrayList();
int chartWidth = 400;
int chartHeight = 400;
CategoryDatasetChartComponent categoryChartComponent = new CategoryDatasetChartComponent(chartType, path, chartWidth, chartHeight, urlFactory, messages);
categoryChartComponent.setLoggingLevel(ILogger.ERROR);
categoryChartComponent.setByRow(true);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
categoryChartComponent.setDataAction("/test-src/solution/test/rules/department_stats.xaction", "rule-result");
// $NON-NLS-1$//$NON-NLS-2$
OutputStream outputStream = getOutputStream("ChartTest." + testName, ".html");
// $NON-NLS-1$
String contentType = "text/html";
SimpleParameterProvider requestParameters = new SimpleParameterProvider();
SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
HashMap parameterProviders = new HashMap();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParameters);
parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters);
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
// $NON-NLS-1$
UserSession usession = new UserSession("Admin", Locale.US, true, requestParameters);
usession.doStartupActions(requestParameters);
// $NON-NLS-1$
UserSession usessionNoAuth = new UserSession("Admin", Locale.US, requestParameters);
usessionNoAuth.doStartupActions(requestParameters);
SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
try {
categoryChartComponent.validate(session, requestHandler);
categoryChartComponent.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.pentaho.platform.engine.core.system.UserSession in project pentaho-platform by pentaho.
the class SubActionComponent method executeAction.
@SuppressWarnings("deprecation")
@Override
protected boolean executeAction() throws Throwable {
SubActionAction subAction = (SubActionAction) getActionDefinition();
List<Object> ignoreParameters = new ArrayList<Object>();
String actionPath = buildActionPath(subAction.getSolution().getStringValue(), subAction.getPath().getStringValue(), subAction.getAction().getStringValue());
// see if we are supposed to proxy the session
IPentahoSession session = getSession();
if (subAction.getSessionProxy() != ActionInputConstant.NULL_INPUT) {
String sessionName = subAction.getSessionProxy().getStringValue();
// TODO support user-by-user locales
PentahoSessionParameterProvider params = new PentahoSessionParameterProvider(session);
session = new UserSession(sessionName, LocaleHelper.getLocale(), params);
}
// create a parameter provider
HashMap<String, Object> parameters = new HashMap<String, Object>();
Iterator<?> iterator = getInputNames().iterator();
while (iterator.hasNext()) {
String inputName = (String) iterator.next();
if (!StandardSettings.SOLUTION.equals(inputName) && !StandardSettings.PATH.equals(inputName) && !StandardSettings.ACTION.equals(inputName)) {
Object value = getInputValue(inputName);
ignoreParameters.add(value);
parameters.put(inputName, value);
}
}
parameters.put(StandardSettings.ACTION_URL_COMPONENT, getInputStringValue(StandardSettings.ACTION_URL_COMPONENT));
// get the ouptut stream
// TODO verify this with MB and JD
// getDefaultOutputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ISolutionEngine solutionEngine = null;
try {
solutionEngine = SolutionHelper.execute(getProcessId(), session, actionPath, parameters, outputStream, null, true, false);
if (outputStream.size() > 0) {
getDefaultOutputStream(null).write(outputStream.toByteArray());
}
int status = solutionEngine.getStatus();
if (status == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
// now pass any outputs back
Iterator<?> it = this.getOutputNames().iterator();
while (it.hasNext()) {
String outputName = (String) it.next();
IActionParameter param = solutionEngine.getExecutionContext().getOutputParameter(outputName);
if (param != null) {
setOutputValue(outputName, param.getValue());
ignoreParameters.add(param.getValue());
}
}
return true;
} else {
return false;
}
} finally {
if (solutionEngine != null) {
solutionEngine.getExecutionContext().dispose(ignoreParameters);
}
}
}
Aggregations