src/java.security.sasl/share/classes/javax/security/sasl/Sasl.java
author herrick
Fri, 21 Jun 2019 08:29:09 -0400
branchJDK-8200758-branch
changeset 57419 44c2481650ce
parent 54802 b0a1572ec64a
permissions -rw-r--r--
8225092: Several jpackage tests failes when run with jcov enabled Submitted-by: almatvee Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2019, 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 javax.security.sasl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.security.auth.callback.CallbackHandler;
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    29
import java.security.AccessController;
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    30
import java.security.PrivilegedAction;
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    31
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Iterator;
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    34
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Collections;
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
    39
import java.security.InvalidParameterException;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
    40
import java.security.NoSuchAlgorithmException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.Provider;
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
    42
import java.security.Provider.Service;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.Security;
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    44
import java.util.logging.Level;
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    45
import java.util.logging.Logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A static class for creating SASL clients and servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class defines the policy of how to locate, load, and instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * SASL clients and servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * For example, an application or library gets a SASL client by doing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * SaslClient sc = Sasl.createSaslClient(mechanisms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     authorizationId, protocol, serverName, props, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * It can then proceed to use the instance to create an authentication connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Similarly, a server gets a SASL server by using code that looks as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * SaslServer ss = Sasl.createSaslServer(mechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *     protocol, serverName, props, callbackHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author Rob Weltman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class Sasl {
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    73
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    74
    private static List<String> disabledMechanisms = new ArrayList<>();
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    75
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    76
    static {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    77
        String prop = AccessController.doPrivileged(
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    78
                (PrivilegedAction<String>)
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    79
                () -> Security.getProperty("jdk.sasl.disabledMechanisms"));
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    80
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    81
        if (prop != null) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    82
            for (String s : prop.split("\\s*,\\s*")) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    83
                if (!s.isEmpty()) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    84
                    disabledMechanisms.add(s);
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    85
                }
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    86
            }
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    87
        }
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    88
    }
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    89
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    90
    private static final String SASL_LOGGER_NAME = "javax.security.sasl";
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    91
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    92
    /**
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    93
     * Logger for debug messages
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    94
     */
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    95
    private static final Logger logger = Logger.getLogger(SASL_LOGGER_NAME);
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
    96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // Cannot create one of these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Sasl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * The name of a property that specifies the quality-of-protection to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The property contains a comma-separated, ordered list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * of quality-of-protection values that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * client or server is willing to support.  A qop value is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <ul>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   107
     * <li>{@code "auth"} - authentication only</li>
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   108
     * <li>{@code "auth-int"} - authentication plus integrity protection</li>
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   109
     * <li>{@code "auth-conf"} - authentication plus integrity and confidentiality
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * protection</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * The order of the list specifies the preference order of the client or
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   114
     * server. If this property is absent, the default qop is {@code "auth"}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   115
     * The value of this constant is {@code "javax.security.sasl.qop"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final String QOP = "javax.security.sasl.qop";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The name of a property that specifies the cipher strength to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * The property contains a comma-separated, ordered list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * of cipher strength values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * the client or server is willing to support. A strength value is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <ul>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   125
     * <li>{@code "low"}</li>
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   126
     * <li>{@code "medium"}</li>
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   127
     * <li>{@code "high"}</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The order of the list specifies the preference order of the client or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * server.  An implementation should allow configuration of the meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * of these values.  An application may use the Java Cryptography
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Extension (JCE) with JCE-aware mechanisms to control the selection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * cipher suites that match the strength values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * If this property is absent, the default strength is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   136
     * {@code "high,medium,low"}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   137
     * The value of this constant is {@code "javax.security.sasl.strength"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final String STRENGTH = "javax.security.sasl.strength";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The name of a property that specifies whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * server must authenticate to the client. The property contains
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   144
     * {@code "true"} if the server must
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   145
     * authenticate the to client; {@code "false"} otherwise.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   146
     * The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <br>The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   148
     * {@code "javax.security.sasl.server.authentication"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static final String SERVER_AUTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    "javax.security.sasl.server.authentication";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
14340
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   154
     * The name of a property that specifies the bound server name for
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   155
     * an unbound server. A server is created as an unbound server by setting
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   156
     * the {@code serverName} argument in {@link #createSaslServer} as null.
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   157
     * The property contains the bound host name after the authentication
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   158
     * exchange has completed. It is only available on the server side.
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   159
     * <br>The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   160
     * {@code "javax.security.sasl.bound.server.name"}.
14340
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   161
     */
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   162
    public static final String BOUND_SERVER_NAME =
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   163
    "javax.security.sasl.bound.server.name";
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   164
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   165
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * The name of a property that specifies the maximum size of the receive
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   167
     * buffer in bytes of {@code SaslClient}/{@code SaslServer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * The property contains the string representation of an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <br>If this property is absent, the default size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * is defined by the mechanism.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   171
     * <br>The value of this constant is {@code "javax.security.sasl.maxbuffer"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public static final String MAX_BUFFER = "javax.security.sasl.maxbuffer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The name of a property that specifies the maximum size of the raw send
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   177
     * buffer in bytes of {@code SaslClient}/{@code SaslServer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * The property contains the string representation of an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * The value of this property is negotiated between the client and server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * during the authentication exchange.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   181
     * <br>The value of this constant is {@code "javax.security.sasl.rawsendsize"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static final String RAW_SEND_SIZE = "javax.security.sasl.rawsendsize";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * The name of a property that specifies whether to reuse previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * authenticated session information. The property contains "true" if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * mechanism implementation may attempt to reuse previously authenticated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * session information; it contains "false" if the implementation must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * not reuse previously authenticated session information.  A setting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * "true" serves only as a hint: it does not necessarily entail actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * reuse because reuse might not be possible due to a number of reasons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * including, but not limited to, lack of mechanism support for reuse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * expiration of reusable information, and the peer's refusal to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * reuse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The property's default value is "false".  The value of this constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * is "javax.security.sasl.reuse".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Note that all other parameters and properties required to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * SASL client/server instance must be provided regardless of whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * this property has been supplied. That is, you cannot supply any less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * information in anticipation of reuse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Mechanism implementations that support reuse might allow customization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * of its implementation, for factors such as cache size, timeouts, and
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18830
diff changeset
   207
     * criteria for reusability. Such customizations are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     public static final String REUSE = "javax.security.sasl.reuse";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The name of a property that specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * whether mechanisms susceptible to simple plain passive attacks (e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * "PLAIN") are not permitted. The property
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   216
     * contains {@code "true"} if such mechanisms are not permitted;
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   217
     * {@code "false"} if such mechanisms are permitted.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   218
     * The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <br>The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   220
     * {@code "javax.security.sasl.policy.noplaintext"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public static final String POLICY_NOPLAINTEXT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    "javax.security.sasl.policy.noplaintext";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The name of a property that specifies whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * mechanisms susceptible to active (non-dictionary) attacks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * are not permitted.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   229
     * The property contains {@code "true"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * if mechanisms susceptible to active attacks
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   231
     * are not permitted; {@code "false"} if such mechanisms are permitted.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   232
     * The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <br>The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   234
     * {@code "javax.security.sasl.policy.noactive"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static final String POLICY_NOACTIVE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    "javax.security.sasl.policy.noactive";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * The name of a property that specifies whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * mechanisms susceptible to passive dictionary attacks are not permitted.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   242
     * The property contains {@code "true"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * if mechanisms susceptible to dictionary attacks are not permitted;
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   244
     * {@code "false"} if such mechanisms are permitted.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   245
     * The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   248
     * {@code "javax.security.sasl.policy.nodictionary"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static final String POLICY_NODICTIONARY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    "javax.security.sasl.policy.nodictionary";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * The name of a property that specifies whether mechanisms that accept
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   255
     * anonymous login are not permitted. The property contains {@code "true"}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * if mechanisms that accept anonymous login are not permitted;
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   257
     * {@code "false"}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   258
     * if such mechanisms are permitted. The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   261
     * {@code "javax.security.sasl.policy.noanonymous"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public static final String POLICY_NOANONYMOUS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    "javax.security.sasl.policy.noanonymous";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      * The name of a property that specifies whether mechanisms that implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      * forward secrecy between sessions are required. Forward secrecy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * means that breaking into one session will not automatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * provide information for breaking into future sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * The property
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   272
      * contains {@code "true"} if mechanisms that implement forward secrecy
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   273
      * between sessions are required; {@code "false"} if such mechanisms
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   274
      * are not required. The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      *<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      * The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   277
      * {@code "javax.security.sasl.policy.forward"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public static final String POLICY_FORWARD_SECRECY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    "javax.security.sasl.policy.forward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * The name of a property that specifies whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * mechanisms that pass client credentials are required. The property
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   285
     * contains {@code "true"} if mechanisms that pass
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   286
     * client credentials are required; {@code "false"}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   287
     * if such mechanisms are not required. The default is {@code "false"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   290
     * {@code "javax.security.sasl.policy.credentials"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public static final String POLICY_PASS_CREDENTIALS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    "javax.security.sasl.policy.credentials";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * The name of a property that specifies the credentials to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * The property contains a mechanism-specific Java credential object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Mechanism implementations may examine the value of this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * to determine whether it is a class that they support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * The property may be used to supply credentials to a mechanism that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * supports delegated authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * The value of this constant is
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   304
     * {@code "javax.security.sasl.credentials"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public static final String CREDENTIALS = "javax.security.sasl.credentials";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   309
     * Creates a {@code SaslClient} using the parameters supplied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * This method uses the
45665
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   312
     * {@extLink security_guide_jca JCA Security Provider Framework},
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   313
     * described in the
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   314
     * "Java Cryptography Architecture (JCA) Reference Guide", for
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   315
     * locating and selecting a {@code SaslClient} implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * First, it
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   318
     * obtains an ordered list of {@code SaslClientFactory} instances from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * the registered security providers for the "SaslClientFactory" service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * and the specified SASL mechanism(s). It then invokes
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   321
     * {@code createSaslClient()} on each factory instance on the list
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   322
     * until one produces a non-null {@code SaslClient} instance. It returns
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   323
     * the non-null {@code SaslClient} instance, or null if the search fails
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   324
     * to produce a non-null {@code SaslClient} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * A security provider for SaslClientFactory registers with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * JCA Security Provider Framework keys of the form <br>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   328
     * {@code SaslClientFactory.}<em>{@code mechanism_name}</em>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * and values that are class names of implementations of
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   331
     * {@code javax.security.sasl.SaslClientFactory}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * For example, a provider that contains a factory class,
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   334
     * {@code com.wiz.sasl.digest.ClientFactory}, that supports the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * "DIGEST-MD5" mechanism would register the following entry with the JCA:
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   336
     * {@code SaslClientFactory.DIGEST-MD5 com.wiz.sasl.digest.ClientFactory}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * See the
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   339
     * "Java Cryptography Architecture API Specification &amp; Reference"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * for information about how to install and configure security service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *  providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   343
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   344
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   345
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   346
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   347
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   348
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   349
     * {@link Security#getProviders() Security.getProviders()}.
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   350
     * <p>
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   351
     * If a mechanism is listed in the {@code jdk.sasl.disabledMechanisms}
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   352
     * security property, it will be ignored and won't be negotiated.
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   353
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param mechanisms The non-null list of mechanism names to try. Each is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * IANA-registered name of a SASL mechanism. (e.g. "GSSAPI", "CRAM-MD5").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @param authorizationId The possibly null protocol-dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * identification to be used for authorization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * If null or empty, the server derives an authorization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * ID from the client's authentication credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * When the SASL authentication completes successfully,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * the specified entity is granted access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param protocol The non-null string name of the protocol for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * the authentication is being performed (e.g., "ldap").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param serverName The non-null fully-qualified host name of the server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * to authenticate to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param props The possibly null set of properties used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * select the SASL mechanism and to configure the authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * exchange of the selected mechanism.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   372
     * For example, if {@code props} contains the
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   373
     * {@code Sasl.POLICY_NOPLAINTEXT} property with the value
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   374
     * {@code "true"}, then the selected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * SASL mechanism must not be susceptible to simple plain passive attacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * In addition to the standard properties declared in this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * other, possibly mechanism-specific, properties can be included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Properties not relevant to the selected mechanism are ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * including any map entries with non-String keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param cbh The possibly null callback handler to used by the SASL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * mechanisms to get further information from the application/library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * to complete the authentication. For example, a SASL mechanism might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * require the authentication ID, password and realm from the caller.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   385
     * The authentication ID is requested by using a {@code NameCallback}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   386
     * The password is requested by using a {@code PasswordCallback}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   387
     * The realm is requested by using a {@code RealmChoiceCallback} if there is a list
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   388
     * of realms to choose from, and by using a {@code RealmCallback} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * the realm must be entered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   391
     *@return A possibly null {@code SaslClient} created using the parameters
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   392
     * supplied. If null, cannot find a {@code SaslClientFactory}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * that will produce one.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   394
     *@exception SaslException If cannot create a {@code SaslClient} because
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * of an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public static SaslClient createSaslClient(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        String[] mechanisms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        String authorizationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        String protocol,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        String serverName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        Map<String,?> props,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        CallbackHandler cbh) throws SaslException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        SaslClient mech = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        SaslClientFactory fac;
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   407
        Service service;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        String mechName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        for (int i = 0; i < mechanisms.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if ((mechName=mechanisms[i]) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    "Mechanism name cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            } else if (mechName.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                continue;
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   416
            } else if (isDisabled(mechName)) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   417
                logger.log(Level.FINE,
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   418
                        "Disabled " + mechName + " mechanism ignored");
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   419
                continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   421
            String type = "SaslClientFactory";
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   422
            Provider[] provs = Security.getProviders(type + "." + mechName);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   423
            if (provs != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   424
                for (Provider p : provs) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   425
                    service = p.getService(type, mechName);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   426
                    if (service == null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   427
                        // no such service exists
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   428
                        continue;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   429
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   431
                    fac = (SaslClientFactory) loadFactory(service);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   432
                    if (fac != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   433
                        mech = fac.createSaslClient(
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   434
                            new String[]{mechanisms[i]}, authorizationId,
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   435
                            protocol, serverName, props, cbh);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   436
                        if (mech != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   437
                            return mech;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   438
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   446
    private static Object loadFactory(Service service)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        throws SaslException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
             * Load the implementation class with the same class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
             * that was used to load the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
             * In order to get the class loader of a class, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
             * caller's class loader must be the same as or an ancestor of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
             * the class loader being returned. Otherwise, the caller must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
             * have "getClassLoader" permission, or a SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
             * will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
             */
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   458
            return service.newInstance(null);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   459
        } catch (InvalidParameterException | NoSuchAlgorithmException e) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   460
            throw new SaslException("Cannot instantiate service " + service, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   466
     * Creates a {@code SaslServer} for the specified mechanism.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * This method uses the
45665
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   469
     * {@extLink security_guide_jca JCA Security Provider Framework},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * described in the
45665
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   471
     * "Java Cryptography Architecture (JCA) Reference Guide", for
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 37348
diff changeset
   472
     * locating and selecting a {@code SaslClient} implementation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * First, it
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   475
     * obtains an ordered list of {@code SaslServerFactory} instances from
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * the registered security providers for the "SaslServerFactory" service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * and the specified mechanism. It then invokes
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   478
     * {@code createSaslServer()} on each factory instance on the list
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   479
     * until one produces a non-null {@code SaslServer} instance. It returns
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   480
     * the non-null {@code SaslServer} instance, or null if the search fails
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   481
     * to produce a non-null {@code SaslServer} instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * A security provider for SaslServerFactory registers with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * JCA Security Provider Framework keys of the form <br>
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   485
     * {@code SaslServerFactory.}<em>{@code mechanism_name}</em>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * and values that are class names of implementations of
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   488
     * {@code javax.security.sasl.SaslServerFactory}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * For example, a provider that contains a factory class,
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   491
     * {@code com.wiz.sasl.digest.ServerFactory}, that supports the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * "DIGEST-MD5" mechanism would register the following entry with the JCA:
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   493
     * {@code SaslServerFactory.DIGEST-MD5  com.wiz.sasl.digest.ServerFactory}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * See the
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   496
     * "Java Cryptography Architecture API Specification &amp; Reference"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * for information about how to install and configure security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * service providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   500
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   501
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   502
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   503
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   504
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   505
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   506
     * {@link Security#getProviders() Security.getProviders()}.
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   507
     * <p>
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   508
     * If {@code mechanism} is listed in the {@code jdk.sasl.disabledMechanisms}
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   509
     * security property, it will be ignored and this method returns {@code null}.
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 31270
diff changeset
   510
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param mechanism The non-null mechanism name. It must be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * IANA-registered name of a SASL mechanism. (e.g. "GSSAPI", "CRAM-MD5").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param protocol The non-null string name of the protocol for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * the authentication is being performed (e.g., "ldap").
14340
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   515
     * @param serverName The fully qualified host name of the server, or null
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   516
     * if the server is not bound to any specific host name. If the mechanism
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   517
     * does not allow an unbound server, a {@code SaslException} will
14340
e150cbaf584e 7110803: SASL service for multiple hostnames
weijun
parents: 10709
diff changeset
   518
     * be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @param props The possibly null set of properties used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * select the SASL mechanism and to configure the authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * exchange of the selected mechanism.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   522
     * For example, if {@code props} contains the
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   523
     * {@code Sasl.POLICY_NOPLAINTEXT} property with the value
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   524
     * {@code "true"}, then the selected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * SASL mechanism must not be susceptible to simple plain passive attacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * In addition to the standard properties declared in this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * other, possibly mechanism-specific, properties can be included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Properties not relevant to the selected mechanism are ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * including any map entries with non-String keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param cbh The possibly null callback handler to used by the SASL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * mechanisms to get further information from the application/library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * to complete the authentication. For example, a SASL mechanism might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * require the authentication ID, password and realm from the caller.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   535
     * The authentication ID is requested by using a {@code NameCallback}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   536
     * The password is requested by using a {@code PasswordCallback}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   537
     * The realm is requested by using a {@code RealmChoiceCallback} if there is a list
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   538
     * of realms to choose from, and by using a {@code RealmCallback} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * the realm must be entered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   541
     *@return A possibly null {@code SaslServer} created using the parameters
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   542
     * supplied. If null, cannot find a {@code SaslServerFactory}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * that will produce one.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   544
     *@exception SaslException If cannot create a {@code SaslServer} because
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * of an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public static SaslServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        createSaslServer(String mechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    String protocol,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    String serverName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    Map<String,?> props,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    javax.security.auth.callback.CallbackHandler cbh)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        throws SaslException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        SaslServer mech = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        SaslServerFactory fac;
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   557
        Service service;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (mechanism == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            throw new NullPointerException("Mechanism name cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        } else if (mechanism.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            return null;
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   563
        } else if (isDisabled(mechanism)) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   564
            logger.log(Level.FINE,
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   565
                    "Disabled " + mechanism + " mechanism ignored");
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   566
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   569
        String type = "SaslServerFactory";
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   570
        Provider[] provs = Security.getProviders(type + "." + mechanism);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   571
        if (provs != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   572
            for (Provider p : provs) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   573
                service = p.getService(type, mechanism);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   574
                if (service == null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   575
                    throw new SaslException("Provider does not support " +
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   576
                        mechanism + " " + type);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   577
                }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   578
                fac = (SaslServerFactory) loadFactory(service);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   579
                if (fac != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   580
                    mech = fac.createSaslServer(
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   581
                        mechanism, protocol, serverName, props, cbh);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   582
                    if (mech != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   583
                        return mech;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   584
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   592
     * Gets an enumeration of known factories for producing {@code SaslClient}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * This method uses the same algorithm for locating factories as
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   594
     * {@code createSaslClient()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @return A non-null enumeration of known factories for producing
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   596
     * {@code SaslClient}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @see #createSaslClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public static Enumeration<SaslClientFactory> getSaslClientFactories() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        Set<Object> facs = getFactories("SaslClientFactory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        final Iterator<Object> iter = facs.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return new Enumeration<SaslClientFactory>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                return iter.hasNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            public SaslClientFactory nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                return (SaslClientFactory)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   613
     * Gets an enumeration of known factories for producing {@code SaslServer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * This method uses the same algorithm for locating factories as
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   615
     * {@code createSaslServer()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @return A non-null enumeration of known factories for producing
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 18156
diff changeset
   617
     * {@code SaslServer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @see #createSaslServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public static Enumeration<SaslServerFactory> getSaslServerFactories() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        Set<Object> facs = getFactories("SaslServerFactory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        final Iterator<Object> iter = facs.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return new Enumeration<SaslServerFactory>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                return iter.hasNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            public SaslServerFactory nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                return (SaslServerFactory)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private static Set<Object> getFactories(String serviceName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        HashSet<Object> result = new HashSet<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if ((serviceName == null) || (serviceName.length() == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            (serviceName.endsWith("."))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   641
        Provider[] provs = Security.getProviders();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        Object fac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   644
        for (Provider p : provs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   646
            Iterator<Service> iter = p.getServices().iterator();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   647
            while (iter.hasNext()) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   648
                Service s = iter.next();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   649
                if (s.getType().equals(serviceName)) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   650
                    try {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   651
                        fac = loadFactory(s);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   652
                        if (fac != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   653
                            result.add(fac);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        }
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 25859
diff changeset
   655
                    } catch (Exception ignore) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        return Collections.unmodifiableSet(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
54802
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   662
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   663
    private static boolean isDisabled(String name) {
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   664
        return disabledMechanisms.contains(name);
b0a1572ec64a 8200400: Restrict Sasl mechanisms
weijun
parents: 47216
diff changeset
   665
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
}