Path: blob/master/src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpsParameters.java
41159 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.net.httpserver;2627import java.net.InetSocketAddress;28import javax.net.ssl.SSLContext;29import javax.net.ssl.SSLParameters;3031/**32* Represents the set of parameters for each https connection negotiated with33* clients. One of these is created and passed to34* {@link HttpsConfigurator#configure(HttpsParameters)} for every incoming https35* connection, in order to determine the parameters to use.36*37* <p> The underlying SSL parameters may be established either via the set/get38* methods of this class, or else via a {@link javax.net.ssl.SSLParameters}39* object. {@code SSLParameters} is the preferred method, because in the future,40* additional configuration capabilities may be added to that class, and it is41* easier to determine the set of supported parameters and their default values42* with SSLParameters. Also, if an {@code SSLParameters} object is provided via43* {@link #setSSLParameters(SSLParameters)} then those parameter settings are44* used, and any settings made in this object are ignored.45*46* @since 1.647*/48public abstract class HttpsParameters {4950private String[] cipherSuites;51private String[] protocols;52private boolean wantClientAuth;53private boolean needClientAuth;5455/**56* Constructor for subclasses to call.57*/58protected HttpsParameters() {}5960/**61* Returns the {@link HttpsConfigurator} for this {@code HttpsParameters}.62*63* @return {@code HttpsConfigurator} for this instance of {@code HttpsParameters}64*/65public abstract HttpsConfigurator getHttpsConfigurator();6667/**68* Returns the address of the remote client initiating the connection.69*70* @return address of the remote client initiating the connection71*/72public abstract InetSocketAddress getClientAddress();7374/**75* Sets the {@link SSLParameters} to use for this {@code HttpsParameters}.76* The parameters must be supported by the {@link SSLContext} contained77* by the {@link HttpsConfigurator} associated with this {@code HttpsParameters}.78* If no parameters are set, then the default behavior is to use79* the default parameters from the associated {@link SSLContext}.80*81* @param params the {@code SSLParameters} to set. If {@code null} then the82* existing parameters (if any) remain unchanged83* @throws IllegalArgumentException if any of the parameters are invalid or84* unsupported85*/86public abstract void setSSLParameters(SSLParameters params);8788/**89* Returns a copy of the array of ciphersuites or {@code null} if none90* have been set.91*92* @return a copy of the array of ciphersuites or {@code null} if none have93* been set94*/95public String[] getCipherSuites() {96return cipherSuites != null ? cipherSuites.clone() : null;97}9899/**100* Sets the array of ciphersuites.101*102* @param cipherSuites the array of ciphersuites (or {@code null})103*/104public void setCipherSuites(String[] cipherSuites) {105this.cipherSuites = cipherSuites != null ? cipherSuites.clone() : null;106}107108/**109* Returns a copy of the array of protocols or {@code null} if none have been110* set.111*112* @return a copy of the array of protocols or {@code null} if none have been113* set114*/115public String[] getProtocols() {116return protocols != null ? protocols.clone() : null;117}118119/**120* Sets the array of protocols.121*122* @param protocols the array of protocols (or {@code null})123*/124public void setProtocols(String[] protocols) {125this.protocols = protocols != null ? protocols.clone() : null;126}127128/**129* Returns whether client authentication should be requested.130*131* @return whether client authentication should be requested132*/133public boolean getWantClientAuth() {134return wantClientAuth;135}136137/**138* Sets whether client authentication should be requested. Calling this139* method clears the {@code needClientAuth} flag.140*141* @param wantClientAuth whether client authentication should be requested142*/143public void setWantClientAuth(boolean wantClientAuth) {144this.wantClientAuth = wantClientAuth;145}146147/**148* Returns whether client authentication should be required.149*150* @return whether client authentication should be required151*/152public boolean getNeedClientAuth() {153return needClientAuth;154}155156/**157* Sets whether client authentication should be required. Calling this method158* clears the {@code wantClientAuth} flag.159*160* @param needClientAuth whether client authentication should be required161*/162public void setNeedClientAuth(boolean needClientAuth) {163this.needClientAuth = needClientAuth;164}165}166167168