Search in sources :

Example 1 with IUserSetting

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);
    }
}
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 IUserSetting

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());
}
Also used : IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 3 with IUserSetting

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());
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 4 with IUserSetting

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());
}
Also used : IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 5 with IUserSetting

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());
        }
    }
}
Also used : IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Aggregations

IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)21 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)6 ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)5 HashMap (java.util.HashMap)4 IAnyUserSettingService (org.pentaho.platform.api.usersettings.IAnyUserSettingService)4 Serializable (java.io.Serializable)3 Map (java.util.Map)3 UserExport (org.pentaho.platform.plugin.services.importexport.UserExport)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Facet (org.codehaus.enunciate.Facet)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 RoleExport (org.pentaho.platform.plugin.services.importexport.RoleExport)2 IRoleAuthorizationPolicyRoleBindingDao (org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao)2 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)2 IOException (java.io.IOException)1 List (java.util.List)1