use of org.pentaho.platform.api.usersettings.pojo.IUserSetting 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.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetGlobalUserSetting.
@Test
public void testGetGlobalUserSetting() throws Exception {
final String settingName = GLOBAL_SETTING_NAME_3;
final String defaultValue = "defaultValue";
final IUserSetting globalUserSetting = userSettingService.getGlobalUserSetting(settingName, defaultValue);
assertEquals(settingName, globalUserSetting.getSettingName());
assertEquals(GLOBAL_SETTING_VALUE_3, globalUserSetting.getSettingValue());
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSettingByName.
@Test
public void testGetUserSettingByName() throws Exception {
final String settingName = USER_SETTING_NAME_3;
final String defaultValue = "defaultValue";
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
// try to get existing setting
final IUserSetting userSetting = userSettingService.getUserSetting("test", settingName, defaultValue);
assertEquals(settingName, userSetting.getSettingName());
assertEquals(USER_SETTING_VALUE_3, userSetting.getSettingValue());
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSettingNoAuth.
@Test
public void testGetUserSettingNoAuth() throws Exception {
final String settingName = "settingName";
final String defaultValue = "defaultValue";
when(session.getAttribute(eq("SPRING_SECURITY_CONTEXT"))).thenReturn(null);
final IUserSetting userSetting = userSettingService.getUserSetting(settingName, defaultValue);
assertEquals(settingName, userSetting.getSettingName());
assertEquals(defaultValue, userSetting.getSettingValue());
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSettings.
@Test
public void testGetUserSettings() throws Exception {
final List<IUserSetting> settings = userSettingService.getUserSettings();
assertNotNull(settings);
assertEquals(3, settings.size());
for (IUserSetting setting : settings) {
if (COMMON_SETTING_NAME.equals(setting.getSettingName())) {
assertEquals(COMMON_USER_SETTING_VALUE, setting.getSettingValue());
} else if (USER_SETTING_NAME_3.equals(setting.getSettingName())) {
assertEquals(USER_SETTING_VALUE_3, setting.getSettingValue());
} else if (GLOBAL_SETTING_NAME_3.equals(setting.getSettingName())) {
assertEquals(GLOBAL_SETTING_VALUE_3, setting.getSettingValue());
}
}
}
Aggregations