Search in sources :

Example 81 with IPentahoSession

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);
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRegistration(javax.servlet.ServletRegistration) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ServletContext(javax.servlet.ServletContext) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) FilterConfig(javax.servlet.FilterConfig) Before(org.junit.Before)

Example 82 with IPentahoSession

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());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 83 with IPentahoSession

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;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 84 with IPentahoSession

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;
    }
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 85 with IPentahoSession

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());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) List(java.util.List) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

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