Package org.jboss.as.cli

Examples of org.jboss.as.cli.CliInitializationException


                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
                    keyManagerFactory.init(theKeyStore, keyStorePassword);
                    keyManagers = keyManagerFactory.getKeyManagers();
                } catch (IOException e) {
                    throw new CliInitializationException(e);
                } catch (GeneralSecurityException e) {
                    throw new CliInitializationException(e);
                } finally {
                    StreamUtils.safeClose(fis);
                }

            }

            trustStore = sslConfig.getTrustStore();
            trustStorePassword = sslConfig.getTrustStorePassword();
            modifyTrustStore = sslConfig.isModifyTrustStore();
        }

        if (trustStore == null) {
            final String userHome = SecurityActions.getSystemProperty("user.home");
            File trustStoreFile = new File(userHome, ".jboss-cli.truststore");
            trustStore = trustStoreFile.getAbsolutePath();
            trustStorePassword = "cli_truststore"; // Risk of modification but no private keys to be stored in the truststore.
        }

        trustManager = new LazyDelagatingTrustManager(trustStore, trustStorePassword, modifyTrustStore);
        trustManagers = new TrustManager[] { trustManager };

        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, null);

            this.sslContext = sslContext;
        } catch (GeneralSecurityException e) {
            throw new CliInitializationException(e);
        }
    }
View Full Code Here


        final CommandContext cmdCtx = CommandContextFactory.getInstance().newCommandContext(defaultHost, defaultPort, username, password, initConsole);
        if(connect) {
            try {
                cmdCtx.connectController();
            } catch (CommandLineException e) {
                throw new CliInitializationException("Failed to connect to the controller", e);
            }
        }
        return cmdCtx;
    }
View Full Code Here

        return parse(ctx, new File(jbossHome + File.separatorChar + "bin", "jboss-cli.xml"));
    }

    static CliConfig parse(final CommandContext ctx, File f) throws CliInitializationException {
        if(f == null) {
            throw new CliInitializationException("The file argument is null.");
        }
        if(!f.exists()) {
            //throw new CliInitializationException(f.getAbsolutePath() + " doesn't exist.");
            return new CliConfigImpl();
        }

        CliConfigImpl config = new CliConfigImpl();

        BufferedInputStream input = null;
        try {
            final XMLMapper mapper = XMLMapper.Factory.create();
            mapper.registerRootElement(new QName(NS, JBOSS_CLI), new XMLElementReader<CliConfigImpl>(){
                @Override
                public void readElement(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    boolean jbossCliEnded = false;
                    while (reader.hasNext() && jbossCliEnded == false) {
                        int tag = reader.nextTag();
                        if(tag == XMLStreamConstants.START_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if(localName.equals(DEFAULT_CONTROLLER)) {
                                readDefaultController(reader, config);
                            } else if(localName.equals(HISTORY)) {
                                readHistory(reader, config);
                            } else if (localName.equals("ssl")) {
                                SslConfig sslConfig = new SslConfig();
                                readSSLElement(reader, sslConfig);
                                config.sslConfig = sslConfig;
                            } else {
                                throw new XMLStreamException("Unexpected element: " + localName);
                            }
                        } else if(tag == XMLStreamConstants.END_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if (localName.equals(JBOSS_CLI)) {
                                jbossCliEnded = true;
                            }
                        }
                    }
                }

                private void readDefaultController(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        final String resolved = resolveString(reader.getElementText());
                        if (HOST.equals(localName)) {
                            config.defaultControllerHost = resolved;
                        } else if (PORT.equals(localName)) {
                            try {
                                config.defaultControllerPort = Integer.parseInt(resolved);
                            } catch(NumberFormatException e) {
                                throw new XMLStreamException("Failed to parse " + DEFAULT_CONTROLLER + " " + PORT + " value '" + resolved + "'", e);
                            }
                        } else {
                            throw new XMLStreamException("Unexpected child of " + DEFAULT_CONTROLLER + ": " + localName);
                        }
                    }
                }

                private void readHistory(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        final String resolved = resolveString(reader.getElementText());
                        if (ENABLED.equals(localName)) {
                            config.historyEnabled = Boolean.parseBoolean(resolved);
                        } else if (FILE_NAME.equals(localName)) {
                            config.historyFileName = resolved;
                        } else if (FILE_DIR.equals(localName)) {
                            config.historyFileDir = resolved;
                        } else if (MAX_SIZE.equals(localName)) {
                            try {
                                config.historyMaxSize = Integer.parseInt(resolved);
                            } catch(NumberFormatException e) {
                                throw new XMLStreamException("Failed to parse " + HISTORY + " " + MAX_SIZE + " value '" + resolved + "'", e);
                            }
                        } else {
                            throw new XMLStreamException("Unexpected child of " + DEFAULT_CONTROLLER + ": " + localName);
                        }
                    }
                }

                public void readSSLElement(XMLExtendedStreamReader reader, SslConfig config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        if ("keyStore".equals(localName)) {
                            config.setKeyStore(reader.getElementText());
                        } else if ("keyStorePassword".equals(localName)) {
                            config.setKeyStorePassword(reader.getElementText());
                        } else if ("trustStore".equals(localName)) {
                            config.setTrustStore(reader.getElementText());
                        } else if ("trustStorePassword".equals(localName)) {
                            config.setTrustStorePassword(reader.getElementText());
                        } else if ("modifyTrustStore".equals(localName)) {
                            config.setModifyTrustStore(Boolean.getBoolean(reader.getElementText()));
                        }
                    }
                }
            });

            FileInputStream is = new FileInputStream(f);
            input = new BufferedInputStream(is);
            XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
            mapper.parseDocument(config, streamReader);
            streamReader.close();
        } catch(Throwable t) {
            throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
        } finally {
            StreamUtils.safeClose(input);
        }
        return config;
    }
View Full Code Here

                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
                    keyManagerFactory.init(theKeyStore, keyStorePassword);
                    keyManagers = keyManagerFactory.getKeyManagers();
                } catch (IOException e) {
                    throw new CliInitializationException(e);
                } catch (GeneralSecurityException e) {
                    throw new CliInitializationException(e);
                } finally {
                    StreamUtils.safeClose(fis);
                }

            }

            trustStore = sslConfig.getTrustStore();
            trustStorePassword = sslConfig.getTrustStorePassword();
            modifyTrustStore = sslConfig.isModifyTrustStore();
        }

        if (trustStore == null) {
            final String userHome = SecurityActions.getSystemProperty("user.home");
            File trustStoreFile = new File(userHome, ".jboss-cli.truststore");
            trustStore = trustStoreFile.getAbsolutePath();
            trustStorePassword = "cli_truststore"; // Risk of modification but no private keys to be stored in the truststore.
        }

        trustManager = new LazyDelagatingTrustManager(trustStore, trustStorePassword, modifyTrustStore);
        trustManagers = new TrustManager[] { trustManager };

        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, null);

            this.sslContext = sslContext;
        } catch (GeneralSecurityException e) {
            throw new CliInitializationException(e);
        }
    }
View Full Code Here

        return parse(ctx, new File(jbossHome + File.separatorChar + "bin", "jboss-cli.xml"));
    }

    static CliConfig parse(final CommandContext ctx, File f) throws CliInitializationException {
        if(f == null) {
            throw new CliInitializationException("The file argument is null.");
        }
        if(!f.exists()) {
            //throw new CliInitializationException(f.getAbsolutePath() + " doesn't exist.");
            return new CliConfigImpl();
        }

        CliConfigImpl config = new CliConfigImpl();

        BufferedInputStream input = null;
        try {
            final XMLMapper mapper = XMLMapper.Factory.create();
            mapper.registerRootElement(new QName("urn:jboss:cli:1.0", "jboss-cli"), new XMLElementReader<CliConfigImpl>(){
                @Override
                public void readElement(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {

                    boolean jbossCliEnded = false;
                    while (reader.hasNext() && jbossCliEnded == false) {
                        int tag = reader.nextTag();
                        if(tag == XMLStreamConstants.START_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if (localName.equals("ssl")) {
                                SslConfig sslConfig = new SslConfig();
                                readSSLElement(reader, sslConfig);
                                config.sslConfig = sslConfig;
                            }
                        } else if(tag == XMLStreamConstants.END_ELEMENT) {
                            final String localName = reader.getLocalName();
                            if (localName.equals("jboss-cli")) {
                                jbossCliEnded = true;
                            }
                        }
                    }
                }

                public void readSSLElement(XMLExtendedStreamReader reader, SslConfig config) throws XMLStreamException {
                    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                        final String localName = reader.getLocalName();
                        if ("keyStore".equals(localName)) {
                            config.setKeyStore(reader.getElementText());
                        } else if ("keyStorePassword".equals(localName)) {
                            config.setKeyStorePassword(reader.getElementText());
                        } else if ("trustStore".equals(localName)) {
                            config.setTrustStore(reader.getElementText());
                        } else if ("trustStorePassword".equals(localName)) {
                            config.setTrustStorePassword(reader.getElementText());
                        } else if ("modifyTrustStore".equals(localName)) {
                            config.setModifyTrustStore(Boolean.getBoolean(reader.getElementText()));
                        }
                    }
                }
            });

            FileInputStream is = new FileInputStream(f);
            input = new BufferedInputStream(is);
            XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
            mapper.parseDocument(config, streamReader);
            streamReader.close();
        } catch(Throwable t) {
            throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
        } finally {
            StreamUtils.safeClose(input);
        }
        return config;
    }
View Full Code Here

                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    keyManagerFactory.init(theKeyStore, keyPassword);
                    keyManagers = keyManagerFactory.getKeyManagers();
                } catch (IOException e) {
                    throw new CliInitializationException(e);
                } catch (GeneralSecurityException e) {
                    throw new CliInitializationException(e);
                } finally {
                    StreamUtils.safeClose(fis);
                }

            }

            trustStore = sslConfig.getTrustStore();
            trustStorePassword = sslConfig.getTrustStorePassword();
            modifyTrustStore = sslConfig.isModifyTrustStore();
        }

        if (trustStore == null) {
            final String userHome = SecurityActions.getSystemProperty("user.home");
            File trustStoreFile = new File(userHome, ".jboss-cli.truststore");
            trustStore = trustStoreFile.getAbsolutePath();
            trustStorePassword = "cli_truststore"; // Risk of modification but no private keys to be stored in the truststore.
        }

        trustManager = new LazyDelagatingTrustManager(trustStore, trustStorePassword, modifyTrustStore);
        trustManagers = new TrustManager[] { trustManager };

        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, null);

            this.sslContext = sslContext;
        } catch (GeneralSecurityException e) {
            throw new CliInitializationException(e);
        }
    }
View Full Code Here

        return parse(ctx, new File(jbossHome + File.separatorChar + "bin", "jboss-cli.xml"));
    }

    static CliConfig parse(final CommandContext ctx, File f) throws CliInitializationException {
        if(f == null) {
            throw new CliInitializationException("The file argument is null.");
        }
        if(!f.exists()) {
            //throw new CliInitializationException(f.getAbsolutePath() + " doesn't exist.");
            return new CliConfigImpl();
        }

        CliConfigImpl config = new CliConfigImpl();

        BufferedInputStream input = null;
        try {
            final XMLMapper mapper = XMLMapper.Factory.create();
            final XMLElementReader<CliConfigImpl> reader = new CliConfigReader();
            for (Namespace current : Namespace.cliValues()) {
                mapper.registerRootElement(new QName(current.getUriString(), JBOSS_CLI), reader);
            }
            FileInputStream is = new FileInputStream(f);
            input = new BufferedInputStream(is);
            XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
            mapper.parseDocument(config, streamReader);
            streamReader.close();
        } catch(Throwable t) {
            throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
        } finally {
            StreamUtils.safeClose(input);
        }
        return config;
    }
View Full Code Here

                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    keyManagerFactory.init(theKeyStore, keyPassword);
                    keyManagers = keyManagerFactory.getKeyManagers();
                } catch (IOException e) {
                    throw new CliInitializationException(e);
                } catch (GeneralSecurityException e) {
                    throw new CliInitializationException(e);
                } finally {
                    StreamUtils.safeClose(fis);
                }

            }

            trustStore = sslConfig.getTrustStore();
            trustStorePassword = sslConfig.getTrustStorePassword();
            modifyTrustStore = sslConfig.isModifyTrustStore();
        }

        if (trustStore == null) {
            final String userHome = SecurityActions.getSystemProperty("user.home");
            File trustStoreFile = new File(userHome, ".jboss-cli.truststore");
            trustStore = trustStoreFile.getAbsolutePath();
            trustStorePassword = "cli_truststore"; // Risk of modification but no private keys to be stored in the truststore.
        }

        trustManager = new LazyDelagatingTrustManager(trustStore, trustStorePassword, modifyTrustStore);
        trustManagers = new TrustManager[] { trustManager };

        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(keyManagers, trustManagers, null);

            this.sslContext = sslContext;
        } catch (GeneralSecurityException e) {
            throw new CliInitializationException(e);
        }
    }
View Full Code Here

        final CommandContext cmdCtx = CommandContextFactory.getInstance().newCommandContext(defaultHost, defaultPort, username, password, initConsole, connectionTimeout);
        if(connect) {
            try {
                cmdCtx.connectController();
            } catch (CommandLineException e) {
                throw new CliInitializationException("Failed to connect to the controller", e);
            }
        }
        return cmdCtx;
    }
View Full Code Here

        return jbossCliFile;
    }

    static CliConfig parse(final CommandContext ctx, File f) throws CliInitializationException {
        if(f == null) {
            throw new CliInitializationException("The file argument is null.");
        }
        if(!f.exists()) {
            //throw new CliInitializationException(f.getAbsolutePath() + " doesn't exist.");
            return new CliConfigImpl();
        }

        CliConfigImpl config = new CliConfigImpl();

        BufferedInputStream input = null;
        try {
            final XMLMapper mapper = XMLMapper.Factory.create();
            final XMLElementReader<CliConfigImpl> reader = new CliConfigReader();
            for (Namespace current : Namespace.cliValues()) {
                mapper.registerRootElement(new QName(current.getUriString(), JBOSS_CLI), reader);
            }
            FileInputStream is = new FileInputStream(f);
            input = new BufferedInputStream(is);
            XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
            mapper.parseDocument(config, streamReader);
            streamReader.close();
        } catch(Throwable t) {
            throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
        } finally {
            StreamUtils.safeClose(input);
        }
        return config;
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.cli.CliInitializationException

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.