KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > transport > http > ssl > HTTPSClientInvoker


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.transport.http.ssl;
8
9 import java.io.IOException JavaDoc;
10 import java.net.HttpURLConnection JavaDoc;
11 import java.util.Map JavaDoc;
12 import javax.net.ssl.HostnameVerifier;
13 import javax.net.ssl.HttpsURLConnection;
14 import javax.net.ssl.SSLSession;
15 import org.jboss.remoting.InvokerLocator;
16 import org.jboss.remoting.transport.http.HTTPClientInvoker;
17
18 /**
19  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
20  */

21 public class HTTPSClientInvoker extends HTTPClientInvoker
22 {
23    /**
24     * A property to override the default https url host verification
25     */

26    public static final String JavaDoc IGNORE_HTTPS_HOST = "org.jboss.security.ignoreHttpsHost";
27
28    public HTTPSClientInvoker(InvokerLocator locator)
29    {
30       super(locator);
31    }
32
33    /**
34     * Checks to see if org.jboss.security.ignoreHttpHost property is set to true, and if it
35     * is, will ste the host name verifier so that will accept any host.
36     *
37     * @return
38     * @throws IOException
39     */

40    protected HttpURLConnection JavaDoc createURLConnection(String JavaDoc url, Map JavaDoc metadat) throws IOException JavaDoc
41    {
42       HttpURLConnection JavaDoc conn = super.createURLConnection(url, metadat);
43
44       if(conn instanceof HttpsURLConnection && Boolean.getBoolean(IGNORE_HTTPS_HOST) == true)
45       {
46          HttpsURLConnection sconn = (HttpsURLConnection) conn;
47          sconn.setHostnameVerifier(new AnyhostVerifier());
48       }
49       return conn;
50    }
51
52    private class AnyhostVerifier implements HostnameVerifier
53    {
54
55       public boolean verify(String JavaDoc s, SSLSession sslSession)
56       {
57          return true;
58       }
59    }
60 }
Popular Tags