📄 kerberosticket.java
字号:
if (destroyed) throw new IllegalStateException("This ticket is no longer valid"); return sessionKey; } /** * Returns the key type of the session key associated with this * ticket as defined by the Kerberos Protocol Specification. * * @return the key type of the session key associated with this * ticket. * * @see #getSessionKey() */ public final int getSessionKeyType() { if (destroyed) throw new IllegalStateException("This ticket is no longer valid"); return sessionKey.getKeyType(); } /** * Determines if this ticket is forwardable. * * @return true if this ticket is forwardable, false if not. */ public final boolean isForwardable() { return flags[FORWARDABLE_TICKET_FLAG]; } /** * Determines if this ticket had been forwarded or was issued based on * authentication involving a forwarded ticket-granting ticket. * * @return true if this ticket had been forwarded or was issued based on * authentication involving a forwarded ticket-granting ticket, * false otherwise. */ public final boolean isForwarded() { return flags[FORWARDED_TICKET_FLAG]; } /** * Determines if this ticket is proxiable. * * @return true if this ticket is proxiable, false if not. */ public final boolean isProxiable() { return flags[PROXIABLE_TICKET_FLAG]; } /** * Determines is this ticket is a proxy-ticket. * * @return true if this ticket is a proxy-ticket, false if not. */ public final boolean isProxy() { return flags[PROXY_TICKET_FLAG]; } /** * Determines is this ticket is post-dated. * * @return true if this ticket is post-dated, false if not. */ public final boolean isPostdated() { return flags[POSTDATED_TICKET_FLAG]; } /** * Determines is this ticket is renewable. If so, the {@link #refresh() * refresh} method can be called, assuming the validity period for * renewing is not already over. * * @return true if this ticket is renewable, false if not. */ public final boolean isRenewable() { return flags[RENEWABLE_TICKET_FLAG]; } /** * Determines if this ticket was issued using the Kerberos AS-Exchange * protocol, and not issued based on some ticket-granting ticket. * * @return true if this ticket was issued using the Kerberos AS-Exchange * protocol, false if not. */ public final boolean isInitial() { return flags[INITIAL_TICKET_FLAG]; } /** * Returns the flags associated with this ticket. Each element in the * returned array indicates the value for the corresponding bit in the * ASN.1 BitString that represents the ticket flags. * * @return the flags associated with this ticket. */ public final boolean[] getFlags() { return (flags == null? null: (boolean[]) flags.clone()); } /** * Returns the time that the client was authenticated. * * @return the time that the client was authenticated * or null if not set. */ public final java.util.Date getAuthTime() { return (authTime == null) ? null : new Date(authTime.getTime()); } /** * Returns the start time for this ticket's validity period. * * @return the start time for this ticket's validity period * or null if not set. */ public final java.util.Date getStartTime() { return (startTime == null) ? null : new Date(startTime.getTime()); } /** * Returns the expiration time for this ticket's validity period. * * @return the expiration time for this ticket's validity period. */ public final java.util.Date getEndTime() { return endTime; } /** * Returns the latest expiration time for this ticket, including all * renewals. This will return a null value for non-renewable tickets. * * @return the latest expiration time for this ticket. */ public final java.util.Date getRenewTill() { return (renewTill == null) ? null: new Date(renewTill.getTime()); } /** * Returns a list of addresses from where the ticket can be used. * * @return ths list of addresses or null, if the field was not * provided. */ public final java.net.InetAddress[] getClientAddresses() { return (clientAddresses == null? null: (InetAddress[]) clientAddresses.clone()); } /** * Returns an ASN.1 encoding of the entire ticket. * * @return an ASN.1 encoding of the entire ticket. */ public final byte[] getEncoded() { if (destroyed) throw new IllegalStateException("This ticket is no longer valid"); return (byte[]) asn1Encoding.clone(); } /** Determines if this ticket is still current. */ public boolean isCurrent() { return (System.currentTimeMillis() <= getEndTime().getTime()); } /** * Extends the validity period of this ticket. The ticket will contain * a new session key if the refresh operation succeeds. The refresh * operation will fail if the ticket is not renewable or the latest * allowable renew time has passed. Any other error returned by the * KDC will also cause this method to fail. * * Note: This method is not synchronized with the the accessor * methods of this object. Hence callers need to be aware of multiple * threads that might access this and try to renew it at the same * time. * * @throws RefreshFailedException if the ticket is not renewable, or * the latest allowable renew time has passed, or the KDC returns some * error. * * @see #isRenewable() * @see #getRenewTill() */ public void refresh() throws RefreshFailedException { if (destroyed) throw new RefreshFailedException("A destroyed ticket " + "cannot be renewd."); if (!isRenewable()) throw new RefreshFailedException("This ticket is not renewable"); if (System.currentTimeMillis() > getRenewTill().getTime()) throw new RefreshFailedException("This ticket is past " + "its last renewal time."); Throwable e = null; sun.security.krb5.Credentials krb5Creds = null; try { krb5Creds = new sun.security.krb5.Credentials(asn1Encoding, client.toString(), server.toString(), sessionKey.getEncoded(), sessionKey.getKeyType(), flags, authTime, startTime, endTime, renewTill, clientAddresses); krb5Creds = krb5Creds.renew(); } catch (sun.security.krb5.KrbException krbException) { e = krbException; } catch (java.io.IOException ioException) { e = ioException; } if (e != null) { RefreshFailedException rfException = new RefreshFailedException("Failed to renew Kerberos Ticket " + "for client " + client + " and server " + server + " - " + e.getMessage()); rfException.initCause(e); throw rfException; } /* * In case multiple threads try to refresh it at the same time. */ synchronized (this) { try { this.destroy(); } catch (DestroyFailedException dfException) { // Squelch it since we don't care about the old ticket. } init(krb5Creds.getEncoded(), new KerberosPrincipal(krb5Creds.getClient().getName()), new KerberosPrincipal(krb5Creds.getServer().getName()), krb5Creds.getSessionKey().getBytes(), krb5Creds.getSessionKey().getEType(), krb5Creds.getFlags(), krb5Creds.getAuthTime(), krb5Creds.getStartTime(), krb5Creds.getEndTime(), krb5Creds.getRenewTill(), krb5Creds.getClientAddresses()); destroyed = false; } } /** * Destroys the ticket and destroys any sensitive information stored in * it. */ public void destroy() throws DestroyFailedException { if (!destroyed) { Arrays.fill(asn1Encoding, (byte) 0); client = null; server = null; sessionKey.destroy(); flags = null; authTime = null; startTime = null; endTime = null; renewTill = null; clientAddresses = null; destroyed = true; } } /** * Determines if this ticket has been destroyed. */ public boolean isDestroyed() { return destroyed; } public String toString() { if (destroyed) throw new IllegalStateException("This ticket is no longer valid"); StringBuffer caddrBuf = new StringBuffer(); if (clientAddresses != null) { for (int i = 0; i < clientAddresses.length; i++) { caddrBuf.append("clientAddresses[" + i + "] = " + clientAddresses[i].toString()); } } return ("Ticket (hex) = " + "\n" + (new HexDumpEncoder()).encode(asn1Encoding) + "\n" + "Client Principal = " + client.toString() + "\n" + "Server Principal = " + server.toString() + "\n" + "Session Key = " + sessionKey.toString() + "\n" + "Forwardable Ticket " + flags[FORWARDABLE_TICKET_FLAG] + "\n" + "Forwarded Ticket " + flags[FORWARDED_TICKET_FLAG] + "\n" + "Proxiable Ticket " + flags[PROXIABLE_TICKET_FLAG] + "\n" + "Proxy Ticket " + flags[PROXY_TICKET_FLAG] + "\n" + "Postdated Ticket " + flags[POSTDATED_TICKET_FLAG] + "\n" + "Renewable Ticket " + flags[RENEWABLE_TICKET_FLAG] + "\n" + "Initial Ticket " + flags[RENEWABLE_TICKET_FLAG] + "\n" + "Auth Time = " + String.valueOf(authTime) + "\n" + "Start Time = " + String.valueOf(startTime) + "\n" + "End Time = " + endTime.toString() + "\n" + "Renew Till = " + String.valueOf(renewTill) + "\n" + "Client Addresses " + (clientAddresses == null ? " Null " : caddrBuf.toString() + "\n")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -