use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PentahoWebContextFilterTest method setup.
@Before
public void setup() throws IOException, ServletException {
this.serverScheme = "https";
String serverName = "di.pentaho.local";
int port = 9055;
this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
this.contextRoot = "/the/context/root/";
this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
this.mockRequest = mock(HttpServletRequest.class);
ServletContext mockServletContext = mock(ServletContext.class);
ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
Collection<String> mappings = new ArrayList<>(1);
mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
when(mockServletRegistration.getMappings()).thenReturn(mappings);
when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
when(this.mockRequest.getServerName()).thenReturn(serverName);
when(this.mockRequest.getServerPort()).thenReturn(port);
when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
this.mockResponse = mock(HttpServletResponse.class);
this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
}
});
FilterConfig mockFilterConfig = mock(FilterConfig.class);
this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
this.activeTheme = "xptoTheme";
IUserSetting mockUserSetting = mock(IUserSetting.class);
when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
this.sessionName = "testSession";
IPentahoSession mockSession = mock(IPentahoSession.class);
when(mockSession.getName()).thenReturn(this.sessionName);
doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
this.reservedChars = new ArrayList<>(2);
this.reservedChars.add('r');
this.reservedChars.add('c');
doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
IPluginManager mockPluginManager = mock(IPluginManager.class);
doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
this.pentahoWebContextFilter.init(mockFilterConfig);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class ProxyTrustingFilterTest method doFilterForTrusted.
@Test
public void doFilterForTrusted() throws Exception {
request.setRemoteHost(TRUSTED_IP);
request.addParameter(filter.getParameterName(), "user");
filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
IPentahoSession session = (IPentahoSession) request.getSession().getAttribute(PentahoSystem.PENTAHO_SESSION_KEY);
assertNotNull(session);
assertEquals("user", session.getName());
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class MondrianUserSessionUserRoleListMapper method mapRoles.
//
// This class doesn't necessarily map roles so much as extract rolss from the session,
// and supply them for downstream use. You must provide the sessionProperty to use
// for the roles to pass along to the Mondrian engine
//
@Override
@SuppressWarnings("unchecked")
protected String[] mapRoles(String[] mondrianRoles, String[] platformRoles) {
//
// Note - this mapper doesn't need the mondrian catalog for mapping
// or in fact any of the passed parameters. The roles for this
// user come out of a session variable.
//
IPentahoSession session = PentahoSessionHolder.getSession();
String[] rtn = null;
Object sessionObj = session.getAttribute(sessionProperty);
if (sessionObj != null) {
if (sessionObj instanceof String[]) {
// If it's already a string array, return it
rtn = ((String[]) sessionObj);
} else if (sessionObj instanceof Collection) {
// Any collection, iterate over it and use toString to
// get roles... This will likely lead to no data cases, but
// it's success oriented.
Collection rolesColl = ((Collection) sessionObj);
rtn = new String[rolesColl.size()];
Iterator it = rolesColl.iterator();
int i = 0;
while (it.hasNext()) {
rtn[i] = it.next().toString();
i++;
}
} else if (sessionObj instanceof Object[]) {
// An Object array? Make it simple and toString
// everything
Object[] roleObjs = (Object[]) sessionObj;
rtn = new String[roleObjs.length];
for (int i = 0; i < roleObjs.length; i++) {
rtn[i] = roleObjs[i].toString();
}
} else {
rtn = new String[] { sessionObj.toString() };
}
}
return rtn;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class DefaultBackingRepositoryLifecycleManager method getTenantManager.
/**
* @return the {@link IBackingRepositoryLifecycleManager} that this instance will use. If none has been
* specified, it will default to getting the information from {@link PentahoSystem.get()}
*/
public ITenantManager getTenantManager() {
// Check ... if we haven't been injected with a lifecycle manager, get one from PentahoSystem
try {
IPentahoObjectFactory objectFactory = PentahoSystem.getObjectFactory();
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
return (null != tenantManager ? tenantManager : objectFactory.get(ITenantManager.class, "tenantMgrProxy", pentahoSession));
} catch (ObjectFactoryException e) {
return null;
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PentahoSystemPluginManagerIT method testPerspectiveUnRegistration.
@Test
public void testPerspectiveUnRegistration() throws Exception {
PentahoSystem.clearObjectFactory();
PentahoSystem.registerObject(new IPluginProvider() {
@Override
public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
return Arrays.asList((IPlatformPlugin) new PlatformPlugin() {
@Override
public List<IPluginPerspective> getPluginPerspectives() {
return Arrays.asList(mock(IPluginPerspective.class));
}
@Override
public String getId() {
return "foo";
}
});
}
}, IPluginProvider.class);
pluginManager = new PentahoSystemPluginManager();
pluginManager.reload();
assertEquals(1, PentahoSystem.getAll(IPluginPerspective.class).size());
assertEquals(1, PentahoSystem.getAll(IPlatformPlugin.class).size());
pluginManager.unloadAllPlugins();
assertEquals(0, PentahoSystem.getAll(IPluginPerspective.class).size());
assertEquals(0, PentahoSystem.getAll(IPlatformPlugin.class).size());
pluginManager.reload();
assertEquals(1, PentahoSystem.getAll(IPluginPerspective.class).size());
}
Aggregations