author | iignatyev |
Thu, 05 Jul 2018 20:00:04 -0700 | |
changeset 50997 | b9361d8c58a5 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
33991
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
package com.sun.security.sasl; |
|
26 |
||
27 |
import java.security.AccessController; |
|
28 |
import java.security.PrivilegedAction; |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
29 |
import java.security.NoSuchAlgorithmException; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
30 |
import java.security.InvalidParameterException; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
31 |
import java.security.ProviderException; |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
33991
diff
changeset
|
32 |
import static sun.security.util.SecurityConstants.PROVIDER_VER; |
2 | 33 |
|
34 |
/** |
|
35 |
* The SASL provider. |
|
36 |
* Provides client support for |
|
37 |
* - EXTERNAL |
|
38 |
* - PLAIN |
|
39 |
* - CRAM-MD5 |
|
40 |
* - DIGEST-MD5 |
|
6517
151856936fd8
6911951: NTLM should be a supported Java SASL mechanism
weijun
parents:
5506
diff
changeset
|
41 |
* - NTLM |
2 | 42 |
* And server support for |
43 |
* - CRAM-MD5 |
|
44 |
* - DIGEST-MD5 |
|
6517
151856936fd8
6911951: NTLM should be a supported Java SASL mechanism
weijun
parents:
5506
diff
changeset
|
45 |
* - NTLM |
2 | 46 |
*/ |
47 |
||
48 |
public final class Provider extends java.security.Provider { |
|
49 |
||
50 |
private static final long serialVersionUID = 8622598936488630849L; |
|
51 |
||
52 |
private static final String info = "Sun SASL provider" + |
|
53 |
"(implements client mechanisms for: " + |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
54 |
"DIGEST-MD5, EXTERNAL, PLAIN, CRAM-MD5, NTLM;" + |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
55 |
" server mechanisms for: DIGEST-MD5, CRAM-MD5, NTLM)"; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
56 |
|
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
57 |
private static final class ProviderService |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
58 |
extends java.security.Provider.Service { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
59 |
ProviderService(java.security.Provider p, String type, String algo, |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
60 |
String cn) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
61 |
super(p, type, algo, cn, null, null); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
62 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
63 |
|
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
64 |
@Override |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
65 |
public Object newInstance(Object ctrParamObj) |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
66 |
throws NoSuchAlgorithmException { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
67 |
String type = getType(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
68 |
if (ctrParamObj != null) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
69 |
throw new InvalidParameterException |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
70 |
("constructorParameter not used with " + type + " engines"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
71 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
72 |
|
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
73 |
String algo = getAlgorithm(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
74 |
try { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
75 |
// DIGEST-MD5, NTLM uses same impl class for client and server |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
76 |
if (algo.equals("DIGEST-MD5")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
77 |
return new com.sun.security.sasl.digest.FactoryImpl(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
78 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
79 |
if (algo.equals("NTLM")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
80 |
return new com.sun.security.sasl.ntlm.FactoryImpl(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
81 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
82 |
if (type.equals("SaslClientFactory")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
83 |
if (algo.equals("EXTERNAL") || algo.equals("PLAIN") || |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
84 |
algo.equals("CRAM-MD5")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
85 |
return new com.sun.security.sasl.ClientFactoryImpl(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
86 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
87 |
} else if (type.equals("SaslServerFactory")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
88 |
if (algo.equals("CRAM-MD5")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
89 |
return new com.sun.security.sasl.ServerFactoryImpl(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
90 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
91 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
92 |
} catch (Exception ex) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
93 |
throw new NoSuchAlgorithmException("Error constructing " + |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
94 |
type + " for " + algo + " using SunSASL", ex); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
95 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
96 |
throw new ProviderException("No impl for " + algo + |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
97 |
" " + type); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
98 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
99 |
} |
2 | 100 |
|
101 |
public Provider() { |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
33991
diff
changeset
|
102 |
super("SunSASL", PROVIDER_VER, info); |
2 | 103 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
104 |
final Provider p = this; |
2 | 105 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
106 |
public Void run() { |
|
107 |
// Client mechanisms |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
108 |
putService(new ProviderService(p, "SaslClientFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
109 |
"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
110 |
putService(new ProviderService(p, "SaslClientFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
111 |
"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
112 |
putService(new ProviderService(p, "SaslClientFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
113 |
"EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
114 |
putService(new ProviderService(p, "SaslClientFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
115 |
"PLAIN", "com.sun.security.sasl.ClientFactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
116 |
putService(new ProviderService(p, "SaslClientFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
117 |
"CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl")); |
2 | 118 |
|
119 |
// Server mechanisms |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
120 |
putService(new ProviderService(p, "SaslServerFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
121 |
"CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
122 |
putService(new ProviderService(p, "SaslServerFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
123 |
"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
124 |
putService(new ProviderService(p, "SaslServerFactory", |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
25859
diff
changeset
|
125 |
"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); |
2 | 126 |
return null; |
127 |
} |
|
128 |
}); |
|
129 |
} |
|
130 |
} |