Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
UserPreferences.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.core;
20 
22 import java.util.prefs.BackingStoreException;
24 import java.util.prefs.PreferenceChangeListener;
25 import java.util.prefs.Preferences;
26 import org.openide.util.NbPreferences;
31 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
32 import org.sleuthkit.datamodel.TskData.DbType;
33 
38 public final class UserPreferences {
39 
40  private static final boolean IS_WINDOWS_OS = PlatformUtil.isWindowsOS();
41  private static final Preferences preferences = NbPreferences.forModule(UserPreferences.class);
42  public static final String KEEP_PREFERRED_VIEWER = "KeepPreferredViewer"; // NON-NLS
43  public static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE = "HideKnownFilesInDataSourcesTree"; //NON-NLS
44  public static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE = "HideKnownFilesInViewsTree"; //NON-NLS
45  public static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE = "HideSlackFilesInDataSourcesTree"; //NON-NLS
46  public static final String HIDE_SLACK_FILES_IN_VIEWS_TREE = "HideSlackFilesInViewsTree"; //NON-NLS
47  public static final String DISPLAY_TIMES_IN_LOCAL_TIME = "DisplayTimesInLocalTime"; //NON-NLS
48  public static final String NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
49  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
50  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
51  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
52  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
53  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
54  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
55  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
56  public static final String INDEXING_SERVER_HOST = "IndexingServerHost"; //NON-NLS
57  public static final String INDEXING_SERVER_PORT = "IndexingServerPort"; //NON-NLS
58  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
59  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
60  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
61  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
62  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
63  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
64  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
65  private static final String DEFAULT_PORT_STRING = "61616";
66  private static final int DEFAULT_PORT_INT = 61616;
67  private static final String APP_NAME = "AppName";
68  public static final String SETTINGS_PROPERTIES = "AutoIngest";
69  private static final String MODE = "AutopsyMode"; // NON-NLS
70  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
71  private static final int LOG_FILE_NUM_INT = 10;
72  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
73  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
74  public static final String HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES = "HideCentralRepoCommentsAndOccurrences";
75 
76  // Prevent instantiation.
77  private UserPreferences() {
78  }
79 
80  public enum SelectedMode {
81 
83  AUTOINGEST
84  };
85 
91  public static SelectedMode getMode() {
92  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
93  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
94  return UserPreferences.SelectedMode.values()[ordinal];
95  }
97  }
98 
104  public static void setMode(SelectedMode mode) {
105  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
106  }
107 
114  public static void reloadFromStorage() throws BackingStoreException {
115  preferences.sync();
116  }
117 
125  public static void saveToStorage() throws BackingStoreException {
126  preferences.flush();
127  }
128 
129  public static void addChangeListener(PreferenceChangeListener listener) {
130  preferences.addPreferenceChangeListener(listener);
131  }
132 
133  public static void removeChangeListener(PreferenceChangeListener listener) {
134  preferences.removePreferenceChangeListener(listener);
135  }
136 
137  public static boolean keepPreferredContentViewer() {
138  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
139  }
140 
141  public static void setKeepPreferredContentViewer(boolean value) {
142  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
143  }
144 
145  public static boolean hideKnownFilesInDataSourcesTree() {
146  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
147  }
148 
149  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
150  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
151  }
152 
153  public static boolean hideKnownFilesInViewsTree() {
154  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
155  }
156 
157  public static void setHideKnownFilesInViewsTree(boolean value) {
158  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
159  }
160 
161  public static boolean hideSlackFilesInDataSourcesTree() {
162  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
163  }
164 
165  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
166  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
167  }
168 
169  public static boolean hideSlackFilesInViewsTree() {
170  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
171  }
172 
173  public static void setHideSlackFilesInViewsTree(boolean value) {
174  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
175  }
176 
177  public static boolean displayTimesInLocalTime() {
178  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
179  }
180 
181  public static void setDisplayTimesInLocalTime(boolean value) {
182  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
183  }
184 
185  public static int numberOfFileIngestThreads() {
186  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
187  }
188 
189  public static void setNumberOfFileIngestThreads(int value) {
190  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
191  }
192 
193  @Deprecated
194  public static boolean groupItemsInTreeByDatasource() {
195  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
196  }
197 
198  @Deprecated
199  public static void setGroupItemsInTreeByDatasource(boolean value) {
200  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
201  }
202 
209  public static boolean showOnlyCurrentUserTags() {
210  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
211  }
212 
213 
220  public static void setShowOnlyCurrentUserTags(boolean value) {
221  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
222  }
223 
232  public static boolean hideCentralRepoCommentsAndOccurrences() {
233  return preferences.getBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, false);
234  }
235 
236 
244  public static void setHideCentralRepoCommentsAndOccurrences(boolean value) {
245  preferences.putBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, value);
246  }
247 
255  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
256  DbType dbType;
257  try {
258  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
259  } catch (Exception ex) {
260  dbType = DbType.SQLITE;
261  }
262  try {
263  return new CaseDbConnectionInfo(
264  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
265  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
266  preferences.get(EXTERNAL_DATABASE_USER, ""),
267  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
268  dbType);
269  } catch (TextConverterException ex) {
270  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
271  }
272  }
273 
282  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
283  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
284  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
285  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
286  try {
287  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
288  } catch (TextConverterException ex) {
289  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
290  }
291  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
292  }
293 
294  public static void setIsMultiUserModeEnabled(boolean enabled) {
295  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
296  }
297 
298  public static boolean getIsMultiUserModeEnabled() {
299  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
300  }
301 
302  public static String getIndexingServerHost() {
303  return preferences.get(INDEXING_SERVER_HOST, "");
304  }
305 
306  public static void setIndexingServerHost(String hostName) {
307  preferences.put(INDEXING_SERVER_HOST, hostName);
308  }
309 
310  public static String getIndexingServerPort() {
311  return preferences.get(INDEXING_SERVER_PORT, "8983");
312  }
313 
314  public static void setIndexingServerPort(int port) {
315  preferences.putInt(INDEXING_SERVER_PORT, port);
316  }
317 
326  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
327  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
328  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
329  try {
330  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
331  } catch (TextConverterException ex) {
332  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
333  }
334  }
335 
344  int port;
345  try {
346  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
347  } catch (NumberFormatException ex) {
348  // if there is an error parsing the port number, use the default port number
349  port = DEFAULT_PORT_INT;
350  }
351 
352  try {
353  return new MessageServiceConnectionInfo(
354  preferences.get(MESSAGE_SERVICE_HOST, ""),
355  port,
356  preferences.get(MESSAGE_SERVICE_USER, ""),
357  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
358  } catch (TextConverterException ex) {
359  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
360  }
361  }
362 
368  public static int getProcessTimeOutHrs() {
369  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
370  if (timeOut < 0) {
371  timeOut = 0;
372  }
373  return timeOut;
374  }
375 
381  public static void setProcessTimeOutHrs(int value) {
382  if (value < 0) {
383  value = 0;
384  }
385  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
386  }
387 
395  public static boolean getIsTimeOutEnabled() {
396  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
397  return enabled;
398  }
399 
407  public static void setIsTimeOutEnabled(boolean enabled) {
408  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
409  }
410 
416  public static String getAppName() {
417  return preferences.get(APP_NAME, Version.getName());
418  }
419 
425  public static void setAppName(String name) {
426  preferences.put(APP_NAME, name);
427  }
428 
434  public static int getLogFileCount() {
435  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
436  }
437 
443  public static int getDefaultLogFileCount() {
444  return LOG_FILE_NUM_INT;
445  }
446 
452  public static void setLogFileCount(int count) {
453  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
454  }
455 }
static void setGroupItemsInTreeByDatasource(boolean value)
static void setKeepPreferredContentViewer(boolean value)
static void setDisplayTimesInLocalTime(boolean value)
static void setMode(SelectedMode mode)
static void setHideSlackFilesInViewsTree(boolean value)
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static void setIsTimeOutEnabled(boolean enabled)
static void setIsMultiUserModeEnabled(boolean enabled)
static void removeChangeListener(PreferenceChangeListener listener)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static void setHideKnownFilesInViewsTree(boolean value)
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void setIndexingServerHost(String hostName)
static void setHideCentralRepoCommentsAndOccurrences(boolean value)
static void setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static String getConfigSetting(String moduleName, String settingName)
static void addChangeListener(PreferenceChangeListener listener)
static void setShowOnlyCurrentUserTags(boolean value)
static String convertTextToHexText(String property)
static boolean settingExists(String moduleName, String settingName)
static final String HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2018 Basis Technology. Generated on: Thu Oct 4 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.