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