Search in sources :

Example 6 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SystemConfigIT method testWrite.

@Test
public void testWrite() throws Exception {
    PentahoSystem.clearObjectFactory();
    IConfiguration c = new PropertiesFileConfiguration("test", new File(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/test.properties"));
    systemConfig.registerConfiguration(c);
    IConfiguration configuration = systemConfig.getConfiguration("test");
    Properties props = configuration.getProperties();
    props.setProperty("someProperty", "new value");
    configuration.update(props);
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/testPropertyPlaceholders.spring.xml");
    context.refresh();
    assertNotNull(context.getBean("testPlaceHolder"));
    assertEquals("new value", context.getBean("testPlaceHolder"));
    props = configuration.getProperties();
    props.setProperty("someProperty", "A dog's tale");
    configuration.update(props);
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 7 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SolutionContextListener method contextInitialized.

public void contextInitialized(final ServletContextEvent event) {
    context = event.getServletContext();
    // $NON-NLS-1$
    String encoding = getServerParameter("encoding");
    if (encoding != null) {
        LocaleHelper.setSystemEncoding(encoding);
    }
    // $NON-NLS-1$
    String textDirection = getServerParameter("text-direction");
    if (textDirection != null) {
        LocaleHelper.setTextDirection(textDirection);
    }
    // $NON-NLS-1$
    String localeLanguage = getServerParameter("locale-language");
    // $NON-NLS-1$
    String localeCountry = getServerParameter("locale-country");
    boolean localeSet = false;
    if (!StringUtils.isEmpty(localeLanguage) && !StringUtils.isEmpty(localeCountry)) {
        Locale[] locales = Locale.getAvailableLocales();
        if (locales != null) {
            for (Locale element : locales) {
                if (element.getLanguage().equals(localeLanguage) && element.getCountry().equals(localeCountry)) {
                    LocaleHelper.setLocale(element);
                    localeSet = true;
                    break;
                }
            }
        }
    }
    if (!localeSet) {
        // do this thread in the default locale
        LocaleHelper.setLocale(Locale.getDefault());
    }
    LocaleHelper.setDefaultLocale(LocaleHelper.getLocale());
    // log everything that goes on here
    // $NON-NLS-1$
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_INITIALIZING"));
    // $NON-NLS-1$
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_SERVLET_CONTEXT", context));
    // $NON-NLS-1$
    SolutionContextListener.contextPath = context.getRealPath("");
    logger.info(// $NON-NLS-1$
    Messages.getInstance().getString("SolutionContextListener.INFO_CONTEXT_PATH", SolutionContextListener.contextPath));
    SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context);
    if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) {
        // $NON-NLS-1$
        String errorMsg = Messages.getInstance().getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH");
        logger.error(errorMsg);
        /*
       * Since we couldn't find solution repository path there is no point in going forward and the user should know
       * that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message.
       */
        throw new RuntimeException(errorMsg);
    }
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_ROOT_PATH", // $NON-NLS-1$
    SolutionContextListener.solutionPath));
    // $NON-NLS-1$
    String fullyQualifiedServerUrl = getServerParameter("fully-qualified-server-url");
    if (fullyQualifiedServerUrl == null) {
        // assume this is a demo installation
        // TODO: Create a servlet that's loaded on startup to set this value
        // $NON-NLS-1$
        fullyQualifiedServerUrl = "http://localhost:8080/pentaho/";
    }
    IApplicationContext applicationContext = new WebApplicationContext(SolutionContextListener.solutionPath, fullyQualifiedServerUrl, context.getRealPath(""), // $NON-NLS-1$
    context);
    /*
     * Copy out all the Server.properties from to the application context
     */
    Properties props = new Properties();
    ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
    if (systemConfig != null) {
        IConfiguration config = systemConfig.getConfiguration("server");
        if (config != null) {
            try {
                props.putAll(config.getProperties());
            } catch (IOException e) {
                logger.error("Could not find/read the server.properties file.");
            }
        }
    }
    /*
     * Copy out all the initParameter values from the servlet context and put them in the application context.
     */
    Enumeration<?> initParmNames = context.getInitParameterNames();
    String initParmName;
    while (initParmNames.hasMoreElements()) {
        initParmName = (String) initParmNames.nextElement();
        props.setProperty(initParmName, getServerParameter(initParmName, true));
    }
    ((WebApplicationContext) applicationContext).setProperties(props);
    setSystemCfgFile(context);
    setObjectFactory(context);
    serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.STARTING);
    serverStatusProvider.setStatusMessages(new String[] { "Caution, the system is initializing. Do not shut down or restart the system at this time." });
    PeriodicStatusLogger.start();
    boolean initOk = false;
    try {
        initOk = PentahoSystem.init(applicationContext);
    } finally {
        updateStatusMessages(initOk);
        PeriodicStatusLogger.stop();
    }
    this.showInitializationMessage(initOk, fullyQualifiedServerUrl);
}
Also used : Locale(java.util.Locale) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IOException(java.io.IOException) Properties(java.util.Properties) IConfiguration(org.pentaho.platform.api.engine.IConfiguration)

Example 8 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class RequestParameterAuthenticationFilter method doFilter.

public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    IConfiguration config = this.systemConfig.getConfiguration("security");
    if (!isRequestAuthenticationParameterLoaded) {
        String strParameter = config.getProperties().getProperty("requestParameterAuthenticationEnabled");
        isRequestParameterAuthenticationEnabled = Boolean.valueOf(strParameter);
        isRequestAuthenticationParameterLoaded = true;
    }
    if (isRequestParameterAuthenticationEnabled) {
        if (!(request instanceof HttpServletRequest)) {
            throw new ServletException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "RequestParameterAuthenticationFilter.ERROR_0005_HTTP_SERVLET_REQUEST_REQUIRED"));
        }
        if (!(response instanceof HttpServletResponse)) {
            throw new ServletException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "RequestParameterAuthenticationFilter.ERROR_0006_HTTP_SERVLET_RESPONSE_REQUIRED"));
        }
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        MultiReadHttpServletRequest wrapper = new MultiReadHttpServletRequest(httpRequest);
        String username = wrapper.getParameter(this.userNameParameter);
        String password = wrapper.getParameter(this.passwordParameter);
        if (RequestParameterAuthenticationFilter.logger.isDebugEnabled()) {
            RequestParameterAuthenticationFilter.logger.debug(Messages.getInstance().getString("RequestParameterAuthenticationFilter.DEBUG_AUTH_USERID", // $NON-NLS-1$
            username));
        }
        if ((username != null) && (password != null)) {
            // Only reauthenticate if username doesn't match SecurityContextHolder and user isn't authenticated (see SEC-53)
            Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();
            password = Encr.decryptPasswordOptionallyEncrypted(password);
            if ((existingAuth == null) || !existingAuth.getName().equals(username) || !existingAuth.isAuthenticated()) {
                UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
                authRequest.setDetails(new WebAuthenticationDetails(httpRequest));
                Authentication authResult;
                try {
                    authResult = authenticationManager.authenticate(authRequest);
                } catch (AuthenticationException failed) {
                    // Authentication failed
                    if (RequestParameterAuthenticationFilter.logger.isDebugEnabled()) {
                        RequestParameterAuthenticationFilter.logger.debug(Messages.getInstance().getString("RequestParameterAuthenticationFilter.DEBUG_AUTHENTICATION_REQUEST", username, // $NON-NLS-1$
                        failed.toString()));
                    }
                    SecurityContextHolder.getContext().setAuthentication(null);
                    if (ignoreFailure) {
                        chain.doFilter(wrapper, response);
                    } else {
                        authenticationEntryPoint.commence(wrapper, (HttpServletResponse) response, failed);
                    }
                    return;
                }
                // Authentication success
                if (RequestParameterAuthenticationFilter.logger.isDebugEnabled()) {
                    RequestParameterAuthenticationFilter.logger.debug(Messages.getInstance().getString("RequestParameterAuthenticationFilter.DEBUG_AUTH_SUCCESS", // $NON-NLS-1$
                    authResult.toString()));
                }
                SecurityContextHolder.getContext().setAuthentication(authResult);
            }
        }
        chain.doFilter(wrapper, response);
    } else {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultiReadHttpServletRequest(org.pentaho.platform.web.http.request.MultiReadHttpServletRequest) ServletException(javax.servlet.ServletException) MultiReadHttpServletRequest(org.pentaho.platform.web.http.request.MultiReadHttpServletRequest) AuthenticationException(org.springframework.security.core.AuthenticationException) Authentication(org.springframework.security.core.Authentication) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) HttpServletResponse(javax.servlet.http.HttpServletResponse) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) IConfiguration(org.pentaho.platform.api.engine.IConfiguration)

Example 9 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SqlMetadataQueryExecTest method testDriverClassesToForceMetaIOE.

@Test
public void testDriverClassesToForceMetaIOE() throws IOException {
    ISystemConfig sysConfig = mock(ISystemConfig.class);
    IConfiguration config = mock(IConfiguration.class);
    when(sysConfig.getConfiguration(SqlMetadataQueryExec.CONFIG_ID)).thenReturn(config);
    when(config.getProperties()).thenThrow(new IOException());
    SqlMetadataQueryExec sqlMetadataQueryExec = new SqlMetadataQueryExec(sysConfig);
    assertEquals(0, sqlMetadataQueryExec.driverClassesToForceMeta.size());
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IOException(java.io.IOException) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Test(org.junit.Test)

Example 10 with IConfiguration

use of org.pentaho.platform.api.engine.IConfiguration in project pentaho-platform by pentaho.

the class SqlMetadataQueryExecTest method testDriverClassesToForceMetaNullProps.

@Test
public void testDriverClassesToForceMetaNullProps() throws IOException {
    ISystemConfig sysConfig = mock(ISystemConfig.class);
    IConfiguration config = mock(IConfiguration.class);
    when(sysConfig.getConfiguration(SqlMetadataQueryExec.CONFIG_ID)).thenReturn(config);
    SqlMetadataQueryExec sqlMetadataQueryExec = new SqlMetadataQueryExec(sysConfig);
    assertEquals(0, sqlMetadataQueryExec.driverClassesToForceMeta.size());
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Test(org.junit.Test)

Aggregations

IConfiguration (org.pentaho.platform.api.engine.IConfiguration)17 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)10 Properties (java.util.Properties)9 Test (org.junit.Test)9 File (java.io.File)4 IOException (java.io.IOException)4 Matchers.anyString (org.mockito.Matchers.anyString)3 Before (org.junit.Before)2 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)2 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1