Here you can find the source of kinit(String username, char[] password)
public static LoginContext kinit(String username, char[] password) throws LoginException
//package com.java2s; //License from project: Apache License import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.PasswordCallback; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; public class Main { private static final String LOGIN_MODULE = "KerberosUtil"; // ww w . j av a 2 s . c o m /** * kinit via code */ public static LoginContext kinit(String username, char[] password) throws LoginException { CallbackHandler handler = (callbacks) -> { for (Callback c : callbacks) { if (c instanceof NameCallback) { ((NameCallback) c).setName(username); } if (c instanceof PasswordCallback) { ((PasswordCallback) c).setPassword(password); } } }; LoginContext lc = new LoginContext(LOGIN_MODULE, handler); lc.login(); return lc; } }