Package java.io

Examples of java.io.Console$ConsoleReader


    public VaultInteractiveSession() {
    }

    public void start() {
        Console console = System.console();

        if (console == null) {
            System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
            System.exit(1);
        }

        while (encDir == null || encDir.length() == 0) {
            encDir = console
                    .readLine(SecurityLogger.ROOT_LOGGER.enterEncryptionDirectory() + " ");
        }

        while (keystoreURL == null || keystoreURL.length() == 0) {
            keystoreURL = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreURL() + " ");
        }

        char[] keystorePasswd = getSensitiveValue(SecurityLogger.ROOT_LOGGER.enterKeyStorePassword(), SecurityLogger.ROOT_LOGGER.enterKeyStorePasswordAgain());

        try {
            while (salt == null || salt.length() != 8) {
                salt = console.readLine(SecurityLogger.ROOT_LOGGER.enterSalt() + " ");
            }

            String ic = console.readLine(SecurityLogger.ROOT_LOGGER.enterIterationCount() + " ");
            iterationCount = Integer.parseInt(ic);
            vaultNISession = new VaultSession(keystoreURL, new String(keystorePasswd), encDir, salt, iterationCount);

            while (keystoreAlias == null || keystoreAlias.length() == 0) {
                keystoreAlias = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreAlias() + " ");
            }

            System.out.println(SecurityLogger.ROOT_LOGGER.initializingVault());
            vaultNISession.startVaultSession(keystoreAlias);
            vaultNISession.vaultConfigurationDisplay();
View Full Code Here


                passwordPrompt = SecurityLogger.ROOT_LOGGER.enterYourPassword();
            if (confirmationPrompt == null) {
                confirmationPrompt = SecurityLogger.ROOT_LOGGER.enterYourPasswordAgain();
            }

            Console console = System.console();

            char[] passwd = console.readPassword(passwordPrompt + " ");
            char[] passwd1 = console.readPassword(confirmationPrompt + " ");
            boolean noMatch = !Arrays.equals(passwd, passwd1);
            if (noMatch)
                System.out.println(SecurityLogger.ROOT_LOGGER.passwordsDoNotMatch());
            else {
                System.out.println(SecurityLogger.ROOT_LOGGER.passwordsMatch());
View Full Code Here

    public VaultInteraction(VaultSession vaultSession) {
        this.vaultNISession = vaultSession;
    }

    public void start() {
        Console console = System.console();

        if (console == null) {
            System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
            System.exit(1);
        }

        Scanner in = new Scanner(System.in);
        while (true) {
            String commandStr = SecurityLogger.ROOT_LOGGER.interactionCommandOptions();

            System.out.println(commandStr);
            int choice = in.nextInt();
            switch (choice) {
                case 0:
                    System.out.println(SecurityLogger.ROOT_LOGGER.taskStoreSecuredAttribute());
                    char[] attributeValue = VaultInteractiveSession.getSensitiveValue(SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValue(), SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValueAgain());
                    String vaultBlock = null;

                    while (vaultBlock == null || vaultBlock.length() == 0) {
                        vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
                    }

                    String attributeName = null;

                    while (attributeName == null || attributeName.length() == 0) {
                        attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
                    }
                    try {
                        vaultNISession.addSecuredAttributeWithDisplay(vaultBlock, attributeName, attributeValue);
                    } catch (Exception e) {
                        System.out.println(SecurityLogger.ROOT_LOGGER.problemOcurred() + "\n" + e.getLocalizedMessage());
                    }
                    break;
                case 1:
                    System.out.println(SecurityLogger.ROOT_LOGGER.taskVerifySecuredAttributeExists());
                    try {
                        vaultBlock = null;

                        while (vaultBlock == null || vaultBlock.length() == 0) {
                            vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
                        }

                        attributeName = null;

                        while (attributeName == null || attributeName.length() == 0) {
                            attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
                        }
                        if (!vaultNISession.checkSecuredAttribute(vaultBlock, attributeName)) {
                            System.out.println(SecurityLogger.ROOT_LOGGER.interactiveMessageNoValueStored(VaultSession
                                    .blockAttributeDisplayFormat(vaultBlock, attributeName)));
                        } else {
                            System.out.println(SecurityLogger.ROOT_LOGGER.interactiveMessageValueStored(VaultSession
                                    .blockAttributeDisplayFormat(vaultBlock, attributeName)));
                        }
                    } catch (Exception e) {
                        System.out.println(SecurityLogger.ROOT_LOGGER.problemOcurred() + "\n" + e.getLocalizedMessage());
                    }
                    break;
                case 2:
                    System.out.println(SecurityLogger.ROOT_LOGGER.taskRemoveSecuredAttribute());
                    try {
                        vaultBlock = null;

                        while (vaultBlock == null || vaultBlock.length() == 0) {
                            vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
                        }

                        attributeName = null;

                        while (attributeName == null || attributeName.length() == 0) {
                            attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
                        }
                        if (!vaultNISession.removeSecuredAttribute(vaultBlock, attributeName)) {
                            System.out.println(SecurityLogger.ROOT_LOGGER.messageAttributeNotRemoved(VaultSession
                                    .blockAttributeDisplayFormat(vaultBlock, attributeName)));
                        } else {
View Full Code Here

         * we treat it as a required option and prompt for it
         * if possible.
         */
        if (programOpts.getUser() == null) {
            // prompt for it (if interactive)
            Console cons = System.console();
            if (cons != null && programOpts.isInteractive()) {
                cons.printf("%s", strings.get("AdminUserDefaultPrompt",
                    SystemPropertyConstants.DEFAULT_ADMIN_USER));
                String val = cons.readLine();
                if (ok(val))
                    programOpts.setUser(val);
                else
                    programOpts.setUser(
                                    SystemPropertyConstants.DEFAULT_ADMIN_USER);
View Full Code Here

 
  @Override
  public String promptForPassword(String message)
  throws PrompterException
  {
    Console console = System.console();
    if (console == null)
      throw new PrompterException("Console not available.");
   
    showMessage(message);
   
    char[] pass = console.readPassword();
    if (pass == null)
      return(null);
    else
      return(new String(pass));
  }
View Full Code Here

    return getInstance(false);
  }

  /** Get a UI instance, possibly forcing batch mode. */
  public static ConsoleUI getInstance(final boolean batchMode) {
    Console console = batchMode ? null : System.console();
    return console != null ? new Interactive(console) : new Batch();
  }
View Full Code Here

    }

    password = commandLine.getOptionValue(ConfigurableOptions.PASSWORD);

    if (password == null) {
      Console console = System.console();
      password = String.valueOf(console.readPassword(String.format("Password for %s: ", username)));
    }

    if (commandLine.hasOption(ConfigurableOptions.FILE)) {
      filePath = commandLine.getOptionValue(ConfigurableOptions.FILE);
    } else {
View Full Code Here

         *
         * The next prompted-for value will be the admin password, if required.
         */
        if (programOpts.getUser() == null && !noPassword) {
            // prompt for it (if interactive)
            Console cons = System.console();
            if (cons != null && programOpts.isInteractive()) {
                cons.printf("%s", strings.get("AdminUserRequiredPrompt",
                        SystemPropertyConstants.DEFAULT_ADMIN_USER));
                String val = cons.readLine();
                if (ok(val)) {
                    programOpts.setUser(val);
                    if (adminPassword == null) {
                        adminPassword = getAdminPassword();
                    }
View Full Code Here

        if (pd != null) {
          if (pd.getParameter().password()) {
            //
            // Password option, use the Console to retrieve the password
            //
            Console console = System.console();
            if (console == null) {
              throw new ParameterException("No console is available to get parameter " + a);
            }
            System.out.print("Value for " + a + " (" + pd.getDescription() + "):");
            char[] password = console.readPassword();
            pd.addValue(new String(password));
          } else {
            //
            // Regular option
            //
View Full Code Here

        log.debug("Using OAuth2 access token authentication");
      }
      client.setOAuth2Token(password);
      return client;
    }else if(!StringUtils.isEmpty(userName) && System.console() != null){
      Console console = System.console();
      while(StringUtils.isEmpty(password)){
        password = new String(console.readPassword("Input the password for '" + userName + "': "));
      }
      client.setCredentials(userName, password);
      return client;
    }
View Full Code Here

TOP

Related Classes of java.io.Console$ConsoleReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.