summaryrefslogtreecommitdiffstats
path: root/base/console/src/com/netscape/admin/certsrv/security/CertListTable.java
blob: 62f58d9c2ed45a42b0f8a188c6f298e7ffaf048a (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
// --- 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 com.netscape.management.client.console.*;
import com.netscape.management.client.util.*;
import com.netscape.management.nmclf.*;

import java.util.*;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;

//import crysec.SSL.DBManager;
//import crysec.X509;
//import crysec.X500Name;
//import crysec.Utils;

class CertListTable extends JPanel implements MouseListener, Runnable {
    JTable _table;
    CertListTableModel _dataModel;
    KeyCertTaskInfo _taskInfo;

    String alias;
    String _certName;
    boolean local = false;
    boolean setupComplete;
    Vector certList;
 //   DBManager trustdb;

    //IBackgroundLoaderCallback _callback;

    ConsoleInfo _consoleInfo;

    private String formatLineString(String val, String option,
            boolean newLine) {
        if (val != null) {
            return val + (newLine ? option + "\n":option);
        } else {
            return "";
        }
    }

    public void showCert() {
// to get it compile
/*
        int row = _table.getSelectedRow();
        if (row == -1)
            return;

        //show cert here

        if (local) {
            X509 cert = (X509)(certList.elementAt(row));
            X500Name holder = (X500Name)(cert.getHolder());
            X500Name issuer = (X500Name)(cert.getIssuer());

            StringBuffer subjectString = new StringBuffer();
            StringBuffer issuerString = new StringBuffer();

            subjectString.append(
                    formatLineString(holder.getName(), "", true));
            subjectString.append(
                    formatLineString(holder.getEmail(), "", true));
            subjectString.append(
                    formatLineString(holder.getOrganizationName(), "",
                    true));
            subjectString.append(
                    formatLineString(holder.getOrgUnitName(), "", true));
            subjectString.append(
                    formatLineString(holder.getLocalityName(), "", true));
            subjectString.append(
                    formatLineString(holder.getStateName(), ", ",
                    false) + holder.getCountryName());

            issuerString.append(
                    formatLineString(issuer.getName(), "", true));
            issuerString.append(
                    formatLineString(issuer.getEmail(), "", true));
            issuerString.append(
                    formatLineString(issuer.getOrganizationName(), "",
                    true));
            issuerString.append(
                    formatLineString(issuer.getOrgUnitName(), "", true));
            issuerString.append(
                    formatLineString(issuer.getLocalityName(), "", true));
            issuerString.append(
                    formatLineString(issuer.getStateName(), ", ",
                    false) + issuer.getCountryName());

            CertInfo ci = new CertInfo(holder.getName(),
                    issuerString.toString(), subjectString.toString(),
                    "", "", cert.getNotBeforeDate().toString(),
                    cert.getNotAfterDate().toString(),
                    new String(cert.getFingerprint()), "1", "0",
                    holder.getOrganizationName());

            CertInfoDialog infoDialog = new CertInfoDialog(null, ci);
            infoDialog.show();

            if (CertInfoDialog.delete) {
                deleteRow(row);

                trustdb.remove(Utils.toHexString(cert.getFingerprint()));
               trustdb.save();
            }
        } else {
            _taskInfo.clear();
            _taskInfo.put("certnn", getRow(row).getCertName());
            _taskInfo.put("alias", alias);
            Response response = null;
            try {
                response = _taskInfo.exec(_taskInfo.SEC_ECRT);
            } catch (Exception e) {
                SuiOptionPane.showMessageDialog(
                        UtilConsoleGlobals.getActivatedFrame(),
                        e.getMessage());
                return;
            }

            if (response.hasCertInfo()) {
                CertInfoDialog infoDialog =
                        new CertInfoDialog(null,
                        response.getCertInfo(), _taskInfo);
                ModalDialogUtil.setDialogLocation(infoDialog, this);
                infoDialog.show();
                //since CertInfoDialog is a modal dialog we will wait until it comes back to check wheather the cer
                //has been deleted if it is deleted then we need to refresh the table
                if (CertInfoDialog.delete) {
                    deleteRow(row);
                }
            }

            //MessageDialog.messageDialog((Message)(response.getMessages().elementAt(0)));
        }
 */
    }


    public void mouseClicked(MouseEvent e) {
        int row = _table.rowAtPoint(e.getPoint());

        if (e.getClickCount() < 2)
            return;

        if (row == -1) {
            _table.clearSelection();
        } else {
            showCert();
        }
    }

    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}

    public boolean isTableSetup() {
        return setupComplete;
    }


    public CertListTable() {
        super(true);
        local = true;

        setLayout(new BorderLayout());

        setupComplete = true;

      //  trustdb = new DBManager();
     //   Enumeration e = trustdb.elements();
       Enumeration e = null;
        certList = new Vector();
        Vector v = new Vector();
      //  while (e.hasMoreElements()) {
    //        X509 cert = (X509)(e.nextElement());
   //         certList.addElement(cert);
//            v.addElement(
 //                   new CertBasicInfo(cert.getHolder().getName(), "Trust Server Certificate",
                 //   cert.getNotAfterDate().toString()));
       // }

        _dataModel = new CertListTableModel(
                CertBasicInfo.getCertTitleLabels(), v);
        setupTable(_dataModel);
    }


    public CertListTable(String certName, ConsoleInfo consoleInfo/*, IBackgroundLoaderCallback callback*/) {
        super(true);
        _consoleInfo = consoleInfo;
        _certName = certName;
        //_callback    = callback;
        setLayout(new BorderLayout());

        setupComplete = true;

        run();

        /*setBackground( Color.white );*/
    }



    private void setupTable(CertListTableModel _tableModel) {
        // Create the table
        _table = new SuiTable(_tableModel);
        _table.addMouseListener(this);
        _table.setColumnSelectionAllowed(false);
        /*_table.setMultipleSelectionAllowed(false);*/

        // Put the table and header into a scrollPane
        JScrollPane scrollpane = new JScrollPane();
        JTableHeader tableHeader = _table.getTableHeader();

        // create and add the column heading to the scrollpane's
        // column header viewport
        JViewport headerViewport = new JViewport();
        headerViewport.setLayout(
                new BoxLayout(headerViewport, BoxLayout.X_AXIS));
        headerViewport.add(tableHeader);
        scrollpane.setColumnHeader(headerViewport);

        // add the table to the viewport
        JViewport mainViewPort = scrollpane.getViewport();
        mainViewPort.add(_table);

        // speed up resizing repaints by turning off live cell updates
        tableHeader.setUpdateTableInRealTime(false);

        add("Center", scrollpane);

        setPreferredSize(new Dimension(0, 0));
        //_callback.classLoaded(this, "CertListTable");
    }

    //public void setCertList(String certName) {
    public void run() {

        _taskInfo = new KeyCertTaskInfo(_consoleInfo);
        _dataModel = new CertListTableModel(
                CertBasicInfo.getCertTitleLabels(), new Vector());
        //setCertList(certName);

        //_dataModel.deleteAllRows();
        //call cgi here to get the cert information
        _taskInfo.put("alias", _certName);
        alias = _certName;
        Response response = null;
        try {
            response = _taskInfo.exec(_taskInfo.SEC_MGCRT);
        } catch (Exception e) {
            SuiOptionPane.showMessageDialog(
                    UtilConsoleGlobals.getActivatedFrame(), e.getMessage());
            setupComplete = false;
            return;
        }

        if (response.hasCertList()) {
            _dataModel.setRowData(response.getCertList());
            //repaint();
        }

        setupTable(_dataModel);
    }

    /**
      *
      *  @return LDAPEntry at specified index, null if index > number of rows
      *
      */
    public CertBasicInfo getRow(int index) {
        return _dataModel.getRow(index);
    }

    /**
      *
      *  @return the number of rows in the table.
      *
      */
    public int getRowCount() {
        return _dataModel.getRowCount();
    }

    /**
      *
      *  Removes the first occurrence of the LDAPEntry from this table. If the object is found.
      *
      *  @param ldapEntry   LDAPEntry to delete from this table.
      *
      */
    public void deleteRow(int rowIndex) {
        _dataModel.deleteRow(rowIndex);
        repaint();
    }
}