1 /* Defaults.java
2    Copyright (C) 2010 Red Hat, Inc.
3 
4 This file is part of IcedTea.
5 
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9 
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19 
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library.  Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24 
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module.  An independent module is a module which is not derived from
32 or based on this library.  If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so.  If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37 
38 package net.sourceforge.jnlp.config;
39 
40 
41 import java.util.HashMap;
42 import java.util.Map;
43 import net.sourceforge.jnlp.ShortcutDesc;
44 import static net.sourceforge.jnlp.config.PathsAndFiles.*;
45 import net.sourceforge.jnlp.runtime.JNLPProxySelector;
46 import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
47 
48 import static net.sourceforge.jnlp.runtime.Translator.R;
49 
50 /**
51  * This class stores the default configuration
52  */
53 public class Defaults {
54 
55 
56     /**
57      * Get the default settings for deployment
58      * @return the default settings for deployment
59      */
getDefaults()60     public static Map<String, Setting<String>> getDefaults() {
61         SecurityManager sm = System.getSecurityManager();
62         if (sm != null) {
63             sm.checkRead(USER_DEPLOYMENT_FILE.getDefaultFullPath());
64             sm.checkRead(USER_DEPLOYMENT_FILE.getFullPath());
65         }
66 
67 
68         /*
69          * This is more or less a straight copy from the deployment
70          * configuration page, with occasional replacements of "" or no-defaults
71          * with null
72          *
73          * The format of this is:
74          * name
75          * checker (can be null or a ValueChecker)
76          * value (can be null or a String)
77          */
78 
79         Object[][] defaults = new Object[][] {
80                 /* infrastructure */
81                 {
82                         DeploymentConfiguration.KEY_USER_CACHE_DIR,
83                         BasicValueValidators.getFilePathValidator(),
84                         CACHE_DIR.getDefaultFullPath()
85                 },
86                 {
87                         DeploymentConfiguration.KEY_USER_PERSISTENCE_CACHE_DIR,
88                         BasicValueValidators.getFilePathValidator(),
89                         PCACHE_DIR.getDefaultFullPath()
90                 },
91                 {
92                         DeploymentConfiguration.KEY_SYSTEM_CACHE_DIR,
93                         BasicValueValidators.getFilePathValidator(),
94                         null
95                 },
96                 {
97                         DeploymentConfiguration.KEY_USER_LOG_DIR,
98                         BasicValueValidators.getFilePathValidator(),
99                         LOG_DIR.getDefaultFullPath()
100                 },
101                 {
102                         DeploymentConfiguration.KEY_USER_TMP_DIR,
103                         BasicValueValidators.getFilePathValidator(),
104                         TMP_DIR.getDefaultFullPath()
105                 },
106                 {
107                         DeploymentConfiguration.KEY_USER_LOCKS_DIR,
108                         BasicValueValidators.getFilePathValidator(),
109                         LOCKS_DIR.getDefaultFullPath()
110                 },
111                 {
112                         DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE,
113                         BasicValueValidators.getFilePathValidator(),
114                         MAIN_LOCK.getDefaultFullPath()
115                 },
116                 /* certificates and policy files */
117                 {
118                         DeploymentConfiguration.KEY_USER_SECURITY_POLICY,
119                         BasicValueValidators.getUrlValidator(),
120                         "file://" + JAVA_POLICY.getDefaultFullPath()
121                 },
122                 {
123                         DeploymentConfiguration.KEY_USER_TRUSTED_CA_CERTS,
124                         BasicValueValidators.getFilePathValidator(),
125                         USER_CACERTS.getDefaultFullPath()
126                 },
127                 {
128                         DeploymentConfiguration.KEY_USER_TRUSTED_JSSE_CA_CERTS,
129                         BasicValueValidators.getFilePathValidator(),
130                         USER_JSSECAC.getDefaultFullPath()
131                 },
132                 {
133                         DeploymentConfiguration.KEY_USER_TRUSTED_CERTS,
134                         BasicValueValidators.getFilePathValidator(),
135                         USER_CERTS.getDefaultFullPath()
136                 },
137                 {
138                         DeploymentConfiguration.KEY_USER_TRUSTED_JSSE_CERTS,
139                         BasicValueValidators.getFilePathValidator(),
140                         USER_JSSECER.getDefaultFullPath()
141                 },
142                 {
143                         DeploymentConfiguration.KEY_USER_TRUSTED_CLIENT_CERTS,
144                         BasicValueValidators.getFilePathValidator(),
145                         USER_CLIENTCERT.getDefaultFullPath()
146                 },
147                 {
148                         DeploymentConfiguration.KEY_SYSTEM_SECURITY_POLICY,
149                         BasicValueValidators.getUrlValidator(),
150                         null
151                 },
152                 {
153                         DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CA_CERTS,
154                         BasicValueValidators.getFilePathValidator(),
155                         SYS_CACERT.getDefaultFullPath()
156                 },
157                 {
158                         DeploymentConfiguration.KEY_SYSTEM_TRUSTED_JSSE_CA_CERTS,
159                         BasicValueValidators.getFilePathValidator(),
160                         SYS_JSSECAC.getDefaultFullPath()
161                 },
162                 {
163                         DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CERTS,
164                         BasicValueValidators.getFilePathValidator(),
165                         SYS_CERT.getDefaultFullPath()
166                 },
167                 {
168                         DeploymentConfiguration.KEY_SYSTEM_TRUSTED_JSSE_CERTS,
169                         BasicValueValidators.getFilePathValidator(),
170                         SYS_JSSECERT.getDefaultFullPath()
171                 },
172                 {
173                         DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CLIENT_CERTS,
174                         BasicValueValidators.getFilePathValidator(),
175                         SYS_CLIENTCERT.getDefaultFullPath()
176                 },
177                 /* security access and control */
178                 {
179                         DeploymentConfiguration.KEY_SECURITY_PROMPT_USER,
180                         BasicValueValidators.getBooleanValidator(),
181                         String.valueOf(true)
182                 },
183                 {
184                         "deployment.security.askgrantdialog.notinca",
185                         BasicValueValidators.getBooleanValidator(),
186                         String.valueOf(true)
187                 },
188                 {
189                         "deployment.security.notinca.warning",
190                         BasicValueValidators.getBooleanValidator(),
191                         String.valueOf(true)
192                 },
193                 {
194                         "deployment.security.expired.warning",
195                         BasicValueValidators.getBooleanValidator(),
196                         String.valueOf(true)
197                 },
198                 {
199                         "deployment.security.jsse.hostmismatch.warning",
200                         BasicValueValidators.getBooleanValidator(),
201                         String.valueOf(true)
202                 },
203                 {
204                         DeploymentConfiguration.KEY_SECURITY_TRUSTED_POLICY,
205                         BasicValueValidators.getFilePathValidator(),
206                         null
207                 },
208                 {
209                         DeploymentConfiguration.KEY_SECURITY_ALLOW_HIDE_WINDOW_WARNING,
210                         BasicValueValidators.getBooleanValidator(),
211                         String.valueOf(true)
212                 },
213                 {
214                         DeploymentConfiguration.KEY_SECURITY_PROMPT_USER_FOR_JNLP,
215                         BasicValueValidators.getBooleanValidator(),
216                         String.valueOf(true)
217                 },
218                 {
219                         DeploymentConfiguration.KEY_STRICT_JNLP_CLASSLOADER,
220                         BasicValueValidators.getBooleanValidator(),
221                         String.valueOf(true)
222                 },
223                                 {
224                         DeploymentConfiguration.KEY_SECURITY_PROMPT_USER_FOR_JNLP,
225                         BasicValueValidators.getBooleanValidator(),
226                         String.valueOf(true)
227                 },
228                 /* networking */
229                 {
230                         DeploymentConfiguration.KEY_PROXY_TYPE,
231                         BasicValueValidators.getRangedIntegerValidator(JNLPProxySelector.PROXY_TYPE_UNKNOWN, JNLPProxySelector.PROXY_TYPE_BROWSER),
232                         String.valueOf(JNLPProxySelector.PROXY_TYPE_BROWSER)
233                 },
234                 {
235                         DeploymentConfiguration.KEY_PROXY_SAME,
236                         BasicValueValidators.getBooleanValidator(),
237                         String.valueOf(false)
238                 },
239                 {
240                         DeploymentConfiguration.KEY_PROXY_AUTO_CONFIG_URL,
241                         BasicValueValidators.getUrlValidator(),
242                         null
243                 },
244                 {
245                         DeploymentConfiguration.KEY_PROXY_BYPASS_LIST,
246                         null,
247                         null
248                 },
249                 {
250                         DeploymentConfiguration.KEY_PROXY_BYPASS_LOCAL,
251                         null,
252                         null
253                 },
254                 {
255                         DeploymentConfiguration.KEY_PROXY_HTTP_HOST,
256                         null,
257                         null
258                 },
259                 {
260                         DeploymentConfiguration.KEY_PROXY_HTTP_PORT,
261                         null,
262                         null
263                 },
264                 {
265                         DeploymentConfiguration.KEY_PROXY_HTTPS_HOST,
266                         null,
267                         null
268                 },
269                 {
270                         DeploymentConfiguration.KEY_PROXY_HTTPS_PORT,
271                         null,
272                         null
273                 },
274                 {
275                         DeploymentConfiguration.KEY_PROXY_FTP_HOST,
276                         null,
277                         null
278                 },
279                 {
280                         DeploymentConfiguration.KEY_PROXY_FTP_PORT,
281                         null,
282                         null
283                 },
284                 {
285                         DeploymentConfiguration.KEY_PROXY_SOCKS4_HOST,
286                         null,
287                         null
288                 },
289                 {
290                         DeploymentConfiguration.KEY_PROXY_SOCKS4_PORT,
291                         null,
292                         null
293                 },
294                 {
295                         DeploymentConfiguration.KEY_PROXY_OVERRIDE_HOSTS,
296                         null,
297                         null
298                 },
299                 /* cache and optional package repository */
300                 {
301                         "deployment.cache.max.size",
302                         BasicValueValidators.getRangedIntegerValidator(-1, Integer.MAX_VALUE),
303                         String.valueOf("-1")
304                 },
305                 {
306                         "deployment.cache.jarcompression",
307                         BasicValueValidators.getRangedIntegerValidator(0, 10),
308                         String.valueOf(0)
309                 },
310                 {
311                         "deployment.javapi.cache.enabled",
312                         BasicValueValidators.getBooleanValidator(),
313                         String.valueOf(false)
314                 },
315                 /* java console */
316                 {
317                         DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE,
318                         BasicValueValidators.getStringValidator(new String[] {
319                                 DeploymentConfiguration.CONSOLE_DISABLE,
320                                 DeploymentConfiguration.CONSOLE_HIDE,
321                                 DeploymentConfiguration.CONSOLE_SHOW,
322                                 DeploymentConfiguration.CONSOLE_SHOW_PLUGIN,
323                                 DeploymentConfiguration.CONSOLE_SHOW_JAVAWS
324                         }),
325                         DeploymentConfiguration.CONSOLE_HIDE
326                 },
327                 {
328                         DeploymentConfiguration.KEY_ENABLE_LOGGING,
329                         BasicValueValidators.getBooleanValidator(),
330                         String.valueOf(false)
331                 },
332                 {
333                         DeploymentConfiguration.KEY_ENABLE_LOGGING_HEADERS,
334                         BasicValueValidators.getBooleanValidator(),
335                         String.valueOf(false)
336                 },
337                 {
338                         DeploymentConfiguration.KEY_ENABLE_LOGGING_TOFILE,
339                         BasicValueValidators.getBooleanValidator(),
340                         String.valueOf(false)
341                 },
342                 {
343                         DeploymentConfiguration.KEY_ENABLE_APPLICATION_LOGGING_TOFILE,
344                         BasicValueValidators.getBooleanValidator(),
345                         String.valueOf(false)
346                 },
347                  {
348                         DeploymentConfiguration.KEY_ENABLE_LEGACY_LOGBASEDFILELOG,
349                         BasicValueValidators.getBooleanValidator(),
350                         String.valueOf(true)
351                 },
352                 {
353                         DeploymentConfiguration.KEY_ENABLE_LOGGING_TOSTREAMS,
354                         BasicValueValidators.getBooleanValidator(),
355                         String.valueOf(true)
356                 },
357                 {
358                         DeploymentConfiguration.KEY_ENABLE_LOGGING_TOSYSTEMLOG,
359                         BasicValueValidators.getBooleanValidator(),
360                         String.valueOf(true)
361                 },
362                 /* JNLP association */
363                 {
364                         DeploymentConfiguration.KEY_JNLP_ASSOCIATIONS,
365                         BasicValueValidators.getRangedIntegerValidator(DeploymentConfiguration.JNLP_ASSOCIATION_NEVER,
366                                 DeploymentConfiguration.JNLP_ASSOCIATION_REPLACE_ASK),
367                         String.valueOf(DeploymentConfiguration.JNLP_ASSOCIATION_ASK_USER)
368                 },
369                 /* desktop integration */
370                 {
371                         DeploymentConfiguration.KEY_CREATE_DESKTOP_SHORTCUT,
372                         BasicValueValidators.getStringValidator(new String[] {
373                                 ShortcutDesc.CREATE_ALWAYS,
374                                 ShortcutDesc.CREATE_ALWAYS_IF_HINTED,
375                                 ShortcutDesc.CREATE_ASK_USER,
376                                 ShortcutDesc.CREATE_ASK_USER_IF_HINTED,
377                                 ShortcutDesc.CREATE_NEVER
378                         }),
379                         ShortcutDesc.CREATE_ASK_USER_IF_HINTED
380                 },
381                 /* jre selection */
382                 {
383                         DeploymentConfiguration.KEY_JRE_INTSTALL_URL,
384                         BasicValueValidators.getUrlValidator(),
385                         null
386                 },
387                 /* jre management */
388                 {
389                         DeploymentConfiguration.KEY_AUTO_DOWNLOAD_JRE,
390                         BasicValueValidators.getBooleanValidator(),
391                         String.valueOf(false)
392                 },
393                 /* browser selection */
394                 {
395                         DeploymentConfiguration.KEY_BROWSER_PATH,
396                         BasicValueValidators.getFilePathValidator(),
397                         null
398                 },
399                 /* check for update timeout */
400                 {
401                         DeploymentConfiguration.KEY_UPDATE_TIMEOUT,
402                         BasicValueValidators.getRangedIntegerValidator(0, 10000),
403                         String.valueOf(500)
404                 },
405                 //JVM arguments for plugin
406                 {
407                         DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS,
408                         null,
409                         null
410                 },
411                //unsigned applet security level
412                 {
413                 DeploymentConfiguration.KEY_SECURITY_LEVEL,
414                 new SecurityValueValidator(),
415                 null
416                 },
417                 //JVM executable for itw
418                 {
419                         DeploymentConfiguration.KEY_JRE_DIR,
420                         null,
421                         null
422                 },
423                 //enable manifest-attributes checks
424                 {
425                         DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK,
426                         BasicValueValidators.getManifestAttributeCheckValidator(),
427                         String.valueOf(ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL)
428                 }
429         };
430 
431         HashMap<String, Setting<String>> result = new HashMap<>();
432         for (Object[] default1 : defaults) {
433             String name = (String) default1[0];
434             ValueValidator checker = (ValueValidator) default1[1];
435             String actualValue = (String) default1[2];
436             boolean locked = false;
437             Setting<String> value = new Setting<>(name, R("Unknown"), locked, checker, actualValue, actualValue, R("DCSourceInternal"));
438             result.put(name, value);
439         }
440 
441         return result;
442     }
443 }
444