author | weijun |
Tue, 27 Jan 2015 18:16:27 +0800 | |
changeset 28670 | bb9afe681988 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21278
diff
changeset
|
2 |
* Copyright (c) 2001, 2013, 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.internal; |
|
33 |
||
34 |
import sun.security.krb5.*; |
|
35 |
import java.io.IOException; |
|
36 |
||
37 |
/** |
|
38 |
* This class is a utility that contains much of the TGS-Exchange |
|
39 |
* protocol. It is used by ../Credentials.java for service ticket |
|
40 |
* acquisition in both the normal and the x-realm case. |
|
41 |
*/ |
|
42 |
public class CredentialsUtil { |
|
43 |
||
44 |
private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG; |
|
45 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
46 |
/** |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
47 |
* Used by a middle server to acquire credentials on behalf of a |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
48 |
* client to itself using the S4U2self extension. |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
49 |
* @param client the client to impersonate |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
50 |
* @param ccreds the TGT of the middle service |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
51 |
* @return the new creds (cname=client, sname=middle) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
52 |
*/ |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
53 |
public static Credentials acquireS4U2selfCreds(PrincipalName client, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
54 |
Credentials ccreds) throws KrbException, IOException { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
55 |
String uRealm = client.getRealmString(); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
56 |
String localRealm = ccreds.getClient().getRealmString(); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
57 |
if (!uRealm.equals(localRealm)) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
58 |
// TODO: we do not support kerberos referral now |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
59 |
throw new KrbException("Cross realm impersonation not supported"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
60 |
} |
28670
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
61 |
if (!ccreds.isForwardable()) { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
62 |
throw new KrbException("S4U2self needs a FORWARDABLE ticket"); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
63 |
} |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
64 |
KrbTgsReq req = new KrbTgsReq( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
65 |
ccreds, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
66 |
ccreds.getClient(), |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
67 |
new PAData(Krb5.PA_FOR_USER, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
68 |
new PAForUserEnc(client, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
69 |
ccreds.getSessionKey()).asn1Encode())); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
70 |
Credentials creds = req.sendAndGetCreds(); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
71 |
if (!creds.getClient().equals(client)) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
72 |
throw new KrbException("S4U2self request not honored by KDC"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
73 |
} |
28670
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
74 |
if (!creds.isForwardable()) { |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
75 |
throw new KrbException("S4U2self ticket must be FORWARDABLE"); |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
25859
diff
changeset
|
76 |
} |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
77 |
return creds; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
78 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
79 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
80 |
/** |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
81 |
* Used by a middle server to acquire a service ticket to a backend |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
82 |
* server using the S4U2proxy extension. |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
83 |
* @param backend the name of the backend service |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
84 |
* @param second the client's service ticket to the middle server |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
85 |
* @param ccreds the TGT of the middle server |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
86 |
* @return the creds (cname=client, sname=backend) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
87 |
*/ |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
88 |
public static Credentials acquireS4U2proxyCreds( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
89 |
String backend, Ticket second, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
90 |
PrincipalName client, Credentials ccreds) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
91 |
throws KrbException, IOException { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
92 |
KrbTgsReq req = new KrbTgsReq( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
93 |
ccreds, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
94 |
second, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
95 |
new PrincipalName(backend)); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
96 |
Credentials creds = req.sendAndGetCreds(); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
97 |
if (!creds.getClient().equals(client)) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
98 |
throw new KrbException("S4U2proxy request not honored by KDC"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
99 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
100 |
return creds; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
101 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
102 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
103 |
/** |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
104 |
* Acquires credentials for a specified service using initial |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
105 |
* credential. When the service has a different realm from the initial |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
106 |
* credential, we do cross-realm authentication - first, we use the |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
107 |
* current credential to get a cross-realm credential from the local KDC, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
108 |
* then use that cross-realm credential to request service credential |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
109 |
* from the foreign KDC. |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
110 |
* |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
111 |
* @param service the name of service principal |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
112 |
* @param ccreds client's initial credential |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
113 |
*/ |
2 | 114 |
public static Credentials acquireServiceCreds( |
115 |
String service, Credentials ccreds) |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
116 |
throws KrbException, IOException { |
13247 | 117 |
PrincipalName sname = new PrincipalName(service); |
2 | 118 |
String serviceRealm = sname.getRealmString(); |
119 |
String localRealm = ccreds.getClient().getRealmString(); |
|
120 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
121 |
if (localRealm.equals(serviceRealm)) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
122 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
123 |
System.out.println( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
124 |
">>> Credentials acquireServiceCreds: same realm"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
125 |
} |
2 | 126 |
return serviceCreds(sname, ccreds); |
127 |
} |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
128 |
Credentials theCreds = null; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
129 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
130 |
boolean[] okAsDelegate = new boolean[1]; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
131 |
Credentials theTgt = getTGTforRealm(localRealm, serviceRealm, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
132 |
ccreds, okAsDelegate); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
133 |
if (theTgt != null) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
134 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
135 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
136 |
+ "got right tgt"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
137 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
138 |
+ "obtaining service creds for " + sname); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
139 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
140 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
141 |
try { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
142 |
theCreds = serviceCreds(sname, theTgt); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
143 |
} catch (Exception exc) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
144 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
145 |
System.out.println(exc); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
146 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
147 |
theCreds = null; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
148 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
149 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
150 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
151 |
if (theCreds != null) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
152 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
153 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
154 |
+ "returning creds:"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
155 |
Credentials.printDebug(theCreds); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
156 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
157 |
if (!okAsDelegate[0]) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
158 |
theCreds.resetDelegate(); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
159 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
160 |
return theCreds; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
161 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
162 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_GEN_CRED, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
163 |
"No service creds"); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
164 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
165 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
166 |
/** |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
167 |
* Gets a TGT to another realm |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
168 |
* @param localRealm this realm |
20175
a65ad0a49e3c
8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents:
14413
diff
changeset
|
169 |
* @param serviceRealm the other realm, cannot equals to localRealm |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
170 |
* @param ccreds TGT in this realm |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
171 |
* @param okAsDelegate an [out] argument to receive the okAsDelegate |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
172 |
* property. True only if all realms allow delegation. |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
173 |
* @return the TGT for the other realm, null if cannot find a path |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
174 |
* @throws KrbException if something goes wrong |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
175 |
*/ |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
176 |
private static Credentials getTGTforRealm(String localRealm, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
177 |
String serviceRealm, Credentials ccreds, boolean[] okAsDelegate) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
178 |
throws KrbException { |
2 | 179 |
|
180 |
// Get a list of realms to traverse |
|
181 |
String[] realms = Realm.getRealmsList(localRealm, serviceRealm); |
|
182 |
||
183 |
int i = 0, k = 0; |
|
184 |
Credentials cTgt = null, newTgt = null, theTgt = null; |
|
13247 | 185 |
PrincipalName tempService = null; |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
186 |
String newTgtRealm = null; |
2 | 187 |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
188 |
okAsDelegate[0] = true; |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
189 |
for (cTgt = ccreds, i = 0; i < realms.length;) { |
13247 | 190 |
tempService = PrincipalName.tgsService(serviceRealm, realms[i]); |
2 | 191 |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
192 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
193 |
System.out.println( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
194 |
">>> Credentials acquireServiceCreds: main loop: [" |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
195 |
+ i +"] tempService=" + tempService); |
2 | 196 |
} |
197 |
||
198 |
try { |
|
199 |
newTgt = serviceCreds(tempService, cTgt); |
|
200 |
} catch (Exception exc) { |
|
201 |
newTgt = null; |
|
202 |
} |
|
203 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
204 |
if (newTgt == null) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
205 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
206 |
System.out.println(">>> Credentials acquireServiceCreds: " |
20175
a65ad0a49e3c
8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents:
14413
diff
changeset
|
207 |
+ "no tgt; searching thru capath"); |
2 | 208 |
} |
209 |
||
210 |
/* |
|
20175
a65ad0a49e3c
8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents:
14413
diff
changeset
|
211 |
* No tgt found. Let's go thru the realms list one by one. |
2 | 212 |
*/ |
20175
a65ad0a49e3c
8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents:
14413
diff
changeset
|
213 |
for (newTgt = null, k = i+1; |
a65ad0a49e3c
8012615: Realm.getRealmsList returns realms list in wrong
weijun
parents:
14413
diff
changeset
|
214 |
newTgt == null && k < realms.length; k++) { |
13247 | 215 |
tempService = PrincipalName.tgsService(realms[k], realms[i]); |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
216 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
217 |
System.out.println( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
218 |
">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
219 |
+ "inner loop: [" + k |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
220 |
+ "] tempService=" + tempService); |
2 | 221 |
} |
222 |
try { |
|
223 |
newTgt = serviceCreds(tempService, cTgt); |
|
224 |
} catch (Exception exc) { |
|
225 |
newTgt = null; |
|
226 |
} |
|
227 |
} |
|
228 |
} // Ends 'if (newTgt == null)' |
|
229 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
230 |
if (newTgt == null) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
231 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
232 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
233 |
+ "no tgt; cannot get creds"); |
2 | 234 |
} |
235 |
break; |
|
236 |
} |
|
237 |
||
238 |
/* |
|
239 |
* We have a tgt. It may or may not be for the target. |
|
240 |
* If it's for the target realm, we're done looking for a tgt. |
|
241 |
*/ |
|
242 |
newTgtRealm = newTgt.getServer().getInstanceComponent(); |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
243 |
if (okAsDelegate[0] && !newTgt.checkDelegate()) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
244 |
if (DEBUG) { |
4336 | 245 |
System.out.println(">>> Credentials acquireServiceCreds: " + |
246 |
"global OK-AS-DELEGATE turned off at " + |
|
247 |
newTgt.getServer()); |
|
248 |
} |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
249 |
okAsDelegate[0] = false; |
4336 | 250 |
} |
2 | 251 |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
252 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
253 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
254 |
+ "got tgt"); |
2 | 255 |
} |
256 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
257 |
if (newTgtRealm.equals(serviceRealm)) { |
2 | 258 |
/* We got the right tgt */ |
259 |
theTgt = newTgt; |
|
260 |
break; |
|
261 |
} |
|
262 |
||
263 |
/* |
|
264 |
* The new tgt is not for the target realm. |
|
265 |
* See if the realm of the new tgt is in the list of realms |
|
266 |
* and continue looking from there. |
|
267 |
*/ |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
268 |
for (k = i+1; k < realms.length; k++) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
269 |
if (newTgtRealm.equals(realms[k])) { |
2 | 270 |
break; |
271 |
} |
|
272 |
} |
|
273 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
274 |
if (k < realms.length) { |
2 | 275 |
/* |
276 |
* (re)set the counter so we start looking |
|
277 |
* from the realm we just obtained a tgt for. |
|
278 |
*/ |
|
279 |
i = k; |
|
280 |
cTgt = newTgt; |
|
281 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
282 |
if (DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
283 |
System.out.println(">>> Credentials acquireServiceCreds: " |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
284 |
+ "continuing with main loop counter reset to " + i); |
2 | 285 |
} |
286 |
continue; |
|
287 |
} |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
288 |
else { |
2 | 289 |
/* |
21278 | 290 |
* The new tgt's realm is not in the hierarchy of realms. |
2 | 291 |
* It's probably not safe to get a tgt from |
292 |
* a tgs that is outside the known list of realms. |
|
293 |
* Give up now. |
|
294 |
*/ |
|
295 |
break; |
|
296 |
} |
|
297 |
} // Ends outermost/main 'for' loop |
|
298 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
14342
diff
changeset
|
299 |
return theTgt; |
2 | 300 |
} |
301 |
||
302 |
/* |
|
303 |
* This method does the real job to request the service credential. |
|
304 |
*/ |
|
305 |
private static Credentials serviceCreds( |
|
13247 | 306 |
PrincipalName service, Credentials ccreds) |
2 | 307 |
throws KrbException, IOException { |
308 |
return new KrbTgsReq(ccreds, service).sendAndGetCreds(); |
|
309 |
} |
|
310 |
} |