Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java
41161 views
1
/*
2
* Copyright (c) 2003, 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
package com.sun.security.sasl;
26
27
import java.security.AccessController;
28
import java.security.PrivilegedAction;
29
import java.security.NoSuchAlgorithmException;
30
import java.security.InvalidParameterException;
31
import java.security.ProviderException;
32
import static sun.security.util.SecurityConstants.PROVIDER_VER;
33
34
/**
35
* The SASL provider.
36
* Provides client support for
37
* - EXTERNAL
38
* - PLAIN
39
* - CRAM-MD5
40
* - DIGEST-MD5
41
* - NTLM
42
* And server support for
43
* - CRAM-MD5
44
* - DIGEST-MD5
45
* - NTLM
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: " +
54
"DIGEST-MD5, EXTERNAL, PLAIN, CRAM-MD5, NTLM;" +
55
" server mechanisms for: DIGEST-MD5, CRAM-MD5, NTLM)";
56
57
private static final class ProviderService
58
extends java.security.Provider.Service {
59
ProviderService(java.security.Provider p, String type, String algo,
60
String cn) {
61
super(p, type, algo, cn, null, null);
62
}
63
64
@Override
65
public Object newInstance(Object ctrParamObj)
66
throws NoSuchAlgorithmException {
67
String type = getType();
68
if (ctrParamObj != null) {
69
throw new InvalidParameterException
70
("constructorParameter not used with " + type + " engines");
71
}
72
73
String algo = getAlgorithm();
74
try {
75
// DIGEST-MD5, NTLM uses same impl class for client and server
76
if (algo.equals("DIGEST-MD5")) {
77
return new com.sun.security.sasl.digest.FactoryImpl();
78
}
79
if (algo.equals("NTLM")) {
80
return new com.sun.security.sasl.ntlm.FactoryImpl();
81
}
82
if (type.equals("SaslClientFactory")) {
83
if (algo.equals("EXTERNAL") || algo.equals("PLAIN") ||
84
algo.equals("CRAM-MD5")) {
85
return new com.sun.security.sasl.ClientFactoryImpl();
86
}
87
} else if (type.equals("SaslServerFactory")) {
88
if (algo.equals("CRAM-MD5")) {
89
return new com.sun.security.sasl.ServerFactoryImpl();
90
}
91
}
92
} catch (Exception ex) {
93
throw new NoSuchAlgorithmException("Error constructing " +
94
type + " for " + algo + " using SunSASL", ex);
95
}
96
throw new ProviderException("No impl for " + algo +
97
" " + type);
98
}
99
}
100
101
@SuppressWarnings("removal")
102
public Provider() {
103
super("SunSASL", PROVIDER_VER, info);
104
105
final Provider p = this;
106
AccessController.doPrivileged(new PrivilegedAction<Void>() {
107
public Void run() {
108
// Client mechanisms
109
putService(new ProviderService(p, "SaslClientFactory",
110
"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));
111
putService(new ProviderService(p, "SaslClientFactory",
112
"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));
113
putService(new ProviderService(p, "SaslClientFactory",
114
"EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl"));
115
putService(new ProviderService(p, "SaslClientFactory",
116
"PLAIN", "com.sun.security.sasl.ClientFactoryImpl"));
117
putService(new ProviderService(p, "SaslClientFactory",
118
"CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl"));
119
120
// Server mechanisms
121
putService(new ProviderService(p, "SaslServerFactory",
122
"CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl"));
123
putService(new ProviderService(p, "SaslServerFactory",
124
"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));
125
putService(new ProviderService(p, "SaslServerFactory",
126
"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));
127
return null;
128
}
129
});
130
}
131
}
132
133