1 2 package com.ca.commons.security.cert; 3 4 import com.ca.commons.cbutil.CBToolBarButton; 5 6 import java.awt.*; 7 import java.awt.event.*; 8 import javax.swing.*; 9 import javax.swing.border.*; 10 import java.util.StringTokenizer ; 11 import javax.swing.tree.*; 12 import java.util.Date ; 13 14 import java.security.cert.*; 15 16 23 public class CertPathViewPanel extends JPanel 24 { 25 private X509Certificate cert = null; 26 27 private JPanel certPathPanel = new JPanel(); 28 private JTree certpath = new JTree(); 29 private CBToolBarButton viewCertButton = new CBToolBarButton("&View Certificate...", null); 30 private JLabel certStatusLabel = new JLabel("Certificate status:"); 31 private JTextArea certStatusText = new JTextArea(2, 20); 32 33 36 public CertPathViewPanel(X509Certificate cert) 37 { 38 this.cert = cert; 39 40 DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); 42 renderer.setLeafIcon(CertViewer.certIcon); 43 renderer.setOpenIcon(CertViewer.certIcon); 44 renderer.setClosedIcon(CertViewer.certIcon); 45 certpath.setCellRenderer(renderer); 46 47 Border etchedBorder = BorderFactory.createEtchedBorder(); 49 50 Border certPathBorder = BorderFactory.createTitledBorder( 51 etchedBorder, "Certification Path"); 52 certPathPanel.setBorder(certPathBorder); 53 54 viewCertButton.setWidthHeight(110, 23); 55 viewCertButton.setEnabled(false); 56 57 if (cert != null) 58 { 59 String ssubject = CertViewer.getMostSignificantName(cert.getSubjectX500Principal().getName()); 60 String iissuer = CertViewer.getMostSignificantName(cert.getIssuerX500Principal().getName()); 61 62 DefaultMutableTreeNode issuer = 63 new DefaultMutableTreeNode(iissuer); 64 DefaultMutableTreeNode subject = 65 new DefaultMutableTreeNode(ssubject); 66 67 if (!iissuer.equals(ssubject)) 68 issuer.add(subject); 69 70 certpath.setModel(new DefaultTreeModel(issuer)); 71 72 try 73 { 74 cert.checkValidity(); 75 certStatusText.setText("This certificate is OK."); 76 } 77 catch (CertificateExpiredException ex) 78 { 79 certStatusText.setText("This certificate is expired."); 80 } 81 catch (CertificateNotYetValidException ex) 82 { 83 certStatusText.setText("This certificate is not yet valid."); 84 } 85 } 86 87 certPathPanel.setLayout(new GridBagLayout()); 89 certPathPanel.add(new JScrollPane(certpath), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 90 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 91 new Insets(3, 6, 6, 6), 0, 0)); 92 93 98 99 setLayout(new GridBagLayout()); 100 add(certPathPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 101 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 102 new Insets(10, 10, 10, 10), 0, 0)); 103 add(certStatusLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 104 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 105 new Insets(5, 13, 2, 11), 0, 0)); 106 add(new JScrollPane(certStatusText), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 107 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 108 new Insets(0, 12, 10, 11), 0, 0)); 109 110 viewCertButton.addActionListener(new ActionListener() 112 { 113 public void actionPerformed(ActionEvent e) 114 { 115 viewCertButton_actionPerformed(e); 116 } 117 }); 118 } 119 120 123 private void viewCertButton_actionPerformed(ActionEvent e) 124 { 125 System.out.println("View a certificate in certification path"); 126 } 127 } 128 | Popular Tags |