jdk/src/share/classes/com/sun/net/httpserver/HttpsParameters.java
author chegar
Mon, 18 Oct 2010 16:51:26 +0100
changeset 6906 d57020b6118f
parent 5506 202f599c92aa
child 7271 17d3fc18872d
permissions -rw-r--r--
6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.* Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.net.httpserver;
6906
d57020b6118f 6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.*
chegar
parents: 5506
diff changeset
    27
import java.net.InetSocketAddress;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.net.ssl.SSLParameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Represents the set of parameters for each https
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * connection negotiated with clients. One of these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * is created and passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * {@link HttpsConfigurator#configure(HttpsParameters)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * for every incoming https connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * in order to determine the parameters to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The underlying SSL parameters may be established either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * via the set/get methods of this class, or else via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * a {@link javax.net.ssl.SSLParameters} object. SSLParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is the preferred method, because in the future,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * additional configuration capabilities may be added to that class, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * it is easier to determine the set of supported parameters and their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * default values with SSLParameters. Also, if an SSLParameters object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * provided via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@link #setSSLParameters(SSLParameters)} then those parameter settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * are used, and any settings made in this object are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public abstract class HttpsParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private String[] cipherSuites;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private String[] protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private boolean wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private boolean needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected HttpsParameters() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Returns the HttpsConfigurator for this HttpsParameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public abstract HttpsConfigurator getHttpsConfigurator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Returns the address of the remote client initiating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public abstract InetSocketAddress getClientAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Sets the SSLParameters to use for this HttpsParameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The parameters must be supported by the SSLContext contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * by the HttpsConfigurator associated with this HttpsParameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * If no parameters are set, then the default behavior is to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * the default parameters from the associated SSLContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param params the SSLParameters to set. If <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * then the existing parameters (if any) remain unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @throws IllegalArgumentException if any of the parameters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *   invalid or unsupported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public abstract void setSSLParameters (SSLParameters params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Returns a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @return a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public String[] getCipherSuites() {
6906
d57020b6118f 6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.*
chegar
parents: 5506
diff changeset
    91
        return cipherSuites != null ? cipherSuites.clone() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Sets the array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void setCipherSuites(String[] cipherSuites) {
6906
d57020b6118f 6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.*
chegar
parents: 5506
diff changeset
   100
        this.cipherSuites = cipherSuites != null ? cipherSuites.clone() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Returns a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public String[] getProtocols() {
6906
d57020b6118f 6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.*
chegar
parents: 5506
diff changeset
   111
        return protocols != null ? protocols.clone() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Sets the array of protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void setProtocols(String[] protocols) {
6906
d57020b6118f 6992545: FindBugs scan - Malicious code vulnerability Warnings in com.sun.net.httpserver.HttpsParameters.*
chegar
parents: 5506
diff changeset
   120
        this.protocols = protocols != null ? protocols.clone() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Sets whether client authentication should be requested. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * this method clears the <code>needClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param wantClientAuth whether client authentication should be requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void setWantClientAuth(boolean wantClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.wantClientAuth = wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Returns whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Sets whether client authentication should be required. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * this method clears the <code>wantClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param needClientAuth whether client authentication should be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void setNeedClientAuth(boolean needClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.needClientAuth = needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}