author | alanb |
Fri, 08 Jan 2016 11:47:35 +0000 | |
changeset 34894 | 3248b89d1921 |
parent 30042 | 4728ebcf8fd0 |
child 45132 | db2f2d72cd4f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20742
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
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: |
|
30042 | 45 |
* |
46 |
* <blockquote><pre> |
|
2 | 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 |
* }); |
|
30042 | 67 |
* </pre></blockquote> |
2 | 68 |
* @since 1.6 |
69 |
*/ |
|
70 |
public class HttpsConfigurator { |
|
71 |
||
72 |
private SSLContext context; |
|
73 |
||
74 |
/** |
|
75 |
* Creates an Https configuration, with the given SSLContext. |
|
76 |
* @param context the SSLContext to use for this configurator |
|
77 |
* @throws NullPointerException if no SSLContext supplied |
|
78 |
*/ |
|
79 |
public HttpsConfigurator (SSLContext context) { |
|
80 |
if (context == null) { |
|
81 |
throw new NullPointerException ("null SSLContext"); |
|
82 |
} |
|
83 |
this.context = context; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Returns the SSLContext for this HttpsConfigurator. |
|
88 |
* @return the SSLContext |
|
89 |
*/ |
|
90 |
public SSLContext getSSLContext() { |
|
91 |
return context; |
|
92 |
} |
|
93 |
||
7271 | 94 |
//BEGIN_TIGER_EXCLUDE |
2 | 95 |
/** |
96 |
* Called by the HttpsServer to configure the parameters |
|
97 |
* for a https connection currently being established. |
|
98 |
* The implementation of configure() must call |
|
99 |
* {@link HttpsParameters#setSSLParameters(SSLParameters)} |
|
100 |
* in order to set the SSL parameters for the connection. |
|
101 |
* <p> |
|
102 |
* The default implementation of this method uses the |
|
103 |
* SSLParameters returned from <p> |
|
30042 | 104 |
* {@code getSSLContext().getDefaultSSLParameters()} |
2 | 105 |
* <p> |
106 |
* configure() may be overridden in order to modify this behavior. |
|
107 |
* See, the example <a href="#example">above</a>. |
|
108 |
* @param params the HttpsParameters to be configured. |
|
109 |
* |
|
110 |
* @since 1.6 |
|
111 |
*/ |
|
112 |
public void configure (HttpsParameters params) { |
|
113 |
params.setSSLParameters (getSSLContext().getDefaultSSLParameters()); |
|
114 |
} |
|
7271 | 115 |
//END_TIGER_EXCLUDE |
2 | 116 |
} |