Search in sources :

Example 1 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class PentahoPlatformExporter method exportUsersAndRoles.

protected void exportUsersAndRoles() {
    log.debug("export users & roles");
    IUserRoleListService userRoleListService = PentahoSystem.get(IUserRoleListService.class);
    UserDetailsService userDetailsService = PentahoSystem.get(UserDetailsService.class);
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
    ITenant tenant = TenantUtils.getCurrentTenant();
    // get the user settings for this user
    IUserSettingService service = getUserSettingService();
    // User Export
    List<String> userList = userRoleListService.getAllUsers(tenant);
    for (String user : userList) {
        UserExport userExport = new UserExport();
        userExport.setUsername(user);
        userExport.setPassword(userDetailsService.loadUserByUsername(user).getPassword());
        for (String role : userRoleListService.getRolesForUser(tenant, user)) {
            userExport.setRole(role);
        }
        if (service != null && service instanceof IAnyUserSettingService) {
            IAnyUserSettingService userSettings = (IAnyUserSettingService) service;
            List<IUserSetting> settings = userSettings.getUserSettings(user);
            if (settings != null) {
                for (IUserSetting setting : settings) {
                    userExport.addUserSetting(new ExportManifestUserSetting(setting));
                }
            }
        }
        this.getExportManifest().addUserExport(userExport);
    }
    // export the global user settings
    if (service != null) {
        List<IUserSetting> globalUserSettings = service.getGlobalUserSettings();
        if (globalUserSettings != null) {
            for (IUserSetting setting : globalUserSettings) {
                getExportManifest().addGlobalUserSetting(new ExportManifestUserSetting(setting));
            }
        }
    }
    // RoleExport
    List<String> roles = userRoleListService.getAllRoles();
    for (String role : roles) {
        RoleExport roleExport = new RoleExport();
        roleExport.setRolename(role);
        roleExport.setPermission(roleBindingDao.getRoleBindingStruct(null).bindingMap.get(role));
        exportManifest.addRoleExport(roleExport);
    }
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) ITenant(org.pentaho.platform.api.mt.ITenant) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) RoleExport(org.pentaho.platform.plugin.services.importexport.RoleExport)

Example 2 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportGlobalUserSetting_noOverwrite.

@Test
public void testImportGlobalUserSetting_noOverwrite() throws Exception {
    importHandler.setOverwriteFile(false);
    List<ExportManifestUserSetting> settings = new ArrayList<>();
    settings.add(new ExportManifestUserSetting("language", "en_US"));
    settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
    IUserSettingService userSettingService = Mockito.mock(IUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    IUserSetting setting = Mockito.mock(IUserSetting.class);
    Mockito.when(userSettingService.getGlobalUserSetting("language", null)).thenReturn(null);
    Mockito.when(userSettingService.getGlobalUserSetting("showHiddenFiles", null)).thenReturn(setting);
    importHandler.importGlobalUserSettings(settings);
    Mockito.verify(userSettingService).setGlobalUserSetting("language", "en_US");
    Mockito.verify(userSettingService, Mockito.never()).setGlobalUserSetting(Mockito.eq("showHiddenFiles"), Mockito.anyString());
    Mockito.verify(userSettingService).getGlobalUserSetting("language", null);
    Mockito.verify(userSettingService).getGlobalUserSetting("showHiddenFiles", null);
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) ArrayList(java.util.ArrayList) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 3 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportGlobalUserSetting.

@Test
public void testImportGlobalUserSetting() throws Exception {
    importHandler.setOverwriteFile(true);
    List<ExportManifestUserSetting> settings = new ArrayList<>();
    settings.add(new ExportManifestUserSetting("language", "en_US"));
    settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
    IUserSettingService userSettingService = Mockito.mock(IUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    importHandler.importGlobalUserSettings(settings);
    Mockito.verify(userSettingService).setGlobalUserSetting("language", "en_US");
    Mockito.verify(userSettingService).setGlobalUserSetting("showHiddenFiles", "false");
    Mockito.verify(userSettingService, Mockito.never()).getGlobalUserSetting(Mockito.anyString(), Mockito.anyString());
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class ThemeServlet method handleRequest.

public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        // look for a passed in theme context (content generator, other named area)
        String moduleName = req.getParameter("context");
        OutputStream out = resp.getOutputStream();
        // $NON-NLS-1$
        resp.setContentType("text/javascript");
        // $NON-NLS-1$
        resp.setHeader("Cache-Control", "no-cache");
        IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, getPentahoSession(req));
        // NOTE: this code should be kept in sync with that of PentahoWebContextFilter.java
        String activeTheme = (String) getPentahoSession(req).getAttribute("pentaho-user-theme");
        String ua = req.getHeader("User-Agent");
        // check if we're coming from a mobile device, if so, lock to system default (ruby)
        if (!StringUtils.isEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
            activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
        }
        if (activeTheme == null) {
            try {
                activeTheme = settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
            } catch (Exception ignored) {
            // the user settings service is not valid in the agile-bi deployment of the
            // server
            }
            if (activeTheme == null) {
                activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
            }
        }
        out.write(("\n\n// Theming scripts. This file is generated by (" + getClass().getName() + ") and cannot be found on disk\n").getBytes());
        out.write(("var active_theme = \"" + activeTheme + "\";\n\n").getBytes());
        // Build-up JSON graph for system theme.
        JSONObject root = new JSONObject();
        JSONObject themeObject;
        for (String systemThemeName : themeManager.getSystemThemeIds()) {
            Theme theme = themeManager.getSystemTheme(systemThemeName);
            themeObject = new JSONObject();
            root.put(theme.getId(), themeObject);
            themeObject.put("rootDir", theme.getThemeRootDir());
            for (ThemeResource res : theme.getResources()) {
                themeObject.append("resources", res.getLocation());
            }
        }
        out.write(("var core_theme_tree = " + root.toString() + ";\n\n").getBytes());
        out.write("// Inject the theme script to handle the insertion of requested theme resources\n\n".getBytes());
        ModuleThemeInfo moduleThemeinfo = themeManager.getModuleThemeInfo(moduleName);
        if (moduleThemeinfo != null) {
            // Build-up JSON graph for module theme.
            root = new JSONObject();
            for (Theme theme : moduleThemeinfo.getModuleThemes()) {
                themeObject = new JSONObject();
                root.put(theme.getName(), themeObject);
                themeObject.put("rootDir", theme.getThemeRootDir());
                for (ThemeResource res : theme.getResources()) {
                    themeObject.append("resources", res.getLocation());
                }
            }
            out.write(("var module_theme_tree = " + root.toString() + ";\n\n").getBytes());
        }
        // createElement & insertBefore
        out.write(("(function() {\n" + "var script = document.createElement('script');\n" + "script.type = 'text/javascript';\n" + // "script.async = false;\n" +
        "script.src = CONTEXT_PATH + 'js/themeResources.js';\n" + "var existing = document.getElementsByTagName('script')[0];\n" + "existing.parentNode.insertBefore(script, existing);\n" + "}());").getBytes());
    } catch (IOException e) {
        logger.debug("IO exception creating Theme info", e);
        throw new ServletException(e);
    } catch (JSONException e) {
        logger.debug("JSON exception creating Theme info", e);
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) JSONObject(org.json.JSONObject) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) OutputStream(java.io.OutputStream) ModuleThemeInfo(org.pentaho.platform.api.ui.ModuleThemeInfo) Theme(org.pentaho.platform.api.ui.Theme) ThemeResource(org.pentaho.platform.api.ui.ThemeResource) JSONException(org.json.JSONException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JSONException(org.json.JSONException)

Example 5 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class UserSettingsResource method getUserSetting.

/**
 * Retrieve a particular user setting for the current user
 *
 * @param setting (Name of the setting)
 *
 * @return value of the setting for the user
 */
@GET
@Path("{setting : .+}")
@Facet(name = "Unsupported")
public Response getUserSetting(@PathParam("setting") String setting) {
    IUserSettingService settingsService = getUserSettingService();
    IUserSetting userSetting = settingsService.getUserSetting(setting, null);
    return Response.ok(userSetting != null ? userSetting.getSettingValue() : null).build();
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)12 IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)6 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Facet (org.codehaus.enunciate.Facet)4 ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)4 IOException (java.io.IOException)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 IThemeManager (org.pentaho.platform.api.ui.IThemeManager)2 Theme (org.pentaho.platform.api.ui.Theme)2 ThemeResource (org.pentaho.platform.api.ui.ThemeResource)2 IAnyUserSettingService (org.pentaho.platform.api.usersettings.IAnyUserSettingService)2 OutputStream (java.io.OutputStream)1 FilterConfig (javax.servlet.FilterConfig)1