author | weijun |
Wed, 11 Jul 2012 17:10:34 +0800 | |
changeset 13247 | 74902cfeb9c6 |
parent 11020 | a17d4ff7bae3 |
child 16905 | 0419f45c7761 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* |
|
27 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
28 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
29 |
*/ |
|
30 |
||
31 |
package sun.security.krb5.internal.ccache; |
|
32 |
||
33 |
import sun.security.krb5.*; |
|
34 |
import sun.security.krb5.internal.*; |
|
35 |
||
36 |
public class Credentials { |
|
73 | 37 |
|
38 |
PrincipalName cname; |
|
2 | 39 |
PrincipalName sname; |
73 | 40 |
EncryptionKey key; |
41 |
KerberosTime authtime; |
|
42 |
KerberosTime starttime;//optional |
|
43 |
KerberosTime endtime; |
|
44 |
KerberosTime renewTill; //optional |
|
45 |
HostAddresses caddr; //optional; for proxied tickets only |
|
2 | 46 |
AuthorizationData authorizationData; //optional, not being actually used |
47 |
public boolean isEncInSKey; // true if ticket is encrypted in another ticket's skey |
|
73 | 48 |
TicketFlags flags; |
2 | 49 |
Ticket ticket; |
73 | 50 |
Ticket secondTicket; //optional |
51 |
private boolean DEBUG = Krb5.DEBUG; |
|
2 | 52 |
|
73 | 53 |
public Credentials( |
54 |
PrincipalName new_cname, |
|
55 |
PrincipalName new_sname, |
|
56 |
EncryptionKey new_key, |
|
57 |
KerberosTime new_authtime, |
|
58 |
KerberosTime new_starttime, |
|
59 |
KerberosTime new_endtime, |
|
60 |
KerberosTime new_renewTill, |
|
61 |
boolean new_isEncInSKey, |
|
62 |
TicketFlags new_flags, |
|
63 |
HostAddresses new_caddr, |
|
64 |
AuthorizationData new_authData, |
|
65 |
Ticket new_ticket, |
|
66 |
Ticket new_secondTicket) { |
|
67 |
cname = (PrincipalName) new_cname.clone(); |
|
68 |
sname = (PrincipalName) new_sname.clone(); |
|
69 |
key = (EncryptionKey) new_key.clone(); |
|
2 | 70 |
|
73 | 71 |
authtime = (KerberosTime) new_authtime.clone(); |
76 | 72 |
if (new_starttime != null) { |
73 |
starttime = (KerberosTime) new_starttime.clone(); |
|
74 |
} |
|
73 | 75 |
endtime = (KerberosTime) new_endtime.clone(); |
76 | 76 |
if (new_renewTill != null) { |
77 |
renewTill = (KerberosTime) new_renewTill.clone(); |
|
78 |
} |
|
73 | 79 |
if (new_caddr != null) { |
80 |
caddr = (HostAddresses) new_caddr.clone(); |
|
81 |
} |
|
82 |
if (new_authData != null) { |
|
83 |
authorizationData = (AuthorizationData) new_authData.clone(); |
|
2 | 84 |
} |
85 |
||
73 | 86 |
isEncInSKey = new_isEncInSKey; |
87 |
flags = (TicketFlags) new_flags.clone(); |
|
88 |
ticket = (Ticket) (new_ticket.clone()); |
|
89 |
if (new_secondTicket != null) { |
|
90 |
secondTicket = (Ticket) new_secondTicket.clone(); |
|
91 |
} |
|
92 |
} |
|
2 | 93 |
|
73 | 94 |
public Credentials( |
95 |
KDCRep kdcRep, |
|
96 |
Ticket new_secondTicket, |
|
97 |
AuthorizationData new_authorizationData, |
|
98 |
boolean new_isEncInSKey) { |
|
99 |
if (kdcRep.encKDCRepPart == null) //can't store while encrypted |
|
100 |
{ |
|
101 |
return; |
|
2 | 102 |
} |
73 | 103 |
cname = (PrincipalName) kdcRep.cname.clone(); |
104 |
ticket = (Ticket) kdcRep.ticket.clone(); |
|
105 |
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); |
|
106 |
flags = (TicketFlags) kdcRep.encKDCRepPart.flags.clone(); |
|
107 |
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); |
|
76 | 108 |
if (kdcRep.encKDCRepPart.starttime != null) { |
109 |
starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone(); |
|
110 |
} |
|
73 | 111 |
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone(); |
76 | 112 |
if (kdcRep.encKDCRepPart.renewTill != null) { |
113 |
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); |
|
114 |
} |
|
73 | 115 |
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); |
116 |
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); |
|
117 |
secondTicket = (Ticket) new_secondTicket.clone(); |
|
118 |
authorizationData = |
|
119 |
(AuthorizationData) new_authorizationData.clone(); |
|
120 |
isEncInSKey = new_isEncInSKey; |
|
121 |
} |
|
2 | 122 |
|
73 | 123 |
public Credentials(KDCRep kdcRep) { |
124 |
this(kdcRep, null); |
|
125 |
} |
|
2 | 126 |
|
73 | 127 |
public Credentials(KDCRep kdcRep, Ticket new_ticket) { |
128 |
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); |
|
129 |
cname = (PrincipalName) kdcRep.cname.clone(); |
|
130 |
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); |
|
131 |
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); |
|
132 |
if (kdcRep.encKDCRepPart.starttime != null) { |
|
133 |
starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone(); |
|
134 |
} else { |
|
135 |
starttime = null; |
|
136 |
} |
|
137 |
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone(); |
|
138 |
if (kdcRep.encKDCRepPart.renewTill != null) { |
|
139 |
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); |
|
140 |
} else { |
|
141 |
renewTill = null; |
|
142 |
} |
|
143 |
// if (kdcRep.msgType == Krb5.KRB_AS_REP) { |
|
144 |
// isEncInSKey = false; |
|
145 |
// secondTicket = null; |
|
146 |
// } |
|
147 |
flags = kdcRep.encKDCRepPart.flags; |
|
148 |
if (kdcRep.encKDCRepPart.caddr != null) { |
|
149 |
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); |
|
150 |
} else { |
|
151 |
caddr = null; |
|
2 | 152 |
} |
73 | 153 |
ticket = (Ticket) kdcRep.ticket.clone(); |
154 |
if (new_ticket != null) { |
|
155 |
secondTicket = (Ticket) new_ticket.clone(); |
|
156 |
isEncInSKey = true; |
|
157 |
} else { |
|
158 |
secondTicket = null; |
|
159 |
isEncInSKey = false; |
|
160 |
} |
|
161 |
} |
|
2 | 162 |
|
73 | 163 |
/** |
164 |
* Checks if this credential is expired |
|
165 |
*/ |
|
166 |
public boolean isValid() { |
|
167 |
boolean valid = true; |
|
168 |
if (endtime.getTime() < System.currentTimeMillis()) { |
|
169 |
valid = false; |
|
76 | 170 |
} else if (starttime != null) { |
171 |
if (starttime.getTime() > System.currentTimeMillis()) { |
|
172 |
valid = false; |
|
173 |
} |
|
174 |
} else { |
|
175 |
if (authtime.getTime() > System.currentTimeMillis()) { |
|
176 |
valid = false; |
|
177 |
} |
|
2 | 178 |
} |
73 | 179 |
return valid; |
180 |
} |
|
2 | 181 |
|
73 | 182 |
public PrincipalName getServicePrincipal() throws RealmException { |
183 |
return sname; |
|
184 |
} |
|
2 | 185 |
|
73 | 186 |
public sun.security.krb5.Credentials setKrbCreds() { |
11011
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
187 |
// Note: We will not pass authorizationData to s.s.k.Credentials. The |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
188 |
// field in that class will be passed to Krb5Context as the return |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
189 |
// value of ExtendedGSSContext.inquireSecContext(KRB5_GET_AUTHZ_DATA), |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
190 |
// which is documented as the authData in the service ticket. That |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
191 |
// is on the acceptor side. |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
192 |
// |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
193 |
// This class is for the initiator side. Also, authdata inside a ccache |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
194 |
// is most likely to be the one in Authenticator in PA-TGS-REQ encoded |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
195 |
// in TGS-REQ, therefore only stored with a service ticket. Currently |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
196 |
// in Java, we only reads TGTs. |
73 | 197 |
return new sun.security.krb5.Credentials(ticket, |
198 |
cname, sname, key, flags, authtime, starttime, endtime, renewTill, caddr); |
|
199 |
} |
|
2 | 200 |
|
11020 | 201 |
public KerberosTime getStartTime() { |
202 |
return starttime; |
|
203 |
} |
|
204 |
||
2 | 205 |
public KerberosTime getAuthTime() { |
206 |
return authtime; |
|
207 |
} |
|
208 |
||
209 |
public KerberosTime getEndTime() { |
|
210 |
return endtime; |
|
211 |
} |
|
212 |
||
11020 | 213 |
public KerberosTime getRenewTill() { |
214 |
return renewTill; |
|
215 |
} |
|
216 |
||
2 | 217 |
public TicketFlags getTicketFlags() { |
218 |
return flags; |
|
219 |
} |
|
220 |
||
221 |
public int getEType() { |
|
222 |
return key.getEType(); |
|
223 |
} |
|
11020 | 224 |
|
225 |
public int getTktEType() { |
|
226 |
return ticket.encPart.getEType(); |
|
227 |
} |
|
2 | 228 |
} |