aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/controlpanel/SecuritySettingsPanel.java
blob: d148b8a680fe156c0fa624eeae35577c962579ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* SecuritySettingsPanel.java -- Display possible security settings.
Copyright (C) 2010 Red Hat

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package net.sourceforge.jnlp.controlpanel;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.sourceforge.jnlp.runtime.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.Translator;

/**
 * This provides a way for the user to modify the security settings through a
 * GUI.
 * 
 * @author Andrew Su (asu@redhat.com, andrew.su@utoronto.ca)
 * 
 */
@SuppressWarnings("serial")
public class SecuritySettingsPanel extends NamedBorderPanel implements ActionListener {

    private DeploymentConfiguration config;

    // NOTE: All the ones listed with "Default" are in Oracle's implementation.
    // Not shown on deployments.properties webpage. Add support for these later!
    /** List of properties used by this panel */
    public static String[] properties = { "deployment.security.askgrantdialog.show",
            "deployment.security.askgrantdialog.notinca",
            "deployment.security.browser.keystore.use", // default TRUE
            "deployment.security.clientauth.keystore.auto", // Default FALSE
            "deployment.security.jsse.hostmismatch.warning",
            "deployment.security.https.warning.show", // Default FALSE
            "deployment.security.sandbox.awtwarningwindow",
            "deployment.security.sandbox.jnlp.enhanced",
            "deployment.security.validation.crl", // Default TRUE
            "deployment.security.validation.ocsp", // Default FALSE
            "deployment.security.pretrust.list", // Default TRUE
            "deployment.security.blacklist.check", // Default TRUE
            "deployment.security.password.cache", // Default TRUE
            "deployment.security.SSLv2Hello", // Default FALSE
            "deployment.security.SSLv3", // Default TRUE
            "deployment.security.TLSv1", // Default TRUE
            //            "deployment.security.mixcode", // Default TRUE
    };

    /**
     * This creates a new instance of the security settings panel.
     * 
     * @param config
     *            Loaded DeploymentConfiguration file.
     */
    public SecuritySettingsPanel(DeploymentConfiguration config) {
        super(Translator.R("CPHeadSecurity"), new BorderLayout());
        this.config = config;

        addComponents();
    }

    /**
     * Add the components to the panel.
     */
    private void addComponents() {
        JPanel topPanel = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        JLabel description = new JLabel("<html>" + Translator.R("CPSecurityDescription") + "<hr /></html>");

        JCheckBox[] securityGeneralOptions = { new JCheckBox(Translator.R("SGPAllowUserGrantSigned")),
                new JCheckBox(Translator.R("SGPAllowUserGrantUntrust")),
                new JCheckBox(Translator.R("SGpUseBrowserKeystore")),
                new JCheckBox(Translator.R("SGPUsePersonalCertOneMatch")),
                new JCheckBox(Translator.R("SGPWarnCertHostMismatch")),
                new JCheckBox(Translator.R("SGPShowValid")),
                new JCheckBox(Translator.R("SGPShowSandboxWarning")),
                new JCheckBox(Translator.R("SGPAllowUserAcceptJNLPSecurityRequests")),
                new JCheckBox(Translator.R("SGPCheckCertRevocationList")),
                new JCheckBox(Translator.R("SGPEnableOnlineCertValidate")),
                new JCheckBox(Translator.R("SGPEnableTrustedPublisherList")),
                new JCheckBox(Translator.R("SGPEnableBlacklistRevocation")),
                new JCheckBox(Translator.R("SGPEnableCachingPassword")),
                new JCheckBox(Translator.R("SGPUseSSL2")),
                new JCheckBox(Translator.R("SGPUseSSL3")),
                new JCheckBox(Translator.R("SGPUseTLS1")), };

        c.fill = GridBagConstraints.BOTH;
        c.gridx = 0;
        c.weightx = 1;

        topPanel.add(description, c);

        // Only display the ones with properties that are valid or existent.
        for (int i = 0; i < properties.length; i++) {
            try {
                String s = config.getProperty(properties[i]);
                securityGeneralOptions[i].setSelected(Boolean.parseBoolean(s));
                securityGeneralOptions[i].setActionCommand(properties[i]);
                securityGeneralOptions[i].addActionListener(this);
                c.gridy = i + 1;
                topPanel.add(securityGeneralOptions[i], c);
            } catch (Exception e) {
                securityGeneralOptions[i] = null;
            }
        }

        Component filler = Box.createRigidArea(new Dimension(1, 1));
        c.weighty = 1;
        c.gridy++;
        topPanel.add(filler, c);

        add(topPanel, BorderLayout.CENTER);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        config.setProperty(e.getActionCommand(), String.valueOf(((JCheckBox) e.getSource()).isSelected()));
    }
}