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


Java KeyTab.getInstance方法代码示例

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


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

示例1: testCheckTGTAfterLoginFromSubject

import javax.security.auth.kerberos.KeyTab; //导入方法依赖的package包/类
@Test
public void testCheckTGTAfterLoginFromSubject() throws Exception {
  // security on, default is remove default realm
  SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  // Login from a pre-set subject with a keytab
  final Subject subject = new Subject();
  KeyTab keytab = KeyTab.getInstance();
  subject.getPrivateCredentials().add(keytab);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  ugi.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws IOException {
      UserGroupInformation.loginUserFromSubject(subject);
      // this should not throw.
      UserGroupInformation.getLoginUser().checkTGTAndReloginFromKeytab();
      return null;
    }
  });

}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:23,代码来源:TestUserGroupInformation.java

示例2: getTGT

import javax.security.auth.kerberos.KeyTab; //导入方法依赖的package包/类
/**
 * Get a Ticket Granting Ticket (TGT) from Authentication Server (AS) with required keytab file.
 *
 * 1. Create and send AS-REQ
 * 2. Receive KRB ERROR (PRE-AUTH is mandatory in Kerberos v5)
 * 3. Re-send AS-REQ
 * 4. Receive AS-REP
 * 5. Return TGT credentials ticket in Java object
 *
 * @param keytabFileName Path file name to keytab (required already on disk storage, for instance
 *                       /etc/bob.keytab)
 * @param userName user name principal (UPN) (ex: [email protected])
 * @param realm Kerberos domain of the Authentication Server (ex: EXAMPLE.COM)
 * @return TGT credentials
 * @throws KrbException
 * @throws IOException
 *
 * Note: 
 * - For system administrator it is like the command: kinit -kt keytab upn 
 * - [WARNING] dependencies with internal proprietary API and may be removed in a future release
 */
public static Credentials getTGT(String keytabFileName, String userName, String realm)
    throws KrbException, IOException {

  KrbAsReqBuilder builder = null;
  try {

    PrincipalName userPrincipalName = new PrincipalName(userName);
    KeyTab keyTab = KeyTab.getInstance(new File(keytabFileName));
    builder = new KrbAsReqBuilder(userPrincipalName, keyTab);

    PrincipalName tgsPrincipalName = PrincipalName.tgsService(realm, realm);
    builder.setTarget(tgsPrincipalName);

    // see http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/default/src/share/classes/sun/security/krb5/KdcComm.java#l145
    // for default parameters (timeout, max retries ...)
    builder.action();

    Credentials tgtCredentials = builder.getCCreds();
    if (DEBUG) {
      System.out.println(">>>TGT credentials : " +
          ReflectionToStringBuilder.toString(tgtCredentials));
    }
    return tgtCredentials;

  } finally {

    if (builder != null) {
      builder.destroy();
    }

  }

}
 
开发者ID:criteo,项目名称:kerberos-docker,代码行数:55,代码来源:KerberosTicketManager.java

示例3: oldktab

import javax.security.auth.kerberos.KeyTab; //导入方法依赖的package包/类
private static KeyTab oldktab() {
    return KeyTab.getInstance();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:4,代码来源:ServiceCredsCombination.java

示例4: ktab

import javax.security.auth.kerberos.KeyTab; //导入方法依赖的package包/类
static KeyTab ktab(String s) {
    return KeyTab.getInstance(princ(s));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:4,代码来源:ServiceCredsCombination.java


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