本文整理汇总了Java中javax.security.auth.kerberos.KerberosPrincipal.getName方法的典型用法代码示例。如果您正苦于以下问题:Java KerberosPrincipal.getName方法的具体用法?Java KerberosPrincipal.getName怎么用?Java KerberosPrincipal.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.kerberos.KerberosPrincipal
的用法示例。
在下文中一共展示了KerberosPrincipal.getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUGIFromSubject
import javax.security.auth.kerberos.KerberosPrincipal; //导入方法依赖的package包/类
/**
* Create a UserGroupInformation from a Subject with Kerberos principal.
*
* @param user The KerberosPrincipal to use in UGI
*
* @throws IOException if the kerberos login fails
*/
public static UserGroupInformation getUGIFromSubject(Subject subject)
throws IOException {
if (subject == null) {
throw new IOException("Subject must not be null");
}
if (subject.getPrincipals(KerberosPrincipal.class).isEmpty()) {
throw new IOException("Provided Subject must contain a KerberosPrincipal");
}
KerberosPrincipal principal =
subject.getPrincipals(KerberosPrincipal.class).iterator().next();
User ugiUser = new User(principal.getName(),
AuthenticationMethod.KERBEROS, null);
subject.getPrincipals().add(ugiUser);
UserGroupInformation ugi = new UserGroupInformation(subject);
ugi.setLogin(null);
ugi.setAuthenticationMethod(AuthenticationMethod.KERBEROS);
return ugi;
}
示例2: getKerberosTicket
import javax.security.auth.kerberos.KerberosPrincipal; //导入方法依赖的package包/类
private static KerberosTicket getKerberosTicket ( KerberosPrincipal principal, String password, Long expire ) throws Exception {
PrincipalName principalName = new PrincipalName(principal.getName(), PrincipalName.KRB_NT_PRINCIPAL, principal.getRealm());
KrbAsReqBuilder builder = new KrbAsReqBuilder(principalName, password != null ? password.toCharArray() : new char[0]);
if ( expire != null ) {
System.out.println("Request expires " + expire);
KerberosTime till = new KerberosTime(expire);
Field tillF = builder.getClass().getDeclaredField("till");
tillF.setAccessible(true);
tillF.set(builder, till);
}
Credentials creds = builder.action().getCreds();
builder.destroy();
KerberosTicket ticket = Krb5Util.credsToTicket(creds);
System.out.println("Ends " + ticket.getEndTime().getTime());
return ticket;
}