use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportUsersAndRoles.
@Test
public void testExportUsersAndRoles() {
IUserRoleListService mockDao = mock(IUserRoleListService.class);
IAnyUserSettingService userSettingService = mock(IAnyUserSettingService.class);
UserDetailsService userDetailsService = mock(UserDetailsService.class);
PentahoSystem.registerObject(mockDao);
PentahoSystem.registerObject(userSettingService);
PentahoSystem.registerObject(userDetailsService);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
PentahoSystem.registerObject(roleBindingDao);
String tenantPath = "path";
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
List<String> userList = new ArrayList<String>();
String user = "testUser";
String role = "testRole";
userList.add(user);
when(mockDao.getAllUsers(any(ITenant.class))).thenReturn(userList);
List<String> roleList = new ArrayList<String>();
roleList.add(role);
when(mockDao.getAllRoles()).thenReturn(roleList);
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> permissions = new ArrayList<String>();
permissions.add("read");
map.put("testRole", permissions);
RoleBindingStruct struct = mock(RoleBindingStruct.class);
struct.bindingMap = map;
when(roleBindingDao.getRoleBindingStruct(anyString())).thenReturn(struct);
ArgumentCaptor<UserExport> userCaptor = ArgumentCaptor.forClass(UserExport.class);
ArgumentCaptor<RoleExport> roleCaptor = ArgumentCaptor.forClass(RoleExport.class);
ExportManifest manifest = mock(ExportManifest.class);
exporter.setExportManifest(manifest);
List<IUserSetting> settings = new ArrayList<>();
IUserSetting setting = mock(IUserSetting.class);
settings.add(setting);
when(userSettingService.getUserSettings(user)).thenReturn(settings);
when(userSettingService.getGlobalUserSettings()).thenReturn(settings);
List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
UserDetails userDetails = new User("testUser", "testPassword", true, true, true, true, authList);
when(userDetailsService.loadUserByUsername(anyString())).thenReturn(userDetails);
exporter.exportUsersAndRoles();
verify(manifest).addUserExport(userCaptor.capture());
verify(manifest).addRoleExport(roleCaptor.capture());
verify(userSettingService).getGlobalUserSettings();
verify(manifest).addGlobalUserSetting(any(ExportManifestUserSetting.class));
assertEquals(settings.size(), userCaptor.getValue().getUserSettings().size());
UserExport userExport = userCaptor.getValue();
assertEquals("testUser", userExport.getUsername());
RoleExport roleExport = roleCaptor.getValue();
assertEquals("testRole", roleExport.getRolename());
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingService method getUserSettings.
public List<IUserSetting> getUserSettings() {
// get the global settings and the user settings
// merge unseen global settings into the user settings list
List<IUserSetting> userSettings = new ArrayList<IUserSetting>();
String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath();
Serializable tenantHomeId = repository.getFile(tentantHomePath).getId();
Map<String, Serializable> tenantMetadata = repository.getFileMetadata(tenantHomeId);
for (Map.Entry<String, Serializable> entry : tenantMetadata.entrySet()) {
String key = entry.getKey();
if (key.startsWith(SETTING_PREFIX)) {
UserSetting setting = createSetting(key.substring(SETTING_PREFIX.length()), entry.getValue());
userSettings.add(setting);
}
}
String homePath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
Serializable userHomeId = repository.getFile(homePath).getId();
Map<String, Serializable> userMetadata = repository.getFileMetadata(userHomeId);
for (Map.Entry<String, Serializable> entry : userMetadata.entrySet()) {
String key = entry.getKey();
if (key.startsWith(SETTING_PREFIX)) {
UserSetting setting = createSetting(key.substring(SETTING_PREFIX.length()), entry.getValue());
// see if a global setting exists which will be overridden
if (userSettings.contains(setting)) {
userSettings.remove(setting);
}
userSettings.add(setting);
}
}
return userSettings;
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSettingUnset.
@Test
public void testGetUserSettingUnset() throws Exception {
final String settingName = "settingName";
final String defaultValue = "defaultValue";
when(session.getAttribute(eq("SPRING_SECURITY_CONTEXT"))).thenReturn(1);
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 testGetUserSettingsByName.
@Test
public void testGetUserSettingsByName() throws Exception {
try {
// autoboxing
((UserSettingServiceForTesting) userSettingService).setCanAdministerOverrideValue(true);
final List<IUserSetting> settings = userSettingService.getUserSettings("test");
assertNotNull(settings);
assertEquals(2, 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());
}
}
} finally {
((UserSettingServiceForTesting) userSettingService).setCanAdministerOverrideValue(null);
}
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSetting.
@Test
public void testGetUserSetting() throws Exception {
final String settingName = USER_SETTING_NAME_3;
final String defaultValue = "defaultValue";
when(session.getAttribute(eq("SPRING_SECURITY_CONTEXT"))).thenReturn(1);
// try to get existing setting
final IUserSetting userSetting = userSettingService.getUserSetting(settingName, defaultValue);
assertEquals(settingName, userSetting.getSettingName());
assertEquals(USER_SETTING_VALUE_3, userSetting.getSettingValue());
}
Aggregations