summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/config/WBaseDNPage.java
blob: 97774727bea2275996a68d571f36acaeb2c788f5 (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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
// --- 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.config;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.netscape.admin.certsrv.*;
import com.netscape.admin.certsrv.connection.*;
import com.netscape.admin.certsrv.wizard.*;
import com.netscape.certsrv.common.*;

/**
 * CA signing cert for installation wizard.
 *
 * @author Christine Ho
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv.config.install
 */
public class WBaseDNPage extends WizardBasePanel implements IWizardPanel {
    protected JTextField mCNText, mOUText, mOText, mLText, mSTText, mCText;
    protected JTextArea mSubjectDNText;
    public static final String CN = "CN=";
    public static final String OU = "OU=";
    public static final String O = "O=";
    public static final String L = "L=";
    public static final String ST = "ST=";
    public static final String C = "C=";
    public static final String cn = "cn=";
    public static final String ou = "ou=";
    public static final String o = "o=";
    public static final String l = "l=";
    public static final String st = "st=";
    public static final String c = "c=";
    protected JRadioButton mDNComponents;
    protected JRadioButton mDNString;
    protected JTextField mSubjectStringText;
    protected JLabel cnLabel;
    protected JLabel ouLabel;
    protected JLabel oLabel;
    protected JLabel lLabel;
    protected JLabel stLabel;
    protected JLabel cLabel;
    protected JLabel subjectDNLabel;
    protected Color mActiveColor;
    //protected JTextArea dnDesc;
    protected boolean displayWarning=false;
    protected String mPanelName;


    public WBaseDNPage(String panelName) {
        super(panelName);
        mPanelName = panelName;
    }

    public boolean isLastPage() {
        return false;
    }

    public boolean initializePanel(WizardInfo info) {
        return true;
    }

    public boolean validatePanel() {
        String str = "";
        if (mDNComponents.isSelected()) {
            str = mOText.getText().trim();
        } else {
            String dnString = mSubjectStringText.getText().trim();
            StringTokenizer tokenizer = new StringTokenizer(dnString, ",");
            while (tokenizer.hasMoreTokens()) {
                String element = ((String)tokenizer.nextToken()).trim();
                if (element.startsWith(O) || element.startsWith(o)) {
                    int index = element.indexOf("=");
                    if (index > -1) {
                        str = element.substring(index+1);
                        break;
                    }
                }
            }
        }

        if (str.equals("") && !displayWarning) {
            String errorMsg = 
              mResource.getString(mPanelName+"_DIALOG_MISSINGO_MESSAGE");
            JOptionPane.showMessageDialog(new JFrame(), errorMsg, "Warning",
              JOptionPane.WARNING_MESSAGE,
              CMSAdminUtil.getImage(CMSAdminResources.IMAGE_WARN_ICON));
/*
            WarningDialog dialog = new WarningDialog(new JFrame(),
              "_TEXT_MISSINGO_LABEL");
*/
            displayWarning = true;
            return false;
        }

        return true;
    }

    public boolean concludePanel(WizardInfo info) {
        return true;
    }

    public void callHelp() {
    }

    public void getUpdateInfo(WizardInfo info) {
    }

    protected void populateDN(String str) {
        StringTokenizer tokenizer = new StringTokenizer(str, ",");
        boolean isDNString = false;
        while (tokenizer.hasMoreTokens()) {
            String element = (String)tokenizer.nextToken();
            element = element.trim();
            int index = element.indexOf('=');
            String val = element.substring(index+1);
            if (element.startsWith(CN) || element.startsWith(cn)) {
                mCNText.setText(val);
            } else if (element.startsWith(OU) || element.startsWith(ou)) {
                mOUText.setText(val);
            } else if (element.startsWith(O) || element.startsWith(o)) {
                mOText.setText(val);
            } else if (element.startsWith(L) || element.startsWith(l)) {
                mLText.setText(val);
            } else if (element.startsWith(ST) || element.startsWith(st)) {
                mSTText.setText(val);
            } else if (element.startsWith(C) || element.startsWith(c)) {
                mCText.setText(val);
            } else {
                isDNString = true;
            }
        }

        mSubjectStringText.setText(str);

        if (isDNString) {
            mDNString.setSelected(true);
            enableFields(false, getBackground());
        } else {
            mDNComponents.setSelected(true);
            enableFields(true, mActiveColor);
        }
    }

    protected void init() {
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);

/*
        JLabel currentDN = makeJLabel("SUBJECTNAME");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.weightx = 1.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
          COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(currentDN, gbc);

        dnDesc = createTextArea(" ", 2, 80);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.weightx = 1.0;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(dnDesc, gbc);
*/
        
/*
        JTextArea desc = createTextArea(
          CMSAdminUtil.wrapText(mResource.getString(
            "CACERT2WIZARD_TEXT_DN_LABEL"), 80), 1, 80);
*/

        JTextArea desc = createTextArea(mResource.getString(
          mPanelName+"_LABEL_DN_LABEL"));
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
          COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(desc, gbc);

        mDNComponents = makeJRadioButton("DNCOMP", true);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.weightx = 1.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
          COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mDNComponents, gbc);
     
        cnLabel = makeJLabel("CN");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(cnLabel, gbc);

        mCNText = new JTextField(30); 
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mCNText, gbc);

/*
        JTextArea dummy = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, cnLabel, mCNText, dummy, gbc);
*/
        //CMSAdminUtil.addComponents(this, cnLabel, mCNText, gbc);

        ouLabel = makeJLabel("OU");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE,4*COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(ouLabel, gbc);

        mOUText = new JTextField(30);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(mOUText, gbc);

/*
        JTextArea dummy1 = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, ouLabel, mOUText, dummy1, gbc);
*/
//        CMSAdminUtil.addComponents(this, ouLabel, mOUText, gbc);

        oLabel = makeJLabel("O");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(oLabel, gbc);

        mOText = new JTextField(30);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mOText, gbc);

/*
        JTextArea dummy2 = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, oLabel, mOText, dummy2, gbc);
*/
        //CMSAdminUtil.addComponents(this, oLabel, mOText, gbc);

        lLabel = makeJLabel("LOCALITY");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(lLabel, gbc);

        mLText = new JTextField(30);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mLText, gbc);
/*
        JTextArea dummy3 = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, lLabel, mLText, dummy3, gbc);
*/
        //CMSAdminUtil.addComponents(this, lLabel, mLText, gbc);

        stLabel = makeJLabel("STATE");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(stLabel, gbc);

        mSTText = new JTextField(30);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mSTText, gbc);
/*
        JTextArea dummy4 = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, stLabel, mSTText, dummy4, gbc);
*/
        //CMSAdminUtil.addComponents(this, stLabel, mSTText, gbc);

        cLabel = makeJLabel("COUNTRY");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        add(cLabel, gbc);

        mCText = new JTextField(30);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.WEST;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mCText, gbc);
/*
        JTextArea dummy5 = createTextArea(" ", 1, 1);
        CMSAdminUtil.addComponents(this, cLabel, mCText, dummy5, gbc);
*/
        //CMSAdminUtil.addComponents(this, cLabel, mCText, gbc);

        subjectDNLabel = makeJLabel("SELECTEDDN");
        mSubjectDNText = new SubjectDNTextArea(3, 30);
        mSubjectDNText.setLineWrap(true);
        mSubjectDNText.setBackground(getBackground());
        mSubjectDNText.setEditable(false);
        mSubjectDNText.setCaretColor(getBackground());
        CMSAdminUtil.resetGBC(gbc);
        //gbc.weighty = 1.0;
        CMSAdminUtil.addComponents(this, subjectDNLabel, mSubjectDNText, gbc);

        mDNString = makeJRadioButton("DNSTRING", false);
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.weightx = 1.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
          COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mDNString, gbc);

        ButtonGroup group = new ButtonGroup();
        group.add(mDNString);
        group.add(mDNComponents);

        mSubjectStringText = new JTextField(256);
/*
        mSubjectStringText = new JTextArea(null, null, 0, 0);        
        mSubjectStringText.setBorder(BorderFactory.createLineBorder(Color.black));
        JScrollPane scrollPane = new JScrollPane(mSubjectStringText,
          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setPreferredSize(new Dimension(50, 20));
*/
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.weightx = 1.0;
        //gbc.weighty = 1.0;
        gbc.insets = new Insets(COMPONENT_SPACE, 4*COMPONENT_SPACE, 0,
          COMPONENT_SPACE);
        gbc.fill = gbc.BOTH;
        gbc.gridwidth = gbc.REMAINDER;
        add(mSubjectStringText, gbc);
        //mSubjectStringText.setLineWrap(true);
        mActiveColor = mCNText.getBackground();

        CMSAdminUtil.resetGBC(gbc);
        JLabel d1 = new JLabel();
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridheight = gbc.REMAINDER;
        gbc.gridwidth = gbc.REMAINDER;
        add(d1, gbc);
        

        mCNText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);
        mOUText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);
        mOText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);
        mLText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);
        mSTText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);
        mCText.getDocument().addDocumentListener((DocumentListener)mSubjectDNText);

        super.init();
    }

    protected void enableFields(boolean enable, Color color) {
        CMSAdminUtil.enableJTextField(mCNText, enable, color);
        CMSAdminUtil.enableJTextField(mOUText, enable, color);
        CMSAdminUtil.enableJTextField(mOText, enable, color);
        CMSAdminUtil.enableJTextField(mLText, enable, color);
        CMSAdminUtil.enableJTextField(mSTText, enable, color);
        CMSAdminUtil.enableJTextField(mCText, enable, color);
        cnLabel.setEnabled(enable);
        ouLabel.setEnabled(enable);
        oLabel.setEnabled(enable);
        lLabel.setEnabled(enable);
        stLabel.setEnabled(enable);
        cLabel.setEnabled(enable);
        subjectDNLabel.setEnabled(enable);
        CMSAdminUtil.repaintComp(cnLabel);
        CMSAdminUtil.repaintComp(ouLabel);
        CMSAdminUtil.repaintComp(oLabel);
        CMSAdminUtil.repaintComp(lLabel);
        CMSAdminUtil.repaintComp(stLabel);
        CMSAdminUtil.repaintComp(cLabel);
        CMSAdminUtil.repaintComp(subjectDNLabel);
        if (enable)
            CMSAdminUtil.enableJTextField(mSubjectStringText, !enable, 
              getBackground());
        else
            CMSAdminUtil.enableJTextField(mSubjectStringText, !enable, 
              mActiveColor);
    }

    public void actionPerformed(ActionEvent e) {
        if (mDNComponents.isSelected()) {
            enableFields(true, mActiveColor);
        } else {
            enableFields(false, getBackground());
        } 
    }

    public class SubjectDNTextArea extends JTextArea implements 
      DocumentListener {

        public SubjectDNTextArea(int rows, int columns) {
            super(rows, columns);
        }

        public void insertUpdate(DocumentEvent e) {
            super.setText(updateStr());
        }

        public void removeUpdate(DocumentEvent e) {
            super.setText(updateStr());
        }
 
        public void changedUpdate(DocumentEvent e) {
            super.setText(updateStr());
        }

        private String updateStr() {
            String cnStr = mCNText.getText().trim();
            String ouStr = mOUText.getText().trim();
            String oStr = mOText.getText().trim();
            String lStr = mLText.getText().trim();
            String stStr = mSTText.getText().trim();
            String cStr = mCText.getText().trim();

            String result = "";
            result = result+appendStr(result, CN, cnStr);
            result = result+appendStr(result, OU, ouStr);
            result = result+appendStr(result, O, oStr);
            result = result+appendStr(result, L, lStr);
            result = result+appendStr(result, ST, stStr);
            result = result+appendStr(result, C, cStr);

            return result;
        }

        private String appendStr(String origStr, String prefix, String suffix) {
            String result = "";
            if (suffix.equals(""))
                return result;

            result = prefix + suffix;
            if (!origStr.equals("")) {
                result = ", "+result;
            }
            return result;
        }
    }
}