summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/security/CertInstallTypePane.java
blob: a55fce2ec30b4c0a6826ad281dc3586721d265b4 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// --- BEGIN COPYRIGHT BLOCK ---
// 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; version 2 of the License.
//
// 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.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv.security;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import com.netscape.management.client.util.*;
import com.netscape.management.nmclf.*;

class CertInstallTypePane extends JPanel implements SuiConstants,
IKeyCertPage {

    JRadioButton thisServer;
    JRadioButton certChain;
    JRadioButton ca;

    JLabel tokenName = new JLabel();
    SingleBytePasswordField passwd = new SingleBytePasswordField(20);
    JLabel certName = new JLabel();

    JLabel _certnameLabel;
    JLabel _tokenLabel;
    JLabel _certType;
    JLabel _passwordLabel;

    public static Hashtable param = new Hashtable();

    IWizardControl control;
    boolean modified = true;

    public JPanel getPanel() {
        return this;
    }

    public boolean pageShow(WizardObservable observable) {
        boolean show =
                ((Boolean)(observable.get("installCert"))).booleanValue();

        control = (IWizardControl)(observable.get("Wizard"));

        passwd.setText((String)(observable.get("keyPasswd")));
        if (passwd.getText().length() == 0) {
            control = (IWizardControl)(observable.get("Wizard"));
            setEnableNextButton();
        }

        if (show) {
            tokenName.setText((String)(observable.get("tokenName")));
            certName.setText((String)(observable.get("certName")));
        }

        return show;
    }

    public boolean pageHide(WizardObservable observable) {


        if (modified) {
            observable.put("keyfilepw", passwd.getText());

            observable.put("CertInstModified", new Boolean(true));

            param.put("certtype" ,
                    thisServer.isSelected() ? "0":
                    (certChain.isSelected() ? "1":"2"));
            param.put("alias" , observable.get("sie"));
            param.put("keyfilepw", passwd.getText());
            observable.put("keyPasswd", passwd.getText());

            if (thisServer.isSelected()) {
                param.put("certname", (String)(observable.get("certName")));
            } else {
                param.remove("certname");
            }

            modified = false;
        }

        return true;
    }

    void setEnableNextButton() {
        if (passwd.getText().length() == 0) {
            control.setCanGoForward(false);
        } else {
            control.setCanGoForward(true);
        }
    }

    class TypeActionListener implements ActionListener, KeyListener {
        public void keyTyped(KeyEvent e) {}
        public void keyPressed(KeyEvent e) {}
        public void keyReleased(KeyEvent e) {
            modified = true;
            setEnableNextButton();
        }

        public void actionPerformed(ActionEvent event) {
            modified = true;

            if (thisServer.isSelected()) {
                certName.setVisible(true);
                _certnameLabel.setVisible(true);

                _passwordLabel.setVisible(true);
                passwd.setVisible(true);

                setEnableNextButton();
            } else {
                certName.setVisible(false);
                _certnameLabel.setVisible(false);

                _passwordLabel.setVisible(false);
                passwd.setVisible(false);

                control.setCanGoForward(true);
            }
        }
    }



    private JPanel getCertTypePane() {
        JPanel certTypePane = new JPanel();
        certTypePane.setLayout(new GridBagLayout());
        int y = 0, x = 0;

        TypeActionListener listener = new TypeActionListener();
        thisServer.addActionListener(listener);
        certChain.addActionListener(listener);
        ca.addActionListener(listener);
        passwd.addKeyListener(listener);

        GridBagUtil.constrain(certTypePane,
                Box.createRigidArea(
                new Dimension(DIFFERENT_COMPONENT_SPACE, 0)), x, y, 1,
                1, 0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);

        GridBagUtil.constrain(certTypePane, new JLabel("1.  "), ++x,
                ++y, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, 0, 0, 0, 0);

        GridBagUtil.constrain(certTypePane, _certType, ++x, y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);

        GridBagUtil.constrain(certTypePane, thisServer, x, ++y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);

        GridBagUtil.constrain(certTypePane, certChain, x, ++y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);

        GridBagUtil.constrain(certTypePane, ca, x, ++y, 1, 1, 1.0, 0.0,
                GridBagConstraints.NORTH, GridBagConstraints.BOTH, 0,
                0, 0, 0);

        return certTypePane;
    }



    private JLabel createRightAlignLabel(String label) {
        return new JLabel(label, JLabel.RIGHT);
    }


    private JPanel getTokenInfoPane() {
        JPanel tokenInfoPane = new JPanel();
        tokenInfoPane.setLayout(new GridBagLayout());
        int y = 0;


        GridBagUtil.constrain(tokenInfoPane, _tokenLabel, 0, y, 1, 1,
                0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        GridBagUtil.constrain(tokenInfoPane, tokenName, 1, y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, DIFFERENT_COMPONENT_SPACE,
                COMPONENT_SPACE, 0);

        GridBagUtil.constrain(tokenInfoPane, _passwordLabel, 0, ++y, 1,
                1, 0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        GridBagUtil.constrain(tokenInfoPane, passwd, 1, y, 1, 1, 1.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, DIFFERENT_COMPONENT_SPACE,
                COMPONENT_SPACE, 0);

        GridBagUtil.constrain(tokenInfoPane, _certnameLabel, 0, ++y, 1,
                1, 0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        GridBagUtil.constrain(tokenInfoPane, certName, 1, y, 1, 1, 1.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, COMPONENT_SPACE,
                COMPONENT_SPACE, 0);

        return tokenInfoPane;
    }


    public CertInstallTypePane() {
        super();
        setLayout(new GridBagLayout());

        ResourceSet resource = KeyCertUtility.getKeyCertWizardResourceSet();
        thisServer = new JRadioButton(
                resource.getString("CertInstallTypePane",
                "thisServerLabel"), true);
        certChain = new JRadioButton(
                resource.getString("CertInstallTypePane",
                "certChainLabel"), false);
        ca = new JRadioButton(
                resource.getString("CertInstallTypePane", "caLabel"),
                false);

        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(thisServer);
        buttonGroup.add(certChain);
        buttonGroup.add(ca);


        _certnameLabel =
                new JLabel(resource.getString("CertInstallTypePane", "certnameLabel"));
        _tokenLabel = createRightAlignLabel(
                resource.getString("CertInstallTypePane", "tokenLabel"));
        _certType =
                new JLabel(resource.getString("CertInstallTypePane", "certType"));
        _passwordLabel = createRightAlignLabel(
                resource.getString("CertInstallTypePane", "passwordLabel"));

        setBorder( new TitledBorder( new CompoundBorder(new EtchedBorder(),
                new EmptyBorder(COMPONENT_SPACE, COMPONENT_SPACE,
                COMPONENT_SPACE, COMPONENT_SPACE)),
                resource.getString("CertInstallTypePane", "title")));

        int y = 0;

        GridBagUtil.constrain(this, getCertTypePane(), 0, ++y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0,
                DIFFERENT_COMPONENT_SPACE, 0);

        GridBagUtil.constrain(this,
                new JLabel(
                resource.getString("CertInstallTypePane", "promptPasswd"))
                , 0, ++y, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, 0, 0, COMPONENT_SPACE, 0);

        GridBagUtil.constrain(this, getTokenInfoPane(), 0, ++y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0,
                DIFFERENT_COMPONENT_SPACE, 0);

        GridBagUtil.constrain(this, Box.createVerticalGlue(), 0, ++y,
                1, 1, 1.0, 1.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);

        GridBagUtil.constrain(this,
                new JLabel(
                resource.getString(null, "clickNextToContinue")), 0,
                ++y, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, 0, 0);
    }

    /*public static void main(String arg[]) {
     JFrame f = new JFrame();
     f.getContentPane().add("North", new CertInstallTypePane());
     f.setSize(400,400);
     f.show();
     }*/

}