Search in sources :

Example 1 with ExportManifestUserSetting

use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting 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 ExportManifestUserSetting

use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUserSettings_NoOverwrite.

@Test
public void testImportUserSettings_NoOverwrite() throws Exception {
    UserExport user = new UserExport();
    user.setUsername("pentaho");
    user.addUserSetting(new ExportManifestUserSetting("theme", "crystal"));
    user.addUserSetting(new ExportManifestUserSetting("language", "en_US"));
    IAnyUserSettingService userSettingService = Mockito.mock(IAnyUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    importHandler.setOverwriteFile(false);
    IUserSetting existingSetting = Mockito.mock(IUserSetting.class);
    Mockito.when(userSettingService.getUserSetting("pentaho", "theme", null)).thenReturn(existingSetting);
    Mockito.when(userSettingService.getUserSetting("pentaho", "language", null)).thenReturn(null);
    importHandler.importUserSettings(user);
    Mockito.verify(userSettingService, Mockito.never()).setUserSetting("pentaho", "theme", "crystal");
    Mockito.verify(userSettingService).setUserSetting("pentaho", "language", "en_US");
    Mockito.verify(userSettingService).getUserSetting("pentaho", "theme", null);
    Mockito.verify(userSettingService).getUserSetting("pentaho", "language", null);
}
Also used : IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 3 with ExportManifestUserSetting

use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUserSettings.

@Test
public void testImportUserSettings() throws Exception {
    UserExport user = new UserExport();
    user.setUsername("pentaho");
    user.addUserSetting(new ExportManifestUserSetting("theme", "crystal"));
    user.addUserSetting(new ExportManifestUserSetting("language", "en_US"));
    IAnyUserSettingService userSettingService = Mockito.mock(IAnyUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    importHandler.setOverwriteFile(true);
    importHandler.importUserSettings(user);
    Mockito.verify(userSettingService).setUserSetting("pentaho", "theme", "crystal");
    Mockito.verify(userSettingService).setUserSetting("pentaho", "language", "en_US");
}
Also used : IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) Test(org.junit.Test)

Example 4 with ExportManifestUserSetting

use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting 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 5 with ExportManifestUserSetting

use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting 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)

Aggregations

ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)6 Test (org.junit.Test)4 IAnyUserSettingService (org.pentaho.platform.api.usersettings.IAnyUserSettingService)4 IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)4 IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)4 UserExport (org.pentaho.platform.plugin.services.importexport.UserExport)3 ArrayList (java.util.ArrayList)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 RoleExport (org.pentaho.platform.plugin.services.importexport.RoleExport)1 IRoleAuthorizationPolicyRoleBindingDao (org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao)1 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)1