当前位置: 首页>>代码示例>>Java>>正文


Java CredentialsCache.getDefaultCreds方法代码示例

本文整理汇总了Java中sun.security.krb5.internal.ccache.CredentialsCache.getDefaultCreds方法的典型用法代码示例。如果您正苦于以下问题:Java CredentialsCache.getDefaultCreds方法的具体用法?Java CredentialsCache.getDefaultCreds怎么用?Java CredentialsCache.getDefaultCreds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.krb5.internal.ccache.CredentialsCache的用法示例。


在下文中一共展示了CredentialsCache.getDefaultCreds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: acquireTGTFromCache

import sun.security.krb5.internal.ccache.CredentialsCache; //导入方法依赖的package包/类
/**
 * 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 is not a file.
        String os = java.security.AccessController.doPrivileged(
                    new sun.security.action.GetPropertyAction("os.name"));
        if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS")) {
            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 (EType.isSupported(tgtCred.getEType())) {
        return tgtCred.setKrbCreds();
    } else {
        if (DEBUG) {
            System.out.println(
                ">>> unsupported key type found the default TGT: " +
                tgtCred.getEType());
        }
        return null;
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:78,代码来源:Credentials.java


注:本文中的sun.security.krb5.internal.ccache.CredentialsCache.getDefaultCreds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。