summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/security/CertRequestTypePane.java
blob: cc36771a6485eb97bdfdb5095be46916b84fa047 (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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// --- 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.*;

/**
 *
 * Step 2 of the certificate request under Key & Cert wizard.
 * Pompt user to enter which type of certificate they want to request
 * and the email address of the CA the request will be sent to.
 *
 * @version    1.0    98/07/10
 * @author     <A HREF="mailto:shihcm@netscape.com">shihcm@netscape.com</A>
 *
 */
class CertRequestTypePane extends JPanel implements SuiConstants,
IKeyCertPage {

    JRadioButton _email;
    SingleByteTextField _emailAddr = new SingleByteTextField();
    JRadioButton _url;
    SingleByteTextField _urlAddr = new SingleByteTextField();

    JLabel _caEmailAddr;

    JRadioButton _new;
    JRadioButton _renew;

    /**
     * Get the panel that is going to be displayed
     * @return a panel to be displayed by the key & cert wizard
     */
    IWizardControl control;
    JButton _caButton;

    MultilineLabel _showCALabel;

    /**
     * Determain whether a cgi need to be call again to decode
     */
    boolean modified = false;

    public static Hashtable param = new Hashtable();

    /**
     * Get the panel that is going to be displayed
     * @return a panel to be displayed by the key & cert wizard
     */
    public JPanel getPanel() {
        return this;
    }


    /**
      * Checks if this panel can be shown
      * @return true if this page can be shown
      */
    public boolean pageShow(WizardObservable observable) {

        boolean show =
                ((Boolean)(observable.get("requestCert"))).booleanValue();

        if (show) {
            control = (IWizardControl)(observable.get("Wizard"));
            setEnableNextButton();
        }

        if (observable.get("CertReqCGIParam") == null) {
            observable.put("CertReqCGIParam", param);
        }

        return show;
    }


    /**
      * Checks if this panel can be hidden
      * @return true if this page can be hide
      */
    public boolean pageHide(WizardObservable observable) {
        KeyCertTaskInfo taskInfo = observable.getTaskInfo();

        //see if this page has been modified.
        if (modified) {
            observable.put("CertReqModified", new Boolean(true));

            //radio button in a group will called twice one for the component that is loosing the focus
            //and one for the component that is getting the focus
            param.put("cert_type" , _new.isSelected() ? "0":"1");

            //remove url support
            param.put("xmt_select" , _email.isSelected() ? "0":"1");
            param.put("url" , _urlAddr.getText());
            param.put("cert_auth" , _emailAddr.getText());

            //support only e-mail at this moment
            //param.put("xmt_select" , "0");
            //param.put("cert_auth"  , _emailAddr.getText());

            modified = false;
        }

        return true;
    }


    /**
      * Listen to changes (key strokes or change in text area or text field)
      * then determain (call setEnableNextButton()) if wizard can proceed
      */
    class TypeActionListener implements KeyListener, ActionListener {
        public void keyTyped(KeyEvent e) {}
        public void keyPressed(KeyEvent e) {}
        public void keyReleased(KeyEvent e) {
            setEnableNextButton();
            modified = true;
        }
        public void actionPerformed(ActionEvent e) {

            if (e.getActionCommand().equals("SHOWCA")) {
                Browser browser = new Browser();
                browser.open("https://certs.netscape.com/server.html",
                        browser.NEW_WINDOW);
            } else {
                if (_email.isSelected()) {
                    _urlAddr.setEnabled(false);
                    _emailAddr.setEnabled(true);
                } else {
                    _urlAddr.setEnabled(true);
                    _emailAddr.setEnabled(false);
                }
                setEnableNextButton();
                modified = true;
            }
        }
    }

    /**
      * Detarmain all the require field has been fill in, if true the
      * enable the "Next >" button.
      */
    void setEnableNextButton() {
        if ((_email.isSelected() && (_emailAddr.getText().length() > 0)) ||
                (_url.isSelected() && (_urlAddr.getText().length() > 0))) {
            control.setCanGoForward(true);
        } else {
            control.setCanGoForward(false);
        }
    }

    /**
      *
      * Convinent method for create a numbered component:
      * [panel]
      *    1. bla bla bla
      *    2. bla bla bla
      * [panel]
      *
      */
    private void addNumberedComponent(JPanel p, int count, Component c,
            Vector components) {
        //JPanel entry = new JPanel();
        //entry.setLayout(new GridBagLayout());
        GridBagUtil.constrain(p,
                Box.createRigidArea(
                new Dimension(DIFFERENT_COMPONENT_SPACE, 0)), 0,
                count - 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.NONE, 0, 0, 0, 0);

        GridBagUtil.constrain(p,
                new JLabel(Integer.toString(count) + ".  "), 1,
                count - 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.NONE, 0, 0, 0, 0);

        GridBagUtil.constrain(p, c, 2, count - 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTH, GridBagConstraints.BOTH, 0,
                0, COMPONENT_SPACE, 0);

        for (int i = 0; i < components.size(); i++) {
            GridBagUtil.constrain(p,
                    (Component)(components.elementAt(i)), 2,
                    count + i, 1, 1, 1.0, 0.0,
                    GridBagConstraints.NORTH, GridBagConstraints.BOTH,
                    0, 0, 0, 0);
        }

        //p.add(entry);
    }



    TypeActionListener listener = new TypeActionListener();


    /**
     * Prompt user to enter e-mail address of the CA where the
     * cert request will submit.
     *
     * Comment out submit by url, will not support in 4.0 but will
     * after 4.1 with agree upon standard between kingpin and cert
     * server.
     *
     */
    private JPanel getRequestViaPane() {
        JPanel requestViaPane = new JPanel();
        requestViaPane.setLayout(new GridBagLayout());

        ButtonGroup buttonTypeGroup = new ButtonGroup();
        buttonTypeGroup.add(_new);
        buttonTypeGroup.add(_renew);

        ButtonGroup buttonViaGroup = new ButtonGroup();
        buttonViaGroup.add(_email);
        buttonViaGroup.add(_url);

        int y = 0;

        _email.addActionListener(listener);
        GridBagUtil.constrain(requestViaPane, _email, 0, y, 1, 1, 0.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        /*GridBagUtil.constrain(requestViaPane, _caEmailAddr,
                              0, y, 1, 1,
                              0.0, 0.0,
                              GridBagConstraints.NORTH, GridBagConstraints.BOTH,
         0, 0, COMPONENT_SPACE, 0);*/

        _emailAddr.addKeyListener(listener);
        GridBagUtil.constrain(requestViaPane, _emailAddr, 1, y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.HORIZONTAL, 0,
                DIFFERENT_COMPONENT_SPACE, COMPONENT_SPACE, 0);

        _url.addActionListener(listener);
        GridBagUtil.constrain(requestViaPane, _url, 0, ++y, 1, 1, 0.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        _urlAddr.addKeyListener(listener);
        GridBagUtil.constrain(requestViaPane, _urlAddr, 1, y, 1, 1,
                1.0, 0.0, GridBagConstraints.NORTH,
                GridBagConstraints.HORIZONTAL, 0,
                DIFFERENT_COMPONENT_SPACE, COMPONENT_SPACE, 0);
        _urlAddr.setEnabled(false);

        return requestViaPane;
    }



    /**
      *
      * return a panel contain a button which if clicked will lunch browser
      * and connect to netscape's cert server site.
      * The site contain links and information regarding CAs and certificate.
      *
      */
    private JPanel getCAButtonPane() {
        JPanel caButtonPane = new JPanel();
        caButtonPane.setLayout(new GridBagLayout());

        GridBagUtil.constrain(caButtonPane, _showCALabel, 0, 0, 1, 1,
                1.0, 0.0, GridBagConstraints.WEST,
                GridBagConstraints.BOTH, 0, 0, COMPONENT_SPACE, 0);

        _caButton.addActionListener(listener);
        _caButton.setActionCommand("SHOWCA");
        GridBagUtil.constrain(caButtonPane, _caButton, 1, 0, 1, 1, 1.0,
                0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
                0, DIFFERENT_COMPONENT_SPACE, COMPONENT_SPACE, 0);

        return caButtonPane;
    }

    /**
      *
      * Create a certificate request type selection pane for key & cert wizard
      *
      *
      */
    public CertRequestTypePane() {
        super();
        setLayout(new GridBagLayout());

        ResourceSet resource = KeyCertUtility.getKeyCertWizardResourceSet();

        _caButton = JButtonFactory.create(
                resource.getString("CertRequestTypePane", "showCAButtonLabel"));
        _email = new JRadioButton( resource.getString("CertRequestTypePane",
                "emailLabel"), true);
        _url = new JRadioButton(
                resource.getString("CertRequestTypePane", "urlLabel"),
                false);
        _new = new JRadioButton( resource.getString("CertRequestTypePane",
                "newcertLabel"), true);
        _renew = new JRadioButton( resource.getString("CertRequestTypePane",
                "renewcertLabel"), false);

        _caEmailAddr =
                new JLabel(resource.getString("CertRequestTypePane", "caEmailLabel"));

        _showCALabel = new MultilineLabel(
                resource.getString("CertRequestTypePane", "showCALabel"));

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

        int y = 0;

        JPanel requestTypePane = new JPanel();
        //requestTypePane.setLayout(new BoxLayout(requestTypePane, BoxLayout.Y_AXIS));
        requestTypePane.setLayout(new GridBagLayout());
        Vector components = new Vector();
        _new.addActionListener(listener);
        _renew.addActionListener(listener);
        components.addElement(_new);
        components.addElement(_renew);
        addNumberedComponent(requestTypePane, ++y,
                new MultilineLabel(
                resource.getString("CertRequestTypePane",
                "requestType")), components);
        GridBagUtil.constrain(this, requestTypePane, 0, y, 1, 1, 0.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0,
                DIFFERENT_COMPONENT_SPACE, 0);

        JPanel requestViaPane = new JPanel();
        //requestViaPane.setLayout(new BoxLayout(requestViaPane, BoxLayout.Y_AXIS));
        requestViaPane.setLayout(new GridBagLayout());
        components = new Vector();
        components.addElement(getRequestViaPane());
        addNumberedComponent(requestViaPane, ++y,
                new MultilineLabel(
                resource.getString("CertRequestTypePane",
                "requestVia")), components);
        //addNumberedComponent(requestViaPane, ++y, new MultilineLabel(resource.getString("CertRequestTypePane", "requestViaEmail")), components);
        GridBagUtil.constrain(this, requestViaPane, 0, y, 1, 1, 0.0,
                0.0, GridBagConstraints.NORTH,
                GridBagConstraints.BOTH, 0, 0,
                DIFFERENT_COMPONENT_SPACE, 0);

        GridBagUtil.constrain(this, getCAButtonPane(), 0, ++y, 1, 1,
                0.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 CertRequestTypePane());
     f.setSize(400,400);
     f.show();
     }*/

}