Search in sources :

Example 6 with IUserSettingService

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

the class UserSettingsResource method setUserSetting.

/**
 * Save the value of a particular setting for the current user.
 *
 * @param setting  (Setting name)
 * @param settingValue   (Value of the setting)
 *
 * @return
 */
@POST
@Path("{setting : .+}")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public Response setUserSetting(@PathParam("setting") String setting, String settingValue) {
    IUserSettingService settingsService = getUserSettingService();
    // preventing stored XSS(PPP-3464)
    settingValue = EscapeUtils.escapeJsonOrRaw(settingValue);
    settingsService.setUserSetting(setting, settingValue);
    return Response.ok(settingValue).build();
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Facet(org.codehaus.enunciate.Facet)

Example 7 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 8 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() {
    importHandler.setOverwriteFile(false);
    List<ExportManifestUserSetting> settings = new ArrayList<>();
    settings.add(new ExportManifestUserSetting("language", "en_US"));
    settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
    IUserSettingService userSettingService = mock(IUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    IUserSetting setting = mock(IUserSetting.class);
    when(userSettingService.getGlobalUserSetting("language", null)).thenReturn(null);
    when(userSettingService.getGlobalUserSetting("showHiddenFiles", null)).thenReturn(setting);
    importHandler.importGlobalUserSettings(settings);
    verify(userSettingService).setGlobalUserSetting("language", "en_US");
    verify(userSettingService, never()).setGlobalUserSetting(eq("showHiddenFiles"), nullable(String.class));
    verify(userSettingService).getGlobalUserSetting("language", null);
    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) Mockito.anyString(org.mockito.Mockito.anyString) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 9 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() {
    importHandler.setOverwriteFile(true);
    List<ExportManifestUserSetting> settings = new ArrayList<>();
    settings.add(new ExportManifestUserSetting("language", "en_US"));
    settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
    IUserSettingService userSettingService = mock(IUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    importHandler.importGlobalUserSettings(settings);
    verify(userSettingService).setGlobalUserSetting("language", "en_US");
    verify(userSettingService).setGlobalUserSetting("showHiddenFiles", "false");
    verify(userSettingService, never()).getGlobalUserSetting(nullable(String.class), nullable(String.class));
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 10 with IUserSettingService

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

the class StyledHtmlAxisServiceLister method createContent.

@Override
public void createContent(AxisConfiguration axisConfiguration, ConfigurationContext context, OutputStream out) throws Exception {
    // write out the style sheet and the HTML document
    // $NON-NLS-1$
    out.write("<html>\n<head>".getBytes());
    final IPentahoSession session = PentahoSessionHolder.getSession();
    IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, session);
    String activeThemeName;
    if (session == null || settingsService == null) {
        activeThemeName = PentahoSystem.getSystemSetting("default-activeThemeName", "onyx");
    } else {
        activeThemeName = StringUtils.defaultIfEmpty((String) session.getAttribute("pentaho-user-activeThemeName"), settingsService.getUserSetting("pentaho-user-activeThemeName", PentahoSystem.getSystemSetting("default-activeThemeName", "onyx")).getSettingValue());
    }
    IThemeManager themeManager = PentahoSystem.get(IThemeManager.class, null);
    Theme theme = themeManager.getSystemTheme(activeThemeName);
    final ServletContext servletContext = (ServletContext) PentahoSystem.getApplicationContext().getContext();
    if (servletContext != null) {
        for (ThemeResource res : theme.getResources()) {
            if (res.getLocation().endsWith(".css")) {
                out.write(("<link rel=\"stylesheet\" href=\"" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + theme.getThemeRootDir() + res.getLocation() + "\">").getBytes());
            }
        }
    }
    // $NON-NLS-1$
    out.write("</head>\n<body>\n".getBytes());
    // get the list of services from the core ListServices
    super.createContent(axisConfiguration, context, out);
    // $NON-NLS-1$
    out.write("\n</html>\n".getBytes());
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Theme(org.pentaho.platform.api.ui.Theme) ServletContext(javax.servlet.ServletContext) ThemeResource(org.pentaho.platform.api.ui.ThemeResource)

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 Produces (javax.ws.rs.Produces)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 Test (org.junit.Test)2 Mockito.anyString (org.mockito.Mockito.anyString)2 IThemeManager (org.pentaho.platform.api.ui.IThemeManager)2 Theme (org.pentaho.platform.api.ui.Theme)2 OutputStream (java.io.OutputStream)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1