Example usage for java.security KeyException getClass

List of usage examples for java.security KeyException getClass

Introduction

In this page you can find the example usage for java.security KeyException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.ow2.proactive.resourcemanager.utils.console.ResourceManagerController.java

public void load(String[] args) {

    Options options = new Options();

    Option help = new Option("h", "help", false, "Display this help");
    help.setRequired(false);//  ww w . j a  va2s  .  c o m
    options.addOption(help);

    Option username = new Option("l", "login", true, "The username to join the Resource Manager");
    username.setArgName("login");
    username.setArgs(1);
    username.setRequired(false);
    options.addOption(username);

    Option rmURL = new Option("u", "rmURL", true, "The Resource manager URL (default " + RM_DEFAULT_URL + ")");
    rmURL.setArgName("rmURL");
    rmURL.setArgs(1);
    rmURL.setRequired(false);
    options.addOption(rmURL);

    Option visual = new Option("g", "gui", false, "Start the console in a graphical view");
    rmURL.setRequired(false);
    options.addOption(visual);

    addCommandLineOptions(options);

    boolean displayHelp = false;

    try {
        String pwdMsg = null;

        Parser parser = new GnuParser();
        cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            displayHelp = true;
        } else {
            if (cmd.hasOption("environment")) {
                model.setInitEnv(cmd.getOptionValue("environment"));
            }
            String url;
            if (cmd.hasOption("u")) {
                url = cmd.getOptionValue("u");
            } else {
                url = RM_DEFAULT_URL;
            }

            logger.info("Connecting to the RM on " + url);
            auth = RMConnection.join(url);
            logger.info("\t-> Connection established on " + url);

            if (cmd.hasOption("l")) {
                user = cmd.getOptionValue("l");
            }
            if (cmd.hasOption("credentials")) {
                if (cmd.getOptionValues("credentials").length == 1) {
                    System.setProperty(Credentials.credentialsPathProperty, cmd.getOptionValue("credentials"));
                }
                try {
                    this.credentials = Credentials.getCredentials();
                } catch (KeyException e) {
                    logger.error("Could not retreive credentials... Try to adjust the System property: "
                            + Credentials.credentialsPathProperty);
                    throw e;
                }
            } else {
                ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out));
                if (cmd.hasOption("l")) {
                    pwdMsg = user + "'s password: ";
                } else {
                    user = console.readLine("login: ");
                    pwdMsg = "password: ";
                }

                //ask password to User
                try {
                    console.setDefaultPrompt(pwdMsg);
                    pwd = console.readLine('*');
                } catch (IOException ioe) {
                    logger.error("" + ioe);
                    logger.debug("", ioe);
                }

                PublicKey pubKey = null;
                try {
                    // first attempt at getting the pubkey : ask the RM
                    RMAuthentication auth = RMConnection.join(url);
                    pubKey = auth.getPublicKey();
                    logger.info("Retrieved public key from Resource Manager at " + url);
                } catch (Exception e) {
                    try {
                        // second attempt : try default location
                        pubKey = Credentials.getPublicKey(Credentials.getPubKeyPath());
                        logger.info("Using public key at " + Credentials.getPubKeyPath());
                    } catch (Exception exc) {
                        logger.error(
                                "Could not find a public key. Contact the administrator of the Resource Manager.");
                        logger.debug("", exc);
                        System.exit(1);
                    }
                }
                try {
                    this.credentials = Credentials.createCredentials(
                            new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd), pubKey);
                } catch (KeyException e) {
                    logger.error("Could not create credentials... " + e);
                    throw e;
                }
            }

            //connect to the scheduler
            connect();
            //connect JMX service
            connectJMXClient();
            //start the command line or the interactive mode
            start();

        }
    } catch (MissingArgumentException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (MissingOptionException e) {
        logger.error("Missing option: " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (UnrecognizedOptionException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (AlreadySelectedException e) {
        logger.error(e.getClass().getSimpleName() + " : " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (ParseException e) {
        logger.debug("", e);
        displayHelp = true;
    } catch (RMException e) {
        logger.error(
                "Error at connection : " + e.getMessage() + newline + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(2);
    } catch (LoginException e) {
        logger.error(e.getMessage() + newline + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(3);
    } catch (Exception e) {
        logger.error(
                "An error has occurred : " + e.getMessage() + newline + "Shutdown the controller." + newline,
                e);
        logger.debug("", e);
        System.exit(4);
    }

    if (displayHelp) {
        logger.info("");
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(160);
        String note = newline + "NOTE : if no " + control
                + " command is specified, the controller will start in interactive mode.";
        hf.printHelp(commandName + shellExtension(), "", options, note, true);
        System.exit(5);
    }

    // if execution reaches this point this means it must exit
    System.exit(0);
}

From source file:org.ow2.proactive.scheduler.util.console.SchedulerController.java

public void load(String[] args) {
    Options options = new Options();

    Option help = new Option("h", "help", false, "Display this help");
    help.setRequired(false);//w  w  w.  jav  a2 s .com
    options.addOption(help);

    Option username = new Option("l", "login", true, "The username to join the Scheduler");
    username.setArgName("login");
    username.setArgs(1);
    username.setRequired(false);
    options.addOption(username);

    Option schedulerURL = new Option("u", "url", true,
            "The scheduler URL (default " + SCHEDULER_DEFAULT_URL + ")");
    schedulerURL.setArgName("schedulerURL");
    schedulerURL.setRequired(false);
    options.addOption(schedulerURL);

    Option keyfile = new Option("k", "key", true, "(Optional) The path to a private SSH key");
    keyfile.setArgName("sshkeyFilePath");
    keyfile.setArgs(1);
    keyfile.setRequired(false);
    options.addOption(keyfile);

    addCommandLineOptions(options);

    boolean displayHelp = false;

    try {
        String pwdMsg = null;

        Parser parser = new GnuParser();
        cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            displayHelp = true;
        } else {

            if (cmd.hasOption("env")) {
                model.setInitEnv(cmd.getOptionValue("env"));
            }
            String url;
            if (cmd.hasOption("url")) {
                url = cmd.getOptionValue("url");
            } else {
                url = SCHEDULER_DEFAULT_URL;
            }
            logger.info("Trying to connect Scheduler on " + url);
            auth = SchedulerConnection.join(url);
            logger.info("\t-> Connection established on " + url);

            logger.info(newline + "Connecting client to the Scheduler");

            if (cmd.hasOption("login")) {
                user = cmd.getOptionValue("login");
            }

            if (cmd.hasOption("credentials")) {
                if (cmd.getOptionValue("credentials") != null) {
                    System.setProperty(Credentials.credentialsPathProperty, cmd.getOptionValue("credentials"));
                }
                try {
                    this.credentials = Credentials.getCredentials();
                } catch (KeyException e) {
                    logger.error("Could not retreive credentials... Try to adjust the System property: "
                            + Credentials.credentialsPathProperty + " or use the -c option.");
                    throw e;
                }
            } else {
                ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out));
                if (cmd.hasOption("login")) {
                    pwdMsg = user + "'s password: ";
                } else {
                    user = console.readLine("login: ");
                    pwdMsg = "password: ";
                }

                //ask password to User
                try {
                    console.setDefaultPrompt(pwdMsg);
                    pwd = console.readLine('*');
                } catch (IOException ioe) {
                    logger.error("" + ioe);
                    logger.debug("", ioe);
                }

                PublicKey pubKey = null;
                try {
                    // first attempt at getting the pubkey : ask the scheduler
                    SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
                    pubKey = auth.getPublicKey();
                    logger.info("Retrieved public key from Scheduler at " + url);
                } catch (Exception e) {
                    try {
                        // second attempt : try default location
                        pubKey = Credentials.getPublicKey(Credentials.getPubKeyPath());
                        logger.info("Using public key at " + Credentials.getPubKeyPath());
                    } catch (Exception exc) {
                        logger.error(
                                "Could not find a public key. Contact the administrator of the Scheduler.");
                        logger.debug("", exc);
                        System.exit(7);
                    }
                }
                try {
                    if (cmd.hasOption("key")) {
                        byte[] keyfileContent = FileToBytesConverter
                                .convertFileToByteArray(new File(cmd.getOptionValue("key")));
                        this.credentials = Credentials.createCredentials(new CredData(CredData.parseLogin(user),
                                CredData.parseDomain(user), pwd, keyfileContent), pubKey);
                    } else {
                        this.credentials = Credentials.createCredentials(
                                new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd),
                                pubKey);
                    }
                } catch (FileNotFoundException fnfe) {
                    logger.error("SSH keyfile not found : '" + cmd.getOptionValue("key") + "'");
                    logger.debug("", fnfe);
                    System.exit(8);
                } catch (Exception e) {
                    logger.error("Could not create credentials... " + e);
                    throw e;
                }
            }

            //connect to the scheduler
            connect();
            //connect JMX service
            connectJMXClient();
            //start the command line or the interactive mode
            start();
        }
    } catch (MissingArgumentException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (MissingOptionException e) {
        logger.error("Missing option: " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (UnrecognizedOptionException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (AlreadySelectedException e) {
        logger.error(e.getClass().getSimpleName() + " : " + e.getLocalizedMessage());
        logger.debug("", e);
        displayHelp = true;
    } catch (ParseException e) {
        displayHelp = true;
    } catch (LoginException e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(3);
    } catch (SchedulerException e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline);
        logger.debug("", e);
        System.exit(4);
    } catch (Exception e) {
        logger.error(getMessages(e) + "Shutdown the controller." + newline, e);
        logger.debug("", e);
        System.exit(5);
    }

    if (displayHelp) {
        logger.info("");
        HelpFormatter hf = new HelpFormatter();
        hf.setWidth(135);
        String note = newline + "NOTE : if no " + control
                + "command is specified, the controller will start in interactive mode.";
        hf.printHelp(getCommandName() + Tools.shellExtension(), "", options, note, true);
        System.exit(6);
    }

    // if execution reaches this point this means it must exit
    System.exit(0);
}