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();
}
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);
}
}
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);
}
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));
}
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());
}
Aggregations