Java Code Examples for javax.security.auth.RefreshFailedException#initCause()

The following examples show how to use javax.security.auth.RefreshFailedException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KerberosTicket.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 2
Source File: KerberosTicket.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 (getRenewTill() == null) {
        // Renewable ticket without renew-till. Illegal and ignored.
        return;
    }

    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(),
                                                (clientAlias != null ?
                                                        clientAlias.getName() : null),
                                                server.toString(),
                                                (serverAlias != null ?
                                                        serverAlias.getName() : null),
                                                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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 3
Source File: KerberosTicket.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 (getRenewTill() == null) {
        // Renewable ticket without renew-till. Illegal and ignored.
        return;
    }

    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(),
                                                (clientAlias != null ?
                                                        clientAlias.getName() : null),
                                                server.toString(),
                                                (serverAlias != null ?
                                                        serverAlias.getName() : null),
                                                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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 4
Source File: KerberosTicket.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 5
Source File: KerberosTicket.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 6
Source File: KerberosTicket.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 (getRenewTill() == null) {
        // Renewable ticket without renew-till. Illegal and ignored.
        return;
    }

    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(),
                                                (clientAlias != null ?
                                                        clientAlias.getName() : null),
                                                server.toString(),
                                                (serverAlias != null ?
                                                        serverAlias.getName() : null),
                                                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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 7
Source File: KerberosTicket.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 8
Source File: KerberosTicket.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 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 IllegalStateException if this ticket is destroyed
 * @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.getName(),
                                                server.getName(),
                                                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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 9
Source File: KerberosTicket.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 10
Source File: KerberosTicket.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 11
Source File: KerberosTicket.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 12
Source File: KerberosTicket.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 13
Source File: KerberosTicket.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 14
Source File: KerberosTicket.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 (getRenewTill() == null) {
        // Renewable ticket without renew-till. Illegal and ignored.
        return;
    }

    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(),
                                                (clientAlias != null ?
                                                        clientAlias.getName() : null),
                                                server.toString(),
                                                (serverAlias != null ?
                                                        serverAlias.getName() : null),
                                                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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 15
Source File: KerberosTicket.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}
 
Example 16
Source File: KerberosTicket.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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(),
                                    KerberosPrincipal.KRB_NT_SRV_INST),
             krb5Creds.getSessionKey().getBytes(),
             krb5Creds.getSessionKey().getEType(),
             krb5Creds.getFlags(),
             krb5Creds.getAuthTime(),
             krb5Creds.getStartTime(),
             krb5Creds.getEndTime(),
             krb5Creds.getRenewTill(),
             krb5Creds.getClientAddresses());
        destroyed = false;
    }
}