⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securityconfigdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*** $Id: SecurityConfigDialog.java,v 1.4 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may 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 should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail.smime;import java.awt.*;import java.awt.event.*;import java.io.File;import java.io.FileInputStream;import java.io.ByteArrayInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Vector;import java.util.Hashtable;import java.util.Enumeration;import java.security.cert.CertificateException;import javax.mail.*;import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import org.icemail.mail.Configuration; import org.icemail.smime.MissingCertificateException;import org.icemail.smime.PasswordCancelException;import org.icemail.util.AWTUtilities; import org.icemail.util.StreamUtilities; import org.icemail.util.UserProperties; import iaik.asn1.ObjectID;import iaik.asn1.structures.AVA;import iaik.asn1.structures.RDN;import iaik.asn1.structures.Name;import iaik.pkcs.PKCSException;import iaik.pkcs.PKCSParsingException;import iaik.pkcs.pkcs12.NetscapeP12;import iaik.pkcs.pkcs12.MicrosoftP12;import iaik.x509.X509Certificate;public class SecurityConfigDialog  extends JDialog  implements ActionListener, ItemListener{  private Frame     frame;  private JComboBox idCombo;  private JComboBox certCombo;  private JTextArea idInfoText;  private JTextArea certInfoText;  private JButton   idViewBtn;  private JButton   certViewBtn;  private Hashtable idTable;  private Hashtable certTable;  public  SecurityConfigDialog( Frame frame ) {    super( frame, "Configure Security Information", true );    this.frame = frame;    SecurityConfig cfgSec = SecurityConfig.getInstance();    this.idTable = (Hashtable) cfgSec.getIDSTable().clone();    this.certTable = (Hashtable) cfgSec.getCertificateTable().clone();    this.establishContents();    this.loadComboBoxes();    this.pack();    Dimension sz = this.getPreferredSize();    int w = UserProperties.getProperty( "securityConfigDialog.width", sz.width );    int h = UserProperties.getProperty( "securityConfigDialog.height", sz.height );    this.setSize( w, h );    this.setLocation( AWTUtilities.computeDialogLocation( this ) );  }  private void  loadComboBoxes() {    Enumeration enum;    if ( this.idCombo.getItemCount() > 0 )      this.idCombo.removeAllItems();    enum = this.idTable.keys();    for ( ; enum.hasMoreElements() ; ) {      this.idCombo.addItem( enum.nextElement() );    }    if ( this.certCombo.getItemCount() > 0 )      this.certCombo.removeAllItems();    enum = this.certTable.keys();    for ( ; enum.hasMoreElements() ; ) {      this.certCombo.addItem( enum.nextElement() );    }  }  public void  itemStateChanged( ItemEvent evt ) {    if ( evt.getStateChange() == ItemEvent.SELECTED ) {      X509Certificate[] certChain = null;      String email = (String) evt.getItem();      try {        if ( evt.getItemSelectable() == this.idCombo ) {          DigitalIDInfo info = (DigitalIDInfo) this.idTable.get( email );          certChain = info.getCertificateChain();          if ( certChain != null ) {            StringBuffer buf = new StringBuffer();            for ( int ci = 0 ; ci < certChain.length ; ++ci ) {              Name nm = (Name) certChain[ci].getSubjectDN();              buf.append( "Certificate #" + ci + ":\n" );              Enumeration rnum = nm.elements();              for ( int ri = 0 ; rnum.hasMoreElements() ; ++ri ) {                RDN rdn = (RDN) rnum.nextElement();                Enumeration anum = rdn.elements();                for ( int ai = 0 ; anum.hasMoreElements() ; ++ai ) {                  AVA ava = (AVA) anum.nextElement();                  buf.append( "  " + ava.getType().getName() );                  buf.append( " = " + ava.getValue() + "\n" );                }              }            }            this.idInfoText.setText( buf.toString() );            this.idViewBtn.setEnabled( true );          }        } else {          CertificateInfo info = (CertificateInfo) this.certTable.get( email );          if ( info.isCertificateChain() ) {            certChain = info.getCertificateChain();          } else {            X509Certificate cert = info.getCertificate();            if ( cert != null ) {              certChain = new X509Certificate[1];              certChain[0] = cert;            }          }          if ( certChain != null ) {            StringBuffer buf = new StringBuffer();            for ( int ci = 0 ; ci < certChain.length ; ++ci ) {              Name nm = (Name) certChain[ci].getSubjectDN();              buf.append( "Certificate #" + ci + ":\n" );              Enumeration rnum = nm.elements();              for ( int ri = 0 ; rnum.hasMoreElements() ; ++ri ) {                RDN rdn = (RDN) rnum.nextElement();                Enumeration anum = rdn.elements();                for ( int ai = 0 ; anum.hasMoreElements() ; ++ai ) {                  AVA ava = (AVA) anum.nextElement();                  buf.append( "  " + ava.getType().getName() );                  buf.append( " = " + ava.getValue() + "\n" );                }              }            }            this.certInfoText.setText( buf.toString() );            this.certViewBtn.setEnabled( true );          }        }      } catch ( PasswordCancelException ex ) {        String message =          "Could not obtain the digital certificate for\n"          + "the email address '"          + email          + "'.\n"          + "A proper password was not provided.";        JOptionPane.showMessageDialog( null, message, "No Certificate",                                       JOptionPane.INFORMATION_MESSAGE );      } catch ( PKCSException ex ) {        ex.printStackTrace();      }    } else {      if ( evt.getItemSelectable() == this.idCombo ) {        this.idViewBtn.setEnabled( false );      } else {        this.certViewBtn.setEnabled( false );      }    }  }  public void  actionPerformed( ActionEvent event ) {    boolean disposeIt = false;    String command = event.getActionCommand();    if ( command.equals( "SAVE" ) ) {      Configuration config = Configuration.getInstance();      SecurityConfig secCfg = SecurityConfig.getInstance();      String errMsg = null;      try {        secCfg.saveP12Tables( this.idTable, this.certTable );        config.saveProperties();        disposeIt = true;      } catch ( IOException ex ) {        ex.printStackTrace();        errMsg =          "An IO exception occurred saving the secutiry configuration.\n"          + ex.getMessage();      } catch ( PKCSException ex ) {        ex.printStackTrace();        errMsg =          "A PKCS exception occurred saving the secutiry configuration.\n"          + ex.getMessage();      } catch ( PasswordCancelException ex ) {        errMsg =          "Failed to save the security configuration.\n"          + "A password was not provided to encrypt the\n"          + "digital ID for '"          + ex.getMessage()          + "'.";      }      if ( errMsg != null ) {        JOptionPane.showMessageDialog( null, errMsg, "Error", JOptionPane.WARNING_MESSAGE );      }    } else if ( command.equals( "CANCEL" ) ) {      disposeIt = true;    } else if ( command.equals( "IMPORTID" ) ) {      FileDialog fDlg = new FileDialog( this.frame, "Import", FileDialog.LOAD );      fDlg.setDirectory( "E:\\crypto\\Certificates" );      fDlg.show();            String fName = fDlg.getFile();      String dName = fDlg.getDirectory();      if ( fName != null && dName != null ) {        this.importDigitalId( dName, fName );      }    } else if ( command.equals( "IMPORTCERT" ) ) {      FileDialog fDlg = new FileDialog( this.frame, "Import", FileDialog.LOAD );      fDlg.setDirectory( "E:\\crypto\\Certificates" );      fDlg.show();            String fName = fDlg.getFile();      String dName = fDlg.getDirectory();      if ( fName != null && dName != null ) {        this.importCertificate( dName, fName );      }    } else if ( command.equals( "VIEWID" ) ) {      String email = (String) this.idCombo.getSelectedItem();      if ( email != null ) {        try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -