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