List of usage examples for java.lang System console
public static Console console()
From source file:nl.paston.bonita.importfile.Main.java
protected static String getConsoleInput(String displayText, String defaultValue, CommandLine cmd, String optionName) {/* www . j a v a2 s. c om*/ if (cmd != null && cmd.hasOption(optionName)) { return cmd.getOptionValue(optionName); } else { Console console = System.console(); String consoleInput = null; if (console != null) { consoleInput = console.readLine(displayText + " (" + defaultValue + "): "); if (!consoleInput.trim().isEmpty()) { return consoleInput.trim(); } else { return defaultValue; } } } return defaultValue; }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private void menu_AddReplicationNode(ReplicationConfiguration replicationNodes, JUDDIApiPortType juddiApiService, String authtoken) throws Exception { if (replicationNodes.getCommunicationGraph() == null) { replicationNodes.setCommunicationGraph(new CommunicationGraph()); }// w w w . ja va2 s. c o m Operator op = new Operator(); System.out.println( "The Operator Node id should be the UDDI Node ID of the new node to replicate with. It should also match the root business key in" + " the new registry."); System.out.print("Operator Node id: "); op.setOperatorNodeID(System.console().readLine().trim()); System.out.print("Replication URL: "); op.setSoapReplicationURL(System.console().readLine().trim()); op.setOperatorStatus(OperatorStatusType.NEW); System.out.println("The replication node requires at least one point of contact"); System.out.print("Number of contacts: "); int index = Integer.parseInt(System.console().readLine()); for (int i = 0; i < index; i++) { System.out.println("_______________________"); System.out.println("Info for contact # " + (i + 1)); op.getContact().add(getContactInfo()); } System.out.println("_______________________"); System.out.println("Current Operator:"); System.out.println("_______________________"); JAXB.marshal(op, System.out); System.out.print("Confirm adding? (y/n) :"); if (System.console().readLine().trim().equalsIgnoreCase("y")) { replicationNodes.getOperator().add(op); replicationNodes.getCommunicationGraph().getNode().add(op.getOperatorNodeID()); } }
From source file:org.apache.maven.cli.CopyOfMavenCli.java
private void encryption(CliRequest cliRequest) throws Exception { if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_MASTER_PASSWORD); if (passwd == null) { Console cons;//from w w w .j av a2 s. c om char[] password; if ((cons = System.console()) != null && (password = cons.readPassword("Master password: ")) != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); } } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); System.out .println(cipher.encryptAndDecorate(passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION)); throw new ExitException(0); } else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_PASSWORD); if (passwd == null) { Console cons; char[] password; if ((cons = System.console()) != null && (password = cons.readPassword("Password: ")) != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); } } String configurationFile = dispatcher.getConfigurationFile(); if (configurationFile.startsWith("~")) { configurationFile = System.getProperty("user.home") + configurationFile.substring(1); } String file = System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile); String master = null; SettingsSecurity sec = SecUtil.read(file, true); if (sec != null) { master = sec.getMaster(); } if (master == null) { throw new IllegalStateException("Master password is not set in the setting security file: " + file); } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); String masterPasswd = cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION); System.out.println(cipher.encryptAndDecorate(passwd, masterPasswd)); throw new ExitException(0); } }
From source file:com.trsst.Command.java
public int doPull(Client client, CommandLine commands, LinkedList<String> arguments, PrintStream out) { if (arguments.size() < 1) { printPullUsage();/* w w w. j av a 2 s .co m*/ return 127; // "command not found" } // decryption option String id = commands.getOptionValue("d"); PrivateKey[] decryptionKeys = null; if (id != null) { // obtain password id = Common.toFeedIdString(id); char[] password = null; String pass = commands.getOptionValue("p"); if (pass != null) { password = pass.toCharArray(); } else { try { Console console = System.console(); if (console != null) { password = console.readPassword("Password: "); } else { log.info("No console detected for password input."); } } catch (Throwable t) { log.error("Unexpected error while reading password", t); } } if (password == null) { log.error("Password is required to decrypt."); return 127; // "command not found" } if (password.length < 6) { System.err.println("Password must be at least six characters in length."); return 127; // "command not found" } // obtain keys KeyPair signingKeys = null; KeyPair encryptionKeys = null; String keyPath = commands.getOptionValue("k"); File keyFile; if (keyPath != null) { keyFile = new File(keyPath, id + Common.KEY_EXTENSION); } else { keyFile = new File(Common.getClientRoot(), id + Common.KEY_EXTENSION); } if (keyFile.exists()) { System.err.println("Using existing account id: " + id); } else { System.err.println("Cannot locate keys for account id: " + id); return 78; // "configuration error" } signingKeys = readSigningKeyPair(id, keyFile, password); if (signingKeys != null) { encryptionKeys = readEncryptionKeyPair(id, keyFile, password); if (encryptionKeys == null) { decryptionKeys = new PrivateKey[] { signingKeys.getPrivate() }; } else { decryptionKeys = new PrivateKey[] { encryptionKeys.getPrivate(), signingKeys.getPrivate() }; } } } List<String> ids = new LinkedList<String>(); for (String arg : arguments) { ids.add(arg); } for (String feedId : ids) { try { Object feed; if (decryptionKeys != null) { feed = client.pull(feedId, decryptionKeys); } else { feed = client.pull(feedId); } if (feed != null) { if (format) { out.println(Common.formatXML(feed.toString())); } else { out.println(feed.toString()); } } else { System.err.println("Could not fetch: " + feedId + " : " + client); } } catch (Throwable t) { log.error("Unexpected error on pull: " + feedId + " : " + client, t); } } return 0; // "OK" }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private Contact getContactInfo() { Contact c = new Contact(); System.out.print("Use Type (i.e. primary): "); c.setUseType(System.console().readLine().trim()); if (c.getUseType().trim().equalsIgnoreCase("")) { c.setUseType("primary"); }/*from w w w .j av a 2s . c o m*/ c.getPersonName().add(getPersonName()); while (true) { System.out.println("Thus far:"); JAXB.marshal(c, System.out); System.out.println("Options:"); System.out.println("\t1) Add PersonName"); System.out.println("\t2) Add Email address"); System.out.println("\t3) Add Phone number"); System.out.println("\t4) Add Description"); System.out.println("\t<enter> Finish and return"); System.out.print("> "); String input = System.console().readLine(); if (input.trim().equalsIgnoreCase("")) { break; } else if (input.trim().equalsIgnoreCase("1")) { c.getPersonName().add(getPersonName()); } else if (input.trim().equalsIgnoreCase("2")) { c.getEmail().add(getEmail()); } else if (input.trim().equalsIgnoreCase("3")) { c.getPhone().add(getPhoneNumber()); } else if (input.trim().equalsIgnoreCase("4")) { c.getDescription().add(getDescription()); } } return c; }
From source file:org.apache.shiro.tools.hasher.Hasher.java
private static char[] readPassword(boolean confirm) { if (!JavaEnvironment.isAtLeastVersion16()) { String msg = "Password hashing (prompt without echo) uses the java.io.Console to read passwords " + "safely. This is only available on Java 1.6 platforms and later."; throw new IllegalArgumentException(msg); }/* w w w . j av a 2 s . c o m*/ java.io.Console console = System.console(); if (console == null) { throw new IllegalStateException( "java.io.Console is not available on the current JVM. Cannot read passwords."); } char[] first = console.readPassword("%s", "Password to hash: "); if (first == null || first.length == 0) { throw new IllegalArgumentException("No password specified."); } if (confirm) { char[] second = console.readPassword("%s", "Password to hash (confirm): "); if (!Arrays.equals(first, second)) { String msg = "Password entries do not match."; throw new IllegalArgumentException(msg); } } return first; }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private PersonName getPersonName() { PersonName pn = new PersonName(); System.out.print("Name: "); pn.setValue(System.console().readLine().trim()); System.out.print("Language (en): "); pn.setLang(System.console().readLine().trim()); if (pn.getLang().equalsIgnoreCase("")) { pn.setLang("en"); }//from www .j a v a2 s . c om return pn; }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private Email getEmail() { Email pn = new Email(); System.out.print("Email address Value: "); pn.setValue(System.console().readLine().trim()); System.out.print("Use type (i.e. primary): "); pn.setUseType(System.console().readLine().trim()); return pn;/*from www. j av a 2s . c o m*/ }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private Phone getPhoneNumber() { Phone pn = new Phone(); System.out.print("Phone Value: "); pn.setValue(System.console().readLine().trim()); System.out.print("Use type (i.e. primary): "); pn.setUseType(System.console().readLine().trim()); return pn;// ww w . ja v a2 s.com }
From source file:org.apache.juddi.samples.JuddiAdminService.java
private Description getDescription() { Description pn = new Description(); System.out.print("Value: "); pn.setValue(System.console().readLine().trim()); System.out.print("Language (en): "); pn.setLang(System.console().readLine().trim()); if (pn.getLang().equalsIgnoreCase("")) { pn.setLang("en"); }/* ww w .java 2 s . c om*/ return pn; }