Java Code Examples for sun.security.krb5.internal.ccache.CredentialsCache#getDefaultCreds()

The following examples show how to use sun.security.krb5.internal.ccache.CredentialsCache#getDefaultCreds() . 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: Credentials.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 2
Source File: Credentials.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 3
Source File: Credentials.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @return the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 4
Source File: Credentials.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 5
Source File: Credentials.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 6
Source File: Credentials.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 7
Source File: Credentials.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 8
Source File: Credentials.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
Example 9
Source File: Credentials.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a TGT for the given client principal from a ticket cache.
 *
 * @param princ the client principal. A value of null means that the
 * default principal name in the credentials cache will be used.
 * @param ticketCache the path to the tickets file. A value
 * of null will be accepted to indicate that the default
 * path should be searched
 * @returns the TGT credentials or null if none were found. If the tgt
 * expired, it is the responsibility of the caller to determine this.
 */
public static Credentials acquireTGTFromCache(PrincipalName princ,
                                              String ticketCache)
    throws KrbException, IOException {

    if (ticketCache == null) {
        // The default ticket cache on Windows and Mac is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
                os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
            Credentials creds = acquireDefaultCreds();
            if (creds == null) {
                if (DEBUG) {
                    System.out.println(">>> Found no TGT's in LSA");
                }
                return null;
            }
            if (princ != null) {
                if (creds.getClient().equals(princ)) {
                    if (DEBUG) {
                        System.out.println(">>> Obtained TGT from LSA: "
                                           + creds);
                    }
                    return creds;
                } else {
                    if (DEBUG) {
                        System.out.println(">>> LSA contains TGT for "
                                           + creds.getClient()
                                           + " not "
                                           + princ);
                    }
                    return null;
                }
            } else {
                if (DEBUG) {
                    System.out.println(">>> Obtained TGT from LSA: "
                                       + creds);
                }
                return creds;
            }
        }
    }

    /*
     * Returns the appropriate cache. If ticketCache is null, it is the
     * default cache otherwise it is the cache filename contained in it.
     */
    CredentialsCache ccache =
        CredentialsCache.getInstance(princ, ticketCache);

    if (ccache == null) {
        return null;
    }

    sun.security.krb5.internal.ccache.Credentials tgtCred  =
        ccache.getDefaultCreds();

    if (tgtCred == null) {
        return null;
    }

    if (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}