📄 securityconfigdialog.java
字号:
DigitalIDInfo info = (DigitalIDInfo) this.idTable.get( email ); X509Certificate[] certChain = info.getCertificateChain(); this.viewCertificates( certChain ); } 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.WARNING_MESSAGE ); } catch ( PKCSException ex ) { ex.printStackTrace(); } } } else if ( command.equals( "VIEWCERT" ) ) { String email = (String) this.certCombo.getSelectedItem(); if ( email != null ) { CertificateInfo info = (CertificateInfo) this.certTable.get( email ); X509Certificate[] certChain = null; if ( info.isCertificateChain() ) { certChain = info.getCertificateChain(); } else { certChain = new X509Certificate[1]; certChain[0] = info.getCertificate(); } this.viewCertificates( certChain ); } } if ( disposeIt ) { this.dispose(); } } private void importDigitalId( String dName, String fName ) { X509Certificate[] certs = null; FileInputStream fin = null; File f = new File( dName, fName ); try { fin = new FileInputStream( f ); byte[] p12Bytes = StreamUtilities.getStreamBytes( fin ); if ( fName.endsWith( ".pfx" ) || fName.endsWith( ".PFX" ) ) { MicrosoftP12 mp12 = new MicrosoftP12( new ByteArrayInputStream( p12Bytes ) ); DigitalIDInfo info = new DigitalIDInfo( "N/A", null, mp12 ); certs = info.getCertificateChain(); Name nm = (Name) certs[certs.length-1].getSubjectDN(); String email = nm.getRDN( ObjectID.emailAddress ); info.setEMailString( email ); this.idTable.put( email, info ); } else if ( fName.endsWith( ".p12" ) || fName.endsWith( ".P12" ) ) { NetscapeP12 np12 = new NetscapeP12( new ByteArrayInputStream( p12Bytes ) ); DigitalIDInfo info = new DigitalIDInfo( "N/A", null, np12 ); certs = info.getCertificateChain(); Name nm = (Name) certs[certs.length-1].getSubjectDN(); String email = nm.getRDN( ObjectID.emailAddress ); info.setEMailString( email ); this.idTable.put( email, info ); } else { // UNDONE } } catch ( PasswordCancelException ex ) { String message = "Could not import the digital certificate from\n" + "the file named '" + fName + "'.\n" + "A proper password was not provided."; JOptionPane.showMessageDialog( null, message, "Import Failed", JOptionPane.WARNING_MESSAGE ); } catch ( FileNotFoundException ex ) { ex.printStackTrace(); } catch ( IOException ex ) { ex.printStackTrace(); } catch ( PKCSParsingException ex ) { ex.printStackTrace(); } catch ( PKCSException ex ) { ex.printStackTrace(); } finally { if ( fin != null ) { try { fin.close(); } catch ( IOException ex ) { } } } this.loadComboBoxes(); } private void importCertificate( String dName, String fName ) { X509Certificate[] certs = null; FileInputStream fin = null; File f = new File( dName, fName ); try { fin = new FileInputStream( f ); if ( fName.endsWith( ".der" ) || fName.endsWith( ".cer" ) ) { X509Certificate cert = new X509Certificate( fin ); Name nm = (Name) cert.getSubjectDN(); String emailAddr = nm.getRDN( ObjectID.emailAddress ); CertificateInfo info = new CertificateInfo( emailAddr, cert ); this.certTable.put( emailAddr, info ); } else { // UNDONE } } catch ( FileNotFoundException ex ) { ex.printStackTrace(); } catch ( IOException ex ) { ex.printStackTrace(); } catch ( CertificateException ex ) { ex.printStackTrace(); } finally { if ( fin != null ) { try { fin.close(); } catch ( IOException ex ) { } } } this.loadComboBoxes(); } private void viewCertificates( X509Certificate[] certs ) { CertificateDialog dlg = new CertificateDialog( null, "Certificates", certs, false ); dlg.setLocation( AWTUtilities.computeDialogLocation( dlg ) ); dlg.show(); } private void establishContents() { JLabel lbl; JScrollPane scroller; Container cont = this.getContentPane(); cont.setLayout( new GridBagLayout() ); int row = 0; JPanel myPan = new JPanel(); myPan.setLayout( new GridBagLayout() ); myPan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) ); AWTUtilities.constrain( cont, myPan, GridBagConstraints.BOTH, GridBagConstraints.NORTH, 0, row++, 2, 1, 1.0, 1.0 ); int subRow = 0; lbl = new JLabel( "My Identities:" ); lbl.setHorizontalAlignment( JLabel.RIGHT ); AWTUtilities.constrain( myPan, lbl, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 ); this.idCombo = new JComboBox(); this.idCombo.addItemListener( this ); AWTUtilities.constrain( myPan, this.idCombo, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 ); this.idInfoText = new JTextArea(); scroller = new JScrollPane( this.idInfoText ); AWTUtilities.constrain( myPan, scroller, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, subRow++, 2, 1, 1.0, 1.0 ); JLabel spacer = new JLabel( "" ); AWTUtilities.constrain( myPan, spacer, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, subRow, 1, 1, 1.0, 0.0 ); JPanel idCtlPan = new JPanel(); AWTUtilities.constrain( myPan, idCtlPan, GridBagConstraints.NONE, GridBagConstraints.EAST, 1, subRow++, 1, 1, 0.0, 0.0, new Insets( 2, 4, 2, 5 ) ); this.idViewBtn = new JButton( "View..." ); this.idViewBtn.addActionListener( this ); this.idViewBtn.setActionCommand( "VIEWID" ); idCtlPan.add( this.idViewBtn ); JButton myImport = new JButton( "Import..." ); myImport.addActionListener( this ); myImport.setActionCommand( "IMPORTID" ); idCtlPan.add( myImport ); AWTUtilities.constrain( cont, new JSeparator( JSeparator.HORIZONTAL ), GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 0.0 ); JPanel otherPan = new JPanel(); otherPan.setLayout( new GridBagLayout() ); otherPan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) ); AWTUtilities.constrain( cont, otherPan, GridBagConstraints.BOTH, GridBagConstraints.NORTH, 0, row++, 2, 1, 1.0, 1.0 ); subRow = 0; lbl = new JLabel( "Other Identities:" ); lbl.setHorizontalAlignment( JLabel.RIGHT ); AWTUtilities.constrain( otherPan, lbl, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 ); this.certCombo = new JComboBox(); this.certCombo.addItemListener( this ); AWTUtilities.constrain( otherPan, this.certCombo, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 ); this.certInfoText = new JTextArea(); scroller = new JScrollPane( this.certInfoText ); AWTUtilities.constrain( otherPan, scroller, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, subRow++, 2, 1, 1.0, 1.0 ); JLabel ospacer = new JLabel( "" ); AWTUtilities.constrain( otherPan, ospacer, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, subRow, 1, 1, 1.0, 0.0 ); JPanel oCtlPan = new JPanel(); AWTUtilities.constrain( otherPan, oCtlPan, GridBagConstraints.NONE, GridBagConstraints.EAST, 1, subRow++, 1, 1, 0.0, 0.0, new Insets( 2, 4, 2, 5 ) ); this.certViewBtn = new JButton( "View..." ); this.certViewBtn.addActionListener( this ); this.certViewBtn.setActionCommand( "VIEWCERT" ); oCtlPan.add( this.certViewBtn ); JButton certImport = new JButton( "Import..." ); certImport.addActionListener( this ); certImport.setActionCommand( "IMPORTCERT" ); oCtlPan.add( certImport ); AWTUtilities.constrain( cont, new JSeparator( JSeparator.HORIZONTAL ), GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 0.0 ); JPanel ctlPan = new JPanel(); ctlPan.setLayout( new BorderLayout() ); AWTUtilities.constrain( cont, ctlPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 0.0 ); JPanel btnPan = new JPanel(); btnPan.setLayout( new GridLayout( 1, 2, 10, 10 ) ); btnPan.setBorder( new EmptyBorder( 8, 5, 5, 5 ) ); ctlPan.add( BorderLayout.EAST, btnPan ); JButton btn; btn = new JButton( "Save" ); btn.addActionListener( this ); btn.setActionCommand( "SAVE" ); btnPan.add( btn ); btn = new JButton( "Cancel" ); btn.addActionListener( this ); btn.setActionCommand( "CANCEL" ); btnPan.add( btn ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -