< prev index next >

src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpsConfigurator.java

Print this page




  25 
  26 package com.sun.net.httpserver;
  27 
  28 import java.net.*;
  29 import java.io.*;
  30 import java.nio.*;
  31 import java.security.*;
  32 import java.nio.channels.*;
  33 import java.util.*;
  34 import java.util.concurrent.*;
  35 import javax.net.ssl.*;
  36 
  37 
  38 /**
  39  * This class is used to configure the https parameters for each incoming
  40  * https connection on a HttpsServer. Applications need to override
  41  * the {@link #configure(HttpsParameters)} method in order to change
  42  * the default configuration.
  43  * <p>
  44  * The following <a name="example">example</a> shows how this may be done:
  45  * <p>
  46  * <pre><blockquote>
  47  * SSLContext sslContext = SSLContext.getInstance (....);
  48  * HttpsServer server = HttpsServer.create();
  49  *
  50  * server.setHttpsConfigurator (new HttpsConfigurator(sslContext) {
  51  *     public void configure (HttpsParameters params) {
  52  *
  53  *         // get the remote address if needed
  54  *         InetSocketAddress remote = params.getClientAddress();
  55  *
  56  *         SSLContext c = getSSLContext();
  57  *
  58  *         // get the default parameters
  59  *         SSLParameters sslparams = c.getDefaultSSLParameters();
  60  *         if (remote.equals (...) ) {
  61  *             // modify the default set for client x
  62  *         }
  63  *
  64  *         params.setSSLParameters(sslparams);
  65  *     }
  66  * });
  67  * </blockquote></pre>
  68  * @since 1.6
  69  */
  70 @jdk.Exported
  71 public class HttpsConfigurator {
  72 
  73     private SSLContext context;
  74 
  75     /**
  76      * Creates an Https configuration, with the given SSLContext.
  77      * @param context the SSLContext to use for this configurator
  78      * @throws NullPointerException if no SSLContext supplied
  79      */
  80     public HttpsConfigurator (SSLContext context) {
  81         if (context == null) {
  82             throw new NullPointerException ("null SSLContext");
  83         }
  84         this.context = context;
  85     }
  86 
  87     /**
  88      * Returns the SSLContext for this HttpsConfigurator.
  89      * @return the SSLContext
  90      */
  91     public SSLContext getSSLContext() {
  92         return context;
  93     }
  94 
  95 //BEGIN_TIGER_EXCLUDE
  96    /**
  97     * Called by the HttpsServer to configure the parameters
  98     * for a https connection currently being established.
  99     * The implementation of configure() must call
 100     * {@link HttpsParameters#setSSLParameters(SSLParameters)}
 101     * in order to set the SSL parameters for the connection.
 102     * <p>
 103     * The default implementation of this method uses the
 104     * SSLParameters returned from <p>
 105     * <code>getSSLContext().getDefaultSSLParameters()</code>
 106     * <p>
 107     * configure() may be overridden in order to modify this behavior.
 108     * See, the example <a href="#example">above</a>.
 109     * @param params the HttpsParameters to be configured.
 110     *
 111     * @since 1.6
 112     */
 113     public void configure (HttpsParameters params) {
 114         params.setSSLParameters (getSSLContext().getDefaultSSLParameters());
 115     }
 116 //END_TIGER_EXCLUDE
 117 }


  25 
  26 package com.sun.net.httpserver;
  27 
  28 import java.net.*;
  29 import java.io.*;
  30 import java.nio.*;
  31 import java.security.*;
  32 import java.nio.channels.*;
  33 import java.util.*;
  34 import java.util.concurrent.*;
  35 import javax.net.ssl.*;
  36 
  37 
  38 /**
  39  * This class is used to configure the https parameters for each incoming
  40  * https connection on a HttpsServer. Applications need to override
  41  * the {@link #configure(HttpsParameters)} method in order to change
  42  * the default configuration.
  43  * <p>
  44  * The following <a name="example">example</a> shows how this may be done:
  45  *
  46  * <blockquote><pre>
  47  * SSLContext sslContext = SSLContext.getInstance (....);
  48  * HttpsServer server = HttpsServer.create();
  49  *
  50  * server.setHttpsConfigurator (new HttpsConfigurator(sslContext) {
  51  *     public void configure (HttpsParameters params) {
  52  *
  53  *         // get the remote address if needed
  54  *         InetSocketAddress remote = params.getClientAddress();
  55  *
  56  *         SSLContext c = getSSLContext();
  57  *
  58  *         // get the default parameters
  59  *         SSLParameters sslparams = c.getDefaultSSLParameters();
  60  *         if (remote.equals (...) ) {
  61  *             // modify the default set for client x
  62  *         }
  63  *
  64  *         params.setSSLParameters(sslparams);
  65  *     }
  66  * });
  67  * </pre></blockquote>
  68  * @since 1.6
  69  */
  70 @jdk.Exported
  71 public class HttpsConfigurator {
  72 
  73     private SSLContext context;
  74 
  75     /**
  76      * Creates an Https configuration, with the given SSLContext.
  77      * @param context the SSLContext to use for this configurator
  78      * @throws NullPointerException if no SSLContext supplied
  79      */
  80     public HttpsConfigurator (SSLContext context) {
  81         if (context == null) {
  82             throw new NullPointerException ("null SSLContext");
  83         }
  84         this.context = context;
  85     }
  86 
  87     /**
  88      * Returns the SSLContext for this HttpsConfigurator.
  89      * @return the SSLContext
  90      */
  91     public SSLContext getSSLContext() {
  92         return context;
  93     }
  94 
  95 //BEGIN_TIGER_EXCLUDE
  96    /**
  97     * Called by the HttpsServer to configure the parameters
  98     * for a https connection currently being established.
  99     * The implementation of configure() must call
 100     * {@link HttpsParameters#setSSLParameters(SSLParameters)}
 101     * in order to set the SSL parameters for the connection.
 102     * <p>
 103     * The default implementation of this method uses the
 104     * SSLParameters returned from <p>
 105     * {@code getSSLContext().getDefaultSSLParameters()}
 106     * <p>
 107     * configure() may be overridden in order to modify this behavior.
 108     * See, the example <a href="#example">above</a>.
 109     * @param params the HttpsParameters to be configured.
 110     *
 111     * @since 1.6
 112     */
 113     public void configure (HttpsParameters params) {
 114         params.setSSLParameters (getSSLContext().getDefaultSSLParameters());
 115     }
 116 //END_TIGER_EXCLUDE
 117 }
< prev index next >