|| command.startsWith("addprinc") || command.startsWith("ank")) { executor = new AddPrincipalCommand(kadmin); } else if (command.startsWith("batch_anks") || command.startsWith("batch")) { executor = new AddPrincipalsCommand(kadmin); } else if (command.startsWith("ktadd") || command.startsWith("xst")) { executor = new KeytabAddCommand(kadmin); } else if (command.startsWith("ktremove") || command.startsWith("ktrem")) { executor = new KeytabRemoveCommand(kadmin); } else if (command.startsWith("delete_principal") || command.startsWith("delprinc")) { executor = new DeletePrincipalCommand(kadmin); } else if (command.startsWith("modify_principal") || command.startsWith("modprinc")) { executor = new ModifyPrincipalCommand(kadmin); } else if (command.startsWith("rename_principal") || command.startsWith("renprinc")) { executor = new RenamePrincipalCommand(kadmin); } else if (command.startsWith("change_password") || command.startsWith("cpw")) { executor = new ChangePasswordCommand(kadmin); } else if (command.startsWith("list_principals") || command.startsWith("listprincs") || command.startsWith("get_principals") || command.startsWith("getprincs") || command.startsWith("List principals")) { executor = new ListPrincipalCommand(kadmin); } else if (command.startsWith("get_principal") || command.startsWith("getprinc")
/** * Get password from console */ private String getPassword(String principal) { String passwordOnce; String passwordTwice; Console console = System.console(); if (console == null) { System.out.println("Couldn't get Console instance, " + "maybe you're running this from within an IDE. " + "Use scanner to read password."); Scanner scanner = new Scanner(System.in, "UTF-8"); passwordOnce = getPassword(scanner, "Please enter new password \"" + principal + "\":"); passwordTwice = getPassword(scanner, "Please re-enter password =\"" + principal + "\":"); } else { passwordOnce = getPassword(console, "Please enter new password \"" + principal + "\":"); passwordTwice = getPassword(console, "Please re-enter password \"" + principal + "\":"); } if (!passwordOnce.equals(passwordTwice)) { System.err.println("change_password: Password mismatch while reading password for \"" + principal + "\"."); return null; } return passwordOnce; }
/** * Get password for the input principal from console */ private String getPassword(String principal) { String passwordOnce; String passwordTwice; Console console = System.console(); if (console == null) { System.out.println("Couldn't get Console instance, " + "maybe you're running this from within an IDE. " + "Use scanner to read password."); Scanner scanner = new Scanner(System.in, "UTF-8"); passwordOnce = getPassword(scanner, "Enter password for principal \"" + principal + "\":"); passwordTwice = getPassword(scanner, "Re-enter password for principal \"" + principal + "\":"); } else { passwordOnce = getPassword(console, "Enter password for principal \"" + principal + "\":"); passwordTwice = getPassword(console, "Re-enter password for principal \"" + principal + "\":"); } if (!passwordOnce.equals(passwordTwice)) { System.err.println("add_principal: Password mismatch while reading password for \"" + principal + "\"."); return null; } return passwordOnce; }
if (cmd.startsWith("add_principal") || cmd.startsWith("addprinc")) { kadminExecutor = new AddPrincipalCommand(kadmin); } else if (cmd.startsWith("delete_principal") || cmd.startsWith("delprinc")) { kadminExecutor = new DeletePrincipalCommand(kadmin); } else if (cmd.startsWith("rename_principal") || cmd.startsWith("renprinc")) { kadminExecutor = new RenamePrincipalCommand(kadmin); } else if (cmd.startsWith("change_password") || cmd.startsWith("cpw")) { kadminExecutor = new ChangePasswordCommand(kadmin); } else if (cmd.startsWith("list_principals") || cmd.startsWith("listprincs")) { kadminExecutor = new ListPrincipalCommand(kadmin); } else if (cmd.startsWith("get_principal") || cmd.startsWith("getprinc")) { kadminExecutor = new GetPrincipalCommand(kadmin); } else if (cmd.startsWith("ktadd") || cmd.startsWith("xst")) { kadminExecutor = new KeytabAddCommand(kadmin); } else if (cmd.startsWith("get_hostroles") || cmd.startsWith("hostroles")) { kadminExecutor.execute(input); } else if (hadminExecutor != null) { hadminExecutor.execute(items);
parseOptions(commands); String principal = commands[commands.length - 1]; deletePrincipal(getKadmin(), principal); } else { String reply; + "Use scanner to read password."); Scanner scanner = new Scanner(System.in, "UTF-8"); reply = getReply(scanner, prompt); } else { reply = getReply(console, prompt); deletePrincipal(getKadmin(), principal); } else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) { System.out.println("Principal \"" + principal + "\" not deleted.");
@Override public void execute(String input) { String[] commands = input.split("\\s+"); if (commands.length < 3 || commands.length > 4) { System.err.println(USAGE); return; } kOptions = ToolUtil.parseOptions(commands, 1, commands.length - 3); if (kOptions == null) { System.err.println(USAGE); return; } oldPrincipalName = commands[commands.length - 2]; newPrincipalName = commands[commands.length - 1]; if (kOptions.contains(KadminOption.FORCE)) { renamePrincipal(getKadmin()); } else { String prompt = "Are you sure want to rename the principal? (yes/no, YES/NO, y/n, Y/N) "; String reply = ToolUtil.getReplay(prompt); if (reply.equals("yes") || reply.equals("YES") || reply.equals("y") || reply.equals("Y")) { renamePrincipal(getKadmin()); } else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) { System.out.println("Principal \"" + oldPrincipalName + "\" not renamed."); } else { System.err.println("Unknown response, fail to rename the principal."); } } }
@Override public void execute(String input) { String[] commands = input.split(" "); if (commands.length < 2) { ToolUtil.printUsage("missing operand!", USAGE); return; } parseOptions(commands); try { getKadmin().modifyPrincipal(principal, kOptions); System.out.println("Principal \"" + principal + "\" modified."); } catch (KrbException e) { System.err.println("Principal \"" + principal + "\" fail to modify. " + e.getMessage()); } }
existNumbers = getKadmin().size(); } catch (KrbException e) { LOG.info("Fail to get the principal size. " + e); addPrincipalForSize(size, existNumbers);
getKadmin().addPrincipal(principal, kOptions); } catch (KrbException e) { System.err.println("Fail to add principal \"" + principal + "\"." + e.getMessage()); password = kOptions.getStringOption(KadminOption.PW); } else { password = getPassword(principal); getKadmin().addPrincipal(principal, password, kOptions); System.out.println("Principal \"" + principal + "\" created."); } catch (KrbException e) {
password = getPassword(principal); if (password == null) { System.out.println("Did not get new password successfully. Please try again"); getKadmin().changePassword(principal, password); System.out.println("Update password success."); } catch (KrbException e) { password = kOptions.getStringOption(KadminOption.PW); try { getKadmin().changePassword(principal, password); System.out.println("Update password success."); } catch (KrbException e) { getKadmin().updateKeys(principal); } catch (KrbException e) { System.err.println("Fail to update key. " + e.getMessage());
private void addPrincipalForSize(int size, int existNumbers) { int i = 0; while (i < size) { try { int temp = i + existNumbers; String principalName = "E" + temp + "@EXAMPLE.COM"; String password = "12"; getKadmin().addPrincipal(principalName, password, kOptions); } catch (KrbException e) { LOG.error("Fail to add principal. " + e); } i++; } System.out.println("Principals created"); } }
@Override public void execute(String input) { String[] commands = input.split("\\s+"); if (commands.length <= 2) { String expression = commands.length == 2 ? commands[1] : null; try { List<String> principalNames = getKadmin().getPrincipals(expression); if (principalNames.size() == 0) { return; } System.out.println("Principals are listed:"); for (String principalName : principalNames) { System.out.println("\t" + principalName); } } catch (KrbException e) { System.err.print("Fail to list principal! " + e.getMessage()); } } else { System.err.println(USAGE); } } }
KrbIdentity identity = null; try { identity = getKadmin().getPrincipal(princName); } catch (KrbException e) { System.err.println("Fail to get principal: " + princName + ". " + e.getMessage());
if (cmd.startsWith("add_principal") || cmd.startsWith("addprinc")) { kadminExecutor = new AddPrincipalCommand(kadmin); } else if (cmd.startsWith("delete_principal") || cmd.startsWith("delprinc")) { kadminExecutor = new DeletePrincipalCommand(kadmin); } else if (cmd.startsWith("rename_principal") || cmd.startsWith("renprinc")) { kadminExecutor = new RenamePrincipalCommand(kadmin); } else if (cmd.startsWith("change_password") || cmd.startsWith("cpw")) { kadminExecutor = new ChangePasswordCommand(kadmin); } else if (cmd.startsWith("list_principals") || cmd.startsWith("listprincs")) { kadminExecutor = new ListPrincipalCommand(kadmin); } else if (cmd.startsWith("get_principal") || cmd.startsWith("getprinc")) { kadminExecutor = new GetPrincipalCommand(kadmin); } else if (cmd.startsWith("ktadd") || cmd.startsWith("xst")) { kadminExecutor = new KeytabAddCommand(kadmin); } else if (cmd.startsWith("get_hostroles") || cmd.startsWith("hostroles")) { kadminExecutor.execute(input); } else if (hadminExecutor != null) { hadminExecutor.execute(items);