Search in sources :

Example 11 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingsResource method getUserSettings.

/**
 * Retrieve the global settings and the user settings for the current user
 *
 * @return list of settings for the platform
 */
@GET
@Path("/list")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public ArrayList<Setting> getUserSettings() {
    try {
        IUserSettingService settingsService = getUserSettingService();
        List<IUserSetting> userSettings = settingsService.getUserSettings();
        ArrayList<Setting> settings = new ArrayList<Setting>();
        for (IUserSetting userSetting : userSettings) {
            settings.add(new Setting(userSetting.getSettingName(), userSetting.getSettingValue()));
        }
        return settings;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) ArrayList(java.util.ArrayList) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 12 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class PentahoWebContextFilterTest method setup.

@Before
public void setup() throws IOException, ServletException {
    this.serverScheme = "https";
    String serverName = "di.pentaho.local";
    int port = 9055;
    this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
    this.contextRoot = "/the/context/root/";
    this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
    this.mockRequest = mock(HttpServletRequest.class);
    ServletContext mockServletContext = mock(ServletContext.class);
    ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
    Collection<String> mappings = new ArrayList<>(1);
    mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
    when(mockServletRegistration.getMappings()).thenReturn(mappings);
    when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
    when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
    when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
    when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
    when(this.mockRequest.getServerName()).thenReturn(serverName);
    when(this.mockRequest.getServerPort()).thenReturn(port);
    when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
    this.mockResponse = mock(HttpServletResponse.class);
    this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
    when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

        @Override
        public void write(int b) throws IOException {
            PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
        }
    });
    FilterConfig mockFilterConfig = mock(FilterConfig.class);
    this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
    IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
    when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
    doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
    IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
    when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
    doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
    this.activeTheme = "xptoTheme";
    IUserSetting mockUserSetting = mock(IUserSetting.class);
    when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
    IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
    when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
    doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
    this.sessionName = "testSession";
    IPentahoSession mockSession = mock(IPentahoSession.class);
    when(mockSession.getName()).thenReturn(this.sessionName);
    doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
    this.reservedChars = new ArrayList<>(2);
    this.reservedChars.add('r');
    this.reservedChars.add('c');
    doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
    IPluginManager mockPluginManager = mock(IPluginManager.class);
    doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
    doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
    this.pentahoWebContextFilter.init(mockFilterConfig);
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRegistration(javax.servlet.ServletRegistration) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ServletContext(javax.servlet.ServletContext) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) FilterConfig(javax.servlet.FilterConfig) Before(org.junit.Before)

Example 13 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingService method getUserSettings.

@Override
public List<IUserSetting> getUserSettings(String username) throws SecurityException {
    // if the user does not have the setting, check if a global setting exists
    List<IUserSetting> userSettings = new ArrayList<>();
    if (canAdminister()) {
        try {
            String homePath = ClientRepositoryPaths.getUserHomeFolderPath(username);
            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)) {
                    String settingFromKey = key.substring(SETTING_PREFIX.length());
                    userSettings.add(createSetting(settingFromKey, entry.getValue()));
                }
            }
        } catch (Throwable ignored) {
        // if anything goes wrong with authentication (anonymous user) or permissions
        // just return the default value, if we continue to log these errors (like on before Login)
        // we'll see *many* errors in the logs which are not helpful
        }
    } else {
        throw new SecurityException("Unauthorized User");
    }
    return userSettings;
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting)

Example 14 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingService method getGlobalUserSettings.

public List<IUserSetting> getGlobalUserSettings() {
    String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath();
    Serializable tenantHomeId = repository.getFile(tentantHomePath).getId();
    Map<String, Serializable> tenantMetadata = repository.getFileMetadata(tenantHomeId);
    List<IUserSetting> userSettings = new ArrayList<IUserSetting>(tenantMetadata.size());
    for (Map.Entry<String, Serializable> entry : tenantMetadata.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(SETTING_PREFIX)) {
            userSettings.add(createSetting(key.substring(SETTING_PREFIX.length()), entry.getValue()));
        }
    }
    return userSettings;
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting)

Example 15 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class SolutionImportHandler method importUserSettings.

protected void importUserSettings(UserExport user) {
    IUserSettingService settingService = PentahoSystem.get(IUserSettingService.class);
    IAnyUserSettingService userSettingService = null;
    if (settingService != null && settingService instanceof IAnyUserSettingService) {
        userSettingService = (IAnyUserSettingService) settingService;
    }
    if (userSettingService != null) {
        List<ExportManifestUserSetting> exportedSettings = user.getUserSettings();
        try {
            for (ExportManifestUserSetting exportedSetting : exportedSettings) {
                if (isOverwriteFile()) {
                    userSettingService.setUserSetting(user.getUsername(), exportedSetting.getName(), exportedSetting.getValue());
                } else {
                    // see if it's there first before we set this setting
                    IUserSetting userSetting = userSettingService.getUserSetting(user.getUsername(), exportedSetting.getName(), null);
                    if (userSetting == null) {
                        // only set it if we didn't find that it exists already
                        userSettingService.setUserSetting(user.getUsername(), exportedSetting.getName(), exportedSetting.getValue());
                    }
                }
            }
        } catch (SecurityException e) {
            log.error(Messages.getInstance().getString("ERROR.ImportingUserSetting", user.getUsername()));
            log.debug(Messages.getInstance().getString("ERROR.ImportingUserSetting", user.getUsername()), e);
        }
    }
}
Also used : IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting)

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