View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.ssl;
    14
    15  import java.awt.BorderLayout;
    16  import java.beans.PropertyChangeEvent;
    17  import java.beans.PropertyChangeListener;
    18  import java.security.cert.Certificate;
    19
    20  import javax.swing.JComponent;
    21  import javax.swing.JEditorPane;
    22  import javax.swing.JPanel;
    23  import javax.swing.JScrollPane;
    24  import javax.swing.text.html.HTMLEditorKit;
    25
    26  import com.eviware.soapui.impl.wsdl.WsdlRequest;
    27  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlLocation;
    28  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.AbstractXmlInspector;
    29  import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
    30  import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
    31
    32  public class ResponseSSLInspector extends AbstractXmlInspector implements PropertyChangeListener
    33  {
    34  	private JEditorPane sslInfoPane;
    35  	private JPanel panel;
    36  	private WsdlRequest request;
    37
    38  	protected ResponseSSLInspector( WsdlRequest request )
    39  	{
    40  		super( "SSL Info", "SSL Certificate Informaation for this response",	true, SSLInspectorFactory.INSPECTOR_ID );
    41  		this.request = request;
    42  		request.addPropertyChangeListener( WsdlRequest.RESPONSE_PROPERTY, this );
    43  	}
    44
    45  	public JComponent getComponent()
    46  	{
    47  		if( panel != null )
    48  			return panel;
    49
    50  		panel = new JPanel( new BorderLayout());
    51  		sslInfoPane = new JEditorPane();
    52  		sslInfoPane.setEditorKit( new HTMLEditorKit() );
    53  		panel.add( new JScrollPane( sslInfoPane ));
    54
    55  		return panel;
    56  	}
    57
    58  	public void locationChanged( XmlLocation location )
    59  	{
    60  	}
    61
    62  	private void updateSSLInfo( SSLInfo sslInfo )
    63  	{
    64  		String sslInfoTabTitle = "SSL Info";
    65
    66  		if( sslInfo != null )
    67  		{
    68  			StringBuffer buf = new StringBuffer( "<html><body><table cellpadding=1 cellspacing=1 border=0>" );
    69
    70  			buf.append( "<tr><td><b>CipherSuite:</b></td><td align=left valign=top>" ).
    71  				append( sslInfo.getCipherSuite().toString() ).append( "</td></tr>");
    72
    73  			if( sslInfo.getLocalPrincipal() != null )
    74  				buf.append( "<tr><td><b>LocalPrincipal:</b></td><td align=left valign=top>" ).
    75  					append( sslInfo.getLocalPrincipal().getName() ).append( "</td></tr>");
    76
    77  			Certificate[] localCertificates = sslInfo.getLocalCertificates();
    78
    79  			if( localCertificates != null)
    80  			{
    81  				buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
    82
    83  				int cnt = 1;
    84  				for( Certificate cert : localCertificates )
    85  				{
    86  					buf.append( "<tr><td><b>Local Certificate " ).append( cnt++ ).
    87  						append( ":</b><pre><font size=-1>" ).
    88  						append( cert.toString() ).append( "</font></pre></td></tr>");
    89
    90  				}
    91
    92  				buf.append( "</table><table cellpadding=1 cellspacing=1 border=0>" );
    93  			}
    94
    95  			if( sslInfo.getPeerPrincipal() != null )
    96  				buf.append( "<tr><td><b>PeerPrincipal:</b></td><td align=left valign=top>" ).
    97  					append( sslInfo.getPeerPrincipal().toString() ).append( "</td></tr>");
    98
    99  			Certificate[] peerCertificates = sslInfo.getPeerCertificates();
    100 			if( peerCertificates != null)
    101 			{
    102 				buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
    103
    104 				int cnt = 1;
    105 				for( Certificate cert : peerCertificates )
    106 				{
    107 					buf.append( "<tr><td colspan=2><b>Peer Certificate " ).append( cnt++ ).
    108 						append( ":</b><pre><font size=-1>" ).
    109 						append( cert.toString() ).append( "</font></pre></td></tr>");
    110 				}
    111
    112 				buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
    113 			}
    114
    115 			buf.append(  "</table></body></html>" );
    116 			sslInfoPane.setText( buf.toString() );
    117
    118 			sslInfoTabTitle += " (" + sslInfo.getPeerCertificates().length + " certs)";
    119 		}
    120
    121 		setTitle( sslInfoTabTitle );
    122 	}
    123
    124 	public void propertyChange( PropertyChangeEvent evt )
    125 	{
    126 		WsdlResponse response = request.getResponse();
    127 		updateSSLInfo( response == null ? null : response.getSSLInfo() );
    128 		setEnabled( response != null && response.getSSLInfo() != null );
    129 	}
    130 }