private static void requestTicket(String principal, KOptions ktOptions) throws Exception { ktOptions.add(KinitOption.CLIENT_PRINCIPAL, principal); // If not request tickets by keytab than by password. if (!ktOptions.contains(KinitOption.USE_KEYTAB)) { ktOptions.add(KinitOption.USE_PASSWD); String password = getPassword(principal); ktOptions.add(KinitOption.USER_PASSWD, password); } KrbClient krbClient = getClient(); TgtTicket tgt = krbClient.requestTgtWithOptions(ToolUtil.convertOptions(ktOptions)); if (tgt == null) { System.err.println("Requesting TGT failed"); return; } File ccacheFile; if (ktOptions.contains(KrbOption.KRB5_CACHE)) { String ccacheName = ktOptions.getStringOption(KrbOption.KRB5_CACHE); ccacheFile = new File(ccacheName); } else { String ccacheName = principal.replaceAll("/", "_"); ccacheName = "krb5_" + ccacheName + ".cc"; ccacheFile = new File(SysUtil.getTempDir(), ccacheName); } krbClient.storeTicket(tgt, ccacheFile); System.out.println( "Successfully requested and stored ticket in " + ccacheFile.getAbsolutePath()); }
/** Init the client. */ private static KrbClient getClient() throws KrbException { KrbClient krbClient = new KrbClient(); krbClient.init(); return krbClient; }