Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.security.jgss/share/classes/sun/security/jgss/LoginConfigImpl.java
67696 views
1
/*
2
* Copyright (c) 2005, 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 sun.security.jgss;
27
28
import java.util.HashMap;
29
import javax.security.auth.login.AppConfigurationEntry;
30
import javax.security.auth.login.Configuration;
31
import org.ietf.jgss.Oid;
32
import sun.security.action.GetPropertyAction;
33
34
/**
35
* A Configuration implementation especially designed for JGSS.
36
*
37
* @author weijun.wang
38
* @since 1.6
39
*/
40
public class LoginConfigImpl extends Configuration {
41
42
private final Configuration config;
43
private final GSSCaller caller;
44
private final String mechName;
45
private static final sun.security.util.Debug debug =
46
sun.security.util.Debug.getInstance("gssloginconfig", "\t[GSS LoginConfigImpl]");
47
48
public static final boolean HTTP_USE_GLOBAL_CREDS;
49
50
static {
51
String prop = GetPropertyAction
52
.privilegedGetProperty("http.use.global.creds");
53
//HTTP_USE_GLOBAL_CREDS = "true".equalsIgnoreCase(prop); // default false
54
HTTP_USE_GLOBAL_CREDS = !"false".equalsIgnoreCase(prop); // default true
55
}
56
57
58
/**
59
* A new instance of LoginConfigImpl must be created for each login request
60
* since it's only used by a single (caller, mech) pair
61
* @param caller defined in GSSUtil as CALLER_XXX final fields
62
* @param mech defined in GSSUtil as XXX_MECH_OID final fields
63
*/
64
@SuppressWarnings("removal")
65
public LoginConfigImpl(GSSCaller caller, Oid mech) {
66
67
this.caller = caller;
68
69
if (mech.equals(GSSUtil.GSS_KRB5_MECH_OID)) {
70
mechName = "krb5";
71
} else {
72
throw new IllegalArgumentException(mech.toString() + " not supported");
73
}
74
config = java.security.AccessController.doPrivileged
75
(new java.security.PrivilegedAction <Configuration> () {
76
public Configuration run() {
77
return Configuration.getConfiguration();
78
}
79
});
80
}
81
82
/**
83
* @param name Almost useless, since the (caller, mech) is already passed
84
* into constructor. The only use will be detecting OTHER which
85
* is called in LoginContext
86
*/
87
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
88
89
AppConfigurationEntry[] entries = null;
90
91
// This is the second call from LoginContext, which we will just ignore
92
if ("OTHER".equalsIgnoreCase(name)) {
93
return null;
94
}
95
96
String[] alts = null;
97
98
// Compatibility:
99
// For the 4 old callers, old entry names will be used if the new
100
// entry name is not provided.
101
102
if ("krb5".equals(mechName)) {
103
if (caller == GSSCaller.CALLER_INITIATE) {
104
alts = new String[] {
105
"com.sun.security.jgss.krb5.initiate",
106
"com.sun.security.jgss.initiate",
107
};
108
} else if (caller == GSSCaller.CALLER_ACCEPT) {
109
alts = new String[] {
110
"com.sun.security.jgss.krb5.accept",
111
"com.sun.security.jgss.accept",
112
};
113
} else if (caller instanceof HttpCaller) {
114
alts = new String[] {
115
"com.sun.security.jgss.krb5.initiate",
116
};
117
} else if (caller == GSSCaller.CALLER_UNKNOWN) {
118
throw new AssertionError("caller not defined");
119
}
120
} else {
121
throw new IllegalArgumentException(mechName + " not supported");
122
// No other mech at the moment, maybe --
123
/*
124
switch (caller) {
125
case GSSUtil.CALLER_INITIATE:
126
case GSSUtil.CALLER_HTTP_NEGOTIATE:
127
alts = new String[] {
128
"com.sun.security.jgss." + mechName + ".initiate",
129
};
130
break;
131
case GSSUtil.CALLER_ACCEPT:
132
alts = new String[] {
133
"com.sun.security.jgss." + mechName + ".accept",
134
};
135
break;
136
case GSSUtil.CALLER_UNKNOWN:
137
// should never use
138
throw new AssertionError("caller cannot be unknown");
139
default:
140
throw new AssertionError("caller not defined");
141
}
142
*/
143
}
144
for (String alt: alts) {
145
entries = config.getAppConfigurationEntry(alt);
146
if (debug != null) {
147
debug.println("Trying " + alt +
148
((entries == null)?": does not exist.":": Found!"));
149
}
150
if (entries != null) {
151
break;
152
}
153
}
154
155
if (entries == null) {
156
if (debug != null) {
157
debug.println("Cannot read JGSS entry, use default values instead.");
158
}
159
entries = getDefaultConfigurationEntry();
160
}
161
return entries;
162
}
163
164
/**
165
* Default value for a caller-mech pair when no entry is defined in
166
* the system-wide Configuration object.
167
*/
168
private AppConfigurationEntry[] getDefaultConfigurationEntry() {
169
HashMap <String, String> options = new HashMap <String, String> (2);
170
171
if (mechName == null || mechName.equals("krb5")) {
172
if (isServerSide(caller)) {
173
// Assuming the keytab file can be found through
174
// krb5 config file or under user home directory
175
options.put("useKeyTab", "true");
176
options.put("storeKey", "true");
177
options.put("doNotPrompt", "true");
178
options.put("principal", "*");
179
options.put("isInitiator", "false");
180
} else {
181
if (caller instanceof HttpCaller && !HTTP_USE_GLOBAL_CREDS) {
182
options.put("useTicketCache", "false");
183
} else {
184
options.put("useTicketCache", "true");
185
}
186
options.put("doNotPrompt", "false");
187
}
188
return new AppConfigurationEntry[] {
189
new AppConfigurationEntry(
190
"com.sun.security.auth.module.Krb5LoginModule",
191
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
192
options)
193
};
194
}
195
return null;
196
}
197
198
private static boolean isServerSide (GSSCaller caller) {
199
return GSSCaller.CALLER_ACCEPT == caller;
200
}
201
}
202
203