author | jmelvin |
Mon, 16 Apr 2012 18:09:53 -0400 | |
changeset 12538 | 211d6e82fe51 |
parent 12423 | a69d7fadb9f8 |
child 13247 | 74902cfeb9c6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12423
diff
changeset
|
2 |
* Copyright (c) 2000, 2012, 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 |
||
26 |
/* |
|
27 |
* |
|
28 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
29 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
30 |
*/ |
|
31 |
||
32 |
package sun.security.krb5; |
|
33 |
||
34 |
import sun.security.krb5.internal.*; |
|
35 |
import sun.security.krb5.internal.ccache.CredentialsCache; |
|
36 |
import sun.security.krb5.internal.crypto.EType; |
|
37 |
import java.io.IOException; |
|
38 |
import java.util.Date; |
|
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5974
diff
changeset
|
39 |
import java.util.Locale; |
2 | 40 |
import java.net.InetAddress; |
41 |
||
42 |
/** |
|
43 |
* This class encapsulates the concept of a Kerberos service |
|
44 |
* credential. That includes a Kerberos ticket and an associated |
|
45 |
* session key. |
|
46 |
*/ |
|
47 |
public class Credentials { |
|
48 |
||
49 |
Ticket ticket; |
|
50 |
PrincipalName client; |
|
51 |
PrincipalName server; |
|
52 |
EncryptionKey key; |
|
53 |
TicketFlags flags; |
|
54 |
KerberosTime authTime; |
|
55 |
KerberosTime startTime; |
|
56 |
KerberosTime endTime; |
|
57 |
KerberosTime renewTill; |
|
58 |
HostAddresses cAddr; |
|
59 |
EncryptionKey serviceKey; |
|
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
60 |
AuthorizationData authzData; |
2 | 61 |
private static boolean DEBUG = Krb5.DEBUG; |
62 |
private static CredentialsCache cache; |
|
63 |
static boolean alreadyLoaded = false; |
|
64 |
private static boolean alreadyTried = false; |
|
65 |
private static native Credentials acquireDefaultNativeCreds(); |
|
66 |
||
67 |
public Credentials(Ticket new_ticket, |
|
68 |
PrincipalName new_client, |
|
69 |
PrincipalName new_server, |
|
70 |
EncryptionKey new_key, |
|
71 |
TicketFlags new_flags, |
|
72 |
KerberosTime authTime, |
|
73 |
KerberosTime new_startTime, |
|
74 |
KerberosTime new_endTime, |
|
75 |
KerberosTime renewTill, |
|
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
76 |
HostAddresses cAddr, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
77 |
AuthorizationData authzData) { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
78 |
this(new_ticket, new_client, new_server, new_key, new_flags, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
79 |
authTime, new_startTime, new_endTime, renewTill, cAddr); |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
80 |
this.authzData = authzData; |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
81 |
} |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
82 |
|
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
83 |
public Credentials(Ticket new_ticket, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
84 |
PrincipalName new_client, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
85 |
PrincipalName new_server, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
86 |
EncryptionKey new_key, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
87 |
TicketFlags new_flags, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
88 |
KerberosTime authTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
89 |
KerberosTime new_startTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
90 |
KerberosTime new_endTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
91 |
KerberosTime renewTill, |
2 | 92 |
HostAddresses cAddr) { |
93 |
ticket = new_ticket; |
|
94 |
client = new_client; |
|
95 |
server = new_server; |
|
96 |
key = new_key; |
|
97 |
flags = new_flags; |
|
98 |
this.authTime = authTime; |
|
99 |
startTime = new_startTime; |
|
100 |
endTime = new_endTime; |
|
101 |
this.renewTill = renewTill; |
|
102 |
this.cAddr = cAddr; |
|
103 |
} |
|
104 |
||
105 |
public Credentials(byte[] encoding, |
|
106 |
String client, |
|
107 |
String server, |
|
108 |
byte[] keyBytes, |
|
109 |
int keyType, |
|
110 |
boolean[] flags, |
|
111 |
Date authTime, |
|
112 |
Date startTime, |
|
113 |
Date endTime, |
|
114 |
Date renewTill, |
|
115 |
InetAddress[] cAddrs) throws KrbException, IOException { |
|
116 |
this(new Ticket(encoding), |
|
117 |
new PrincipalName(client, PrincipalName.KRB_NT_PRINCIPAL), |
|
118 |
new PrincipalName(server, PrincipalName.KRB_NT_SRV_INST), |
|
119 |
new EncryptionKey(keyType, keyBytes), |
|
120 |
(flags == null? null: new TicketFlags(flags)), |
|
121 |
(authTime == null? null: new KerberosTime(authTime)), |
|
122 |
(startTime == null? null: new KerberosTime(startTime)), |
|
123 |
(endTime == null? null: new KerberosTime(endTime)), |
|
124 |
(renewTill == null? null: new KerberosTime(renewTill)), |
|
125 |
null); // caddrs are in the encoding at this point |
|
126 |
} |
|
127 |
||
128 |
/** |
|
129 |
* Acquires a service ticket for the specified service |
|
130 |
* principal. If the service ticket is not already available, it |
|
131 |
* obtains a new one from the KDC. |
|
132 |
*/ |
|
133 |
/* |
|
134 |
public Credentials(Credentials tgt, PrincipalName service) |
|
135 |
throws KrbException { |
|
136 |
} |
|
137 |
*/ |
|
138 |
||
139 |
public final PrincipalName getClient() { |
|
140 |
return client; |
|
141 |
} |
|
142 |
||
143 |
public final PrincipalName getServer() { |
|
144 |
return server; |
|
145 |
} |
|
146 |
||
147 |
public final EncryptionKey getSessionKey() { |
|
148 |
return key; |
|
149 |
} |
|
150 |
||
151 |
public final Date getAuthTime() { |
|
152 |
if (authTime != null) { |
|
153 |
return authTime.toDate(); |
|
154 |
} else { |
|
155 |
return null; |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
public final Date getStartTime() { |
|
160 |
if (startTime != null) |
|
161 |
{ |
|
162 |
return startTime.toDate(); |
|
163 |
} |
|
164 |
return null; |
|
165 |
} |
|
166 |
||
167 |
public final Date getEndTime() { |
|
168 |
if (endTime != null) |
|
169 |
{ |
|
170 |
return endTime.toDate(); |
|
171 |
} |
|
172 |
return null; |
|
173 |
} |
|
174 |
||
175 |
public final Date getRenewTill() { |
|
176 |
if (renewTill != null) |
|
177 |
{ |
|
178 |
return renewTill.toDate(); |
|
179 |
} |
|
180 |
return null; |
|
181 |
} |
|
182 |
||
183 |
public final boolean[] getFlags() { |
|
184 |
if (flags == null) // Can be in a KRB-CRED |
|
185 |
return null; |
|
186 |
return flags.toBooleanArray(); |
|
187 |
} |
|
188 |
||
189 |
public final InetAddress[] getClientAddresses() { |
|
190 |
||
191 |
if (cAddr == null) |
|
192 |
return null; |
|
193 |
||
194 |
return cAddr.getInetAddresses(); |
|
195 |
} |
|
196 |
||
197 |
public final byte[] getEncoded() { |
|
198 |
byte[] retVal = null; |
|
199 |
try { |
|
200 |
retVal = ticket.asn1Encode(); |
|
201 |
} catch (Asn1Exception e) { |
|
202 |
if (DEBUG) |
|
203 |
System.out.println(e); |
|
204 |
} catch (IOException ioe) { |
|
205 |
if (DEBUG) |
|
206 |
System.out.println(ioe); |
|
207 |
} |
|
208 |
return retVal; |
|
209 |
} |
|
210 |
||
211 |
public boolean isForwardable() { |
|
212 |
return flags.get(Krb5.TKT_OPTS_FORWARDABLE); |
|
213 |
} |
|
214 |
||
215 |
public boolean isRenewable() { |
|
216 |
return flags.get(Krb5.TKT_OPTS_RENEWABLE); |
|
217 |
} |
|
218 |
||
219 |
public Ticket getTicket() { |
|
220 |
return ticket; |
|
221 |
} |
|
222 |
||
223 |
public TicketFlags getTicketFlags() { |
|
224 |
return flags; |
|
225 |
} |
|
226 |
||
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
227 |
public AuthorizationData getAuthzData() { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
228 |
return authzData; |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
229 |
} |
2 | 230 |
/** |
231 |
* Checks if the service ticket returned by the KDC has the OK-AS-DELEGATE |
|
232 |
* flag set |
|
233 |
* @return true if OK-AS_DELEGATE flag is set, otherwise, return false. |
|
234 |
*/ |
|
235 |
public boolean checkDelegate() { |
|
4336 | 236 |
return flags.get(Krb5.TKT_OPTS_DELEGATE); |
237 |
} |
|
238 |
||
239 |
/** |
|
240 |
* Reset TKT_OPTS_DELEGATE to false, called at credentials acquirement |
|
241 |
* when one of the cross-realm TGTs does not have the OK-AS-DELEGATE |
|
242 |
* flag set. This info must be preservable and restorable through |
|
243 |
* the Krb5Util.credsToTicket/ticketToCreds() methods so that even if |
|
244 |
* the service ticket is cached it still remembers the cross-realm |
|
245 |
* authentication result. |
|
246 |
*/ |
|
247 |
public void resetDelegate() { |
|
248 |
flags.set(Krb5.TKT_OPTS_DELEGATE, false); |
|
2 | 249 |
} |
250 |
||
251 |
public Credentials renew() throws KrbException, IOException { |
|
252 |
KDCOptions options = new KDCOptions(); |
|
253 |
options.set(KDCOptions.RENEW, true); |
|
254 |
/* |
|
255 |
* Added here to pass KrbKdcRep.check:73 |
|
256 |
*/ |
|
257 |
options.set(KDCOptions.RENEWABLE, true); |
|
258 |
||
259 |
return new KrbTgsReq(options, |
|
260 |
this, |
|
261 |
server, |
|
262 |
null, // from |
|
263 |
null, // till |
|
264 |
null, // rtime |
|
265 |
null, // eTypes |
|
266 |
cAddr, |
|
267 |
null, |
|
268 |
null, |
|
269 |
null).sendAndGetCreds(); |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
* Returns a TGT for the given client principal from a ticket cache. |
|
274 |
* |
|
275 |
* @param princ the client principal. A value of null means that the |
|
276 |
* default principal name in the credentials cache will be used. |
|
277 |
* @param ticketCache the path to the tickets file. A value |
|
278 |
* of null will be accepted to indicate that the default |
|
279 |
* path should be searched |
|
280 |
* @returns the TGT credentials or null if none were found. If the tgt |
|
281 |
* expired, it is the responsibility of the caller to determine this. |
|
282 |
*/ |
|
283 |
public static Credentials acquireTGTFromCache(PrincipalName princ, |
|
284 |
String ticketCache) |
|
285 |
throws KrbException, IOException { |
|
286 |
||
287 |
if (ticketCache == null) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
288 |
// The default ticket cache on Windows and Mac is not a file. |
2 | 289 |
String os = java.security.AccessController.doPrivileged( |
290 |
new sun.security.action.GetPropertyAction("os.name")); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
291 |
if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") || |
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12423
diff
changeset
|
292 |
os.toUpperCase(Locale.ENGLISH).contains("OS X")) { |
2 | 293 |
Credentials creds = acquireDefaultCreds(); |
294 |
if (creds == null) { |
|
295 |
if (DEBUG) { |
|
296 |
System.out.println(">>> Found no TGT's in LSA"); |
|
297 |
} |
|
298 |
return null; |
|
299 |
} |
|
300 |
if (princ != null) { |
|
301 |
if (creds.getClient().equals(princ)) { |
|
302 |
if (DEBUG) { |
|
303 |
System.out.println(">>> Obtained TGT from LSA: " |
|
304 |
+ creds); |
|
305 |
} |
|
306 |
return creds; |
|
307 |
} else { |
|
308 |
if (DEBUG) { |
|
309 |
System.out.println(">>> LSA contains TGT for " |
|
310 |
+ creds.getClient() |
|
311 |
+ " not " |
|
312 |
+ princ); |
|
313 |
} |
|
314 |
return null; |
|
315 |
} |
|
316 |
} else { |
|
317 |
if (DEBUG) { |
|
318 |
System.out.println(">>> Obtained TGT from LSA: " |
|
319 |
+ creds); |
|
320 |
} |
|
321 |
return creds; |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
/* |
|
327 |
* Returns the appropriate cache. If ticketCache is null, it is the |
|
328 |
* default cache otherwise it is the cache filename contained in it. |
|
329 |
*/ |
|
330 |
CredentialsCache ccache = |
|
331 |
CredentialsCache.getInstance(princ, ticketCache); |
|
332 |
||
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
333 |
if (ccache == null) { |
2 | 334 |
return null; |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
335 |
} |
2 | 336 |
|
337 |
sun.security.krb5.internal.ccache.Credentials tgtCred = |
|
338 |
ccache.getDefaultCreds(); |
|
339 |
||
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
340 |
if (tgtCred == null) { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
341 |
return null; |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
342 |
} |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
343 |
|
2 | 344 |
if (EType.isSupported(tgtCred.getEType())) { |
345 |
return tgtCred.setKrbCreds(); |
|
346 |
} else { |
|
347 |
if (DEBUG) { |
|
348 |
System.out.println( |
|
349 |
">>> unsupported key type found the default TGT: " + |
|
350 |
tgtCred.getEType()); |
|
351 |
} |
|
352 |
return null; |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
/** |
|
357 |
* Acquires default credentials. |
|
358 |
* <br>The possible locations for default credentials cache is searched in |
|
359 |
* the following order: |
|
360 |
* <ol> |
|
361 |
* <li> The directory and cache file name specified by "KRB5CCNAME" system. |
|
362 |
* property. |
|
363 |
* <li> The directory and cache file name specified by "KRB5CCNAME" |
|
364 |
* environment variable. |
|
365 |
* <li> A cache file named krb5cc_{user.name} at {user.home} directory. |
|
366 |
* </ol> |
|
367 |
* @return a <code>KrbCreds</code> object if the credential is found, |
|
368 |
* otherwise return null. |
|
369 |
*/ |
|
370 |
||
371 |
// this method is intentionally changed to not check if the caller's |
|
372 |
// principal name matches cache file's principal name. |
|
373 |
// It assumes that the GSS call has |
|
374 |
// the privilege to access the default cache file. |
|
375 |
||
376 |
public static synchronized Credentials acquireDefaultCreds() { |
|
377 |
Credentials result = null; |
|
378 |
||
379 |
if (cache == null) { |
|
380 |
cache = CredentialsCache.getInstance(); |
|
381 |
} |
|
382 |
if (cache != null) { |
|
383 |
sun.security.krb5.internal.ccache.Credentials temp = |
|
384 |
cache.getDefaultCreds(); |
|
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
385 |
if (temp != null) { |
2 | 386 |
if (DEBUG) { |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
387 |
System.out.println(">>> KrbCreds found the default ticket" |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
388 |
+ " granting ticket in credential cache."); |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
389 |
} |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
390 |
if (EType.isSupported(temp.getEType())) { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
391 |
result = temp.setKrbCreds(); |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
392 |
} else { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
393 |
if (DEBUG) { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
394 |
System.out.println( |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
395 |
">>> unsupported key type found the default TGT: " + |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
396 |
temp.getEType()); |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
397 |
} |
2 | 398 |
} |
399 |
} |
|
400 |
} |
|
401 |
if (result == null) { |
|
402 |
// Doesn't seem to be a default cache on this system or |
|
403 |
// TGT has unsupported encryption type |
|
404 |
||
405 |
if (!alreadyTried) { |
|
406 |
// See if there's any native code to load |
|
407 |
try { |
|
408 |
ensureLoaded(); |
|
409 |
} catch (Exception e) { |
|
410 |
if (DEBUG) { |
|
411 |
System.out.println("Can not load credentials cache"); |
|
412 |
e.printStackTrace(); |
|
413 |
} |
|
414 |
alreadyTried = true; |
|
415 |
} |
|
416 |
} |
|
417 |
if (alreadyLoaded) { |
|
418 |
// There is some native code |
|
419 |
if (DEBUG) |
|
420 |
System.out.println(">> Acquire default native Credentials"); |
|
421 |
result = acquireDefaultNativeCreds(); |
|
422 |
// only TGT with DES key will be returned by native method |
|
423 |
} |
|
424 |
} |
|
425 |
return result; |
|
426 |
} |
|
427 |
||
428 |
/** |
|
429 |
* Acquires credentials for a specified service using initial credential. |
|
430 |
* When the service has a different realm |
|
431 |
* from the initial credential, we do cross-realm authentication |
|
432 |
* - first, we use the current credential to get |
|
433 |
* a cross-realm credential from the local KDC, then use that |
|
434 |
* cross-realm credential to request service credential |
|
435 |
* from the foreigh KDC. |
|
436 |
* |
|
437 |
* @param service the name of service principal using format |
|
438 |
* components@realm |
|
439 |
* @param ccreds client's initial credential. |
|
440 |
* @exception IOException if an error occurs in reading the credentials |
|
441 |
* cache |
|
442 |
* @exception KrbException if an error occurs specific to Kerberos |
|
443 |
* @return a <code>Credentials</code> object. |
|
444 |
*/ |
|
445 |
||
446 |
public static Credentials acquireServiceCreds(String service, |
|
447 |
Credentials ccreds) |
|
448 |
throws KrbException, IOException { |
|
449 |
return CredentialsUtil.acquireServiceCreds(service, ccreds); |
|
450 |
} |
|
451 |
||
452 |
public CredentialsCache getCache() { |
|
453 |
return cache; |
|
454 |
} |
|
455 |
||
456 |
public EncryptionKey getServiceKey() { |
|
457 |
return serviceKey; |
|
458 |
} |
|
459 |
||
460 |
/* |
|
461 |
* Prints out debug info. |
|
462 |
*/ |
|
463 |
public static void printDebug(Credentials c) { |
|
464 |
System.out.println(">>> DEBUG: ----Credentials----"); |
|
465 |
System.out.println("\tclient: " + c.client.toString()); |
|
466 |
System.out.println("\tserver: " + c.server.toString()); |
|
467 |
System.out.println("\tticket: realm: " + c.ticket.realm.toString()); |
|
468 |
System.out.println("\t sname: " + c.ticket.sname.toString()); |
|
469 |
if (c.startTime != null) { |
|
470 |
System.out.println("\tstartTime: " + c.startTime.getTime()); |
|
471 |
} |
|
472 |
System.out.println("\tendTime: " + c.endTime.getTime()); |
|
473 |
System.out.println(" ----Credentials end----"); |
|
474 |
} |
|
475 |
||
476 |
||
477 |
static void ensureLoaded() { |
|
478 |
java.security.AccessController.doPrivileged( |
|
479 |
new java.security.PrivilegedAction<Void> () { |
|
480 |
public Void run() { |
|
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12423
diff
changeset
|
481 |
if (System.getProperty("os.name").contains("OS X")) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
482 |
System.loadLibrary("osxkrb5"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
483 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
484 |
System.loadLibrary("w2k_lsa_auth"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
485 |
} |
2 | 486 |
return null; |
487 |
} |
|
488 |
}); |
|
489 |
alreadyLoaded = true; |
|
490 |
} |
|
491 |
||
492 |
public String toString() { |
|
493 |
StringBuffer buffer = new StringBuffer("Credentials:"); |
|
494 |
buffer.append("\nclient=").append(client); |
|
495 |
buffer.append("\nserver=").append(server); |
|
496 |
if (authTime != null) { |
|
497 |
buffer.append("\nauthTime=").append(authTime); |
|
498 |
} |
|
499 |
if (startTime != null) { |
|
500 |
buffer.append("\nstartTime=").append(startTime); |
|
501 |
} |
|
502 |
buffer.append("\nendTime=").append(endTime); |
|
503 |
buffer.append("\nrenewTill=").append(renewTill); |
|
504 |
buffer.append("\nflags: ").append(flags); |
|
505 |
buffer.append("\nEType (int): ").append(key.getEType()); |
|
506 |
return buffer.toString(); |
|
507 |
} |
|
508 |
||
509 |
} |