Example usage for org.apache.commons.configuration ConfigurationException ConfigurationException

List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationException ConfigurationException.

Prototype

public ConfigurationException(Throwable cause) 

Source Link

Document

Constructs a new ConfigurationException with specified nested Throwable.

Usage

From source file:org.wso2.andes.configuration.qpid.VirtualHostConfiguration.java

@Override
public void validateConfiguration() throws ConfigurationException {
    // QPID-3249.  Support for specifying authentication name at vhost level is no longer
    // supported.
    if (getListValue("security.authentication.name").size() > 0) {
        String message = "Validation error : security/authentication/name is no longer a "
                + "supported element within the configuration xml."
                + " It appears in virtual host definition : " + _name;
        throw new ConfigurationException(message);
    }/*from w ww .j a v a2 s .com*/
}

From source file:org.wso2.andes.server.configuration.ServerConfiguration.java

@Override
public void validateConfiguration() throws ConfigurationException {
    // Support for security.jmx.access was removed when JMX access rights were incorporated into the main ACL.
    // This ensure that users remove the element from their configuration file.

    if (getListValue("security.jmx.access").size() > 0) {
        String message = "Validation error : security/jmx/access is no longer a supported element within the configuration xml."
                + (_configFile == null ? "" : " Configuration file : " + _configFile);
        throw new ConfigurationException(message);
    }/*from w w  w .j  av  a 2  s  .  c  o m*/

    if (getListValue("security.jmx.principal-database").size() > 0) {
        String message = "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml."
                + (_configFile == null ? "" : " Configuration file : " + _configFile);
        throw new ConfigurationException(message);
    }

    if (getListValue("security.principal-databases.principal-database(0).class").size() > 0) {
        String message = "Validation error : security/principal-databases is no longer supported within the configuration xml."
                + (_configFile == null ? "" : " Configuration file : " + _configFile);
        throw new ConfigurationException(message);
    }
}

From source file:org.wso2.andes.server.configuration.ServerConfiguration.java

@SuppressWarnings("unchecked")
protected void setupVirtualHosts(Configuration conf) throws ConfigurationException {
    List<String> vhostFiles = conf.getList("virtualhosts");
    Configuration vhostConfig = conf.subset("virtualhosts");

    // Only one configuration mechanism allowed
    if (!vhostFiles.isEmpty() && !vhostConfig.subset("virtualhost").isEmpty()) {
        throw new ConfigurationException(
                "Only one of external or embedded virtualhosts configuration allowed.");
    }/*w  ww .  j  a  v a 2  s  .  c  om*/

    // We can only have one vhosts XML file included
    if (vhostFiles.size() > 1) {
        throw new ConfigurationException(
                "Only one external virtualhosts configuration file allowed, multiple filenames found.");
    }

    // Virtualhost configuration object
    Configuration vhostConfiguration = new HierarchicalConfiguration();

    // Load from embedded configuration if possible
    if (!vhostConfig.subset("virtualhost").isEmpty()) {
        vhostConfiguration = vhostConfig;
    } else {
        // Load from the external configuration if possible
        for (String fileName : vhostFiles) {
            // Open the vhosts XML file and copy values from it to our config
            _vhostsFile = new File(fileName);
            if (!_vhostsFile.exists()) {
                throw new ConfigurationException("Virtualhosts file does not exist");
            }
            vhostConfiguration = parseConfig(new File(fileName));

            // save the default virtualhost name
            String defaultVirtualHost = vhostConfiguration.getString("default");
            _configuration.setProperty("virtualhosts.default", defaultVirtualHost);
        }
    }

    // Now extract the virtual host names from the configuration object
    List hosts = vhostConfiguration.getList("virtualhost.name");
    for (int j = 0; j < hosts.size(); j++) {
        String name = (String) hosts.get(j);

        // Add the virtual hosts to the server configuration
        VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name,
                vhostConfiguration.subset("virtualhost." + name));
        _virtualHosts.put(virtualhost.getName(), virtualhost);
    }
}

From source file:org.wso2.andes.server.configuration.VirtualHostConfiguration.java

@Override
public void validateConfiguration() throws ConfigurationException {
    // QPID-3249.  Support for specifying authentication name at vhost level is no longer supported.
    if (getListValue("security.authentication.name").size() > 0) {
        String message = "Validation error : security/authentication/name is no longer a supported element within the configuration xml."
                + " It appears in virtual host definition : " + _name;
        throw new ConfigurationException(message);
    }/*from   w w  w .ja  v  a2 s. co m*/
}

From source file:org.wso2.andes.server.management.JMXManagedObjectRegistry.java

public void start() throws IOException, ConfigurationException {

    CurrentActor.get().message(ManagementConsoleMessages.STARTUP());

    //check if system properties are set to use the JVM's out-of-the-box JMXAgent
    if (areOutOfTheBoxJMXOptionsSet()) {
        CurrentActor.get().message(ManagementConsoleMessages.READY(true));
        return;/* w  w w .j  a v  a2s  .  c  om*/
    }

    IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
    int port = appRegistry.getConfiguration().getJMXManagementPort();

    //Socket factories for the RMIConnectorServer, either default or SLL depending on configuration
    RMIClientSocketFactory csf;
    RMIServerSocketFactory ssf;

    //check ssl enabled option in config, default to true if option is not set
    boolean sslEnabled = appRegistry.getConfiguration().getManagementSSLEnabled();

    if (sslEnabled) {
        //set the SSL related system properties used by the SSL RMI socket factories to the values
        //given in the configuration file, unless command line settings have already been specified
        String keyStorePath;

        if (System.getProperty("javax.net.ssl.keyStore") != null) {
            keyStorePath = System.getProperty("javax.net.ssl.keyStore");
        } else {
            keyStorePath = appRegistry.getConfiguration().getManagementKeyStorePath();
        }

        //check the keystore path value is valid
        if (keyStorePath == null) {
            throw new ConfigurationException("JMX management SSL keystore path not defined, "
                    + "unable to start SSL protected JMX ConnectorServer");
        } else {
            //ensure the system property is set
            System.setProperty("javax.net.ssl.keyStore", keyStorePath);

            //check the file is usable
            File ksf = new File(keyStorePath);

            if (!ksf.exists()) {
                throw new FileNotFoundException("Cannot find JMX management SSL keystore file " + ksf + "\n"
                        + "Check broker configuration, or see create-example-ssl-stores script"
                        + "in the bin/ directory if you need to generate an example store.");
            }
            if (!ksf.canRead()) {
                throw new FileNotFoundException(
                        "Cannot read JMX management SSL keystore file: " + ksf + ". Check permissions.");
            }

            CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(ksf.getAbsolutePath()));
        }

        //check the key store password is set
        if (System.getProperty("javax.net.ssl.keyStorePassword") == null) {

            if (appRegistry.getConfiguration().getManagementKeyStorePassword() == null) {
                throw new ConfigurationException("JMX management SSL keystore password not defined, "
                        + "unable to start requested SSL protected JMX server");
            } else {
                System.setProperty("javax.net.ssl.keyStorePassword",
                        appRegistry.getConfiguration().getManagementKeyStorePassword());
            }
        }

        //create the SSL RMI socket factories
        csf = new SslRMIClientSocketFactory();
        ssf = new SslRMIServerSocketFactory();
    } else {
        //Do not specify any specific RMI socket factories, resulting in use of the defaults.
        csf = null;
        ssf = null;
    }

    //add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server
    RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator();
    rmipa.setAuthenticationManager(appRegistry.getAuthenticationManager());
    HashMap<String, Object> env = new HashMap<String, Object>();
    env.put(JMXConnectorServer.AUTHENTICATOR, rmipa);

    /*
     * Start a RMI registry on the management port, to hold the JMX RMI ConnectorServer stub. 
     * Using custom socket factory to prevent anyone (including us unfortunately) binding to the registry using RMI.
     * As a result, only binds made using the object reference will succeed, thus securing it from external change. 
     */
    System.setProperty("java.rmi.server.randomIDs", "true");
    if (_useCustomSocketFactory) {
        _rmiRegistry = LocateRegistry.createRegistry(port, null, new CustomRMIServerSocketFactory());
    } else {
        _rmiRegistry = LocateRegistry.createRegistry(port, null, null);
    }

    CurrentActor.get().message(ManagementConsoleMessages.LISTENING("RMI Registry", port));

    /*
     * We must now create the RMI ConnectorServer manually, as the JMX Factory methods use RMI calls 
     * to bind the ConnectorServer to the registry, which will now fail as for security we have
     * locked it from any RMI based modifications, including our own. Instead, we will manually bind 
     * the RMIConnectorServer stub to the registry using its object reference, which will still succeed.
     * 
     * The registry is exported on the defined management port 'port'. We will export the RMIConnectorServer
     * on 'port +1'. Use of these two well-defined ports will ease any navigation through firewall's. 
     */
    final RMIServerImpl rmiConnectorServerStub = new RMIJRMPServerImpl(port + PORT_EXPORT_OFFSET, csf, ssf,
            env);
    String localHost;
    try {
        localHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ex) {
        localHost = "127.0.0.1";
    }
    final String hostname = localHost;
    final JMXServiceURL externalUrl = new JMXServiceURL("service:jmx:rmi://" + hostname + ":"
            + (port + PORT_EXPORT_OFFSET) + "/jndi/rmi://" + hostname + ":" + port + "/jmxrmi");

    final JMXServiceURL internalUrl = new JMXServiceURL("rmi", hostname, port + PORT_EXPORT_OFFSET);
    _cs = new RMIConnectorServer(internalUrl, env, rmiConnectorServerStub, _mbeanServer) {
        @Override
        public synchronized void start() throws IOException {
            try {
                //manually bind the connector server to the registry at key 'jmxrmi', like the out-of-the-box agent                        
                _rmiRegistry.bind("jmxrmi", rmiConnectorServerStub);
            } catch (AlreadyBoundException abe) {
                //key was already in use. shouldnt happen here as its a new registry, unbindable by normal means.

                //IOExceptions are the only checked type throwable by the method, wrap and rethrow
                IOException ioe = new IOException(abe.getMessage());
                ioe.initCause(abe);
                throw ioe;
            }

            //now do the normal tasks
            super.start();
        }

        @Override
        public synchronized void stop() throws IOException {
            try {
                if (_rmiRegistry != null) {
                    _rmiRegistry.unbind("jmxrmi");
                }
            } catch (NotBoundException nbe) {
                //ignore
            }

            //now do the normal tasks
            super.stop();
        }

        @Override
        public JMXServiceURL getAddress() {
            //must return our pre-crafted url that includes the full details, inc JNDI details
            return externalUrl;
        }

    };

    //Add the custom invoker as an MBeanServerForwarder, and start the RMIConnectorServer.
    MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance();
    _cs.setMBeanServerForwarder(mbsf);

    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(JMXConnectionNotification.OPENED);
    filter.enableType(JMXConnectionNotification.CLOSED);
    filter.enableType(JMXConnectionNotification.FAILED);
    // Get the handler that is used by the above MBInvocationHandler Proxy.
    // which is the MBeanInvocationHandlerImpl and so also a NotificationListener
    _cs.addNotificationListener((NotificationListener) Proxy.getInvocationHandler(mbsf), filter, null);

    _cs.start();

    String connectorServer = (sslEnabled ? "SSL " : "") + "JMX RMIConnectorServer";
    CurrentActor.get().message(ManagementConsoleMessages.LISTENING(connectorServer, port + PORT_EXPORT_OFFSET));

    CurrentActor.get().message(ManagementConsoleMessages.READY(false));
}

From source file:org.wso2.andes.server.registry.ApplicationRegistry.java

public void configure() throws ConfigurationException {
    _configurationManager = new ConfigurationManager();

    try {//  w ww  .  j av  a2  s.c o  m
        _pluginManager = new PluginManager(_configuration.getPluginDirectory(),
                _configuration.getCacheDirectory());
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }

    _configuration.initialise();
}

From source file:org.wso2.andes.server.registry.ApplicationRegistry.java

/**
 * Iterates across all discovered authentication manager factories, offering the security configuration to each.
 * Expects <b>exactly</b> one authentication manager to configure and initialise itself.
 * /*from w  w w.jav  a  2s .c  o m*/
 * It is an error to configure more than one authentication manager, or to configure none.
 *
 * @return authentication manager
 * @throws ConfigurationException
 */
protected AuthenticationManager createAuthenticationManager() throws ConfigurationException {
    final SecurityConfiguration securityConfiguration = _configuration
            .getConfiguration(SecurityConfiguration.class.getName());
    final Collection<AuthenticationManagerPluginFactory<? extends Plugin>> factories = _pluginManager
            .getAuthenticationManagerPlugins().values();

    if (factories.size() == 0) {
        throw new ConfigurationException(
                "No authentication manager factory plugins found.  Check the desired authentication"
                        + "manager plugin has been placed in the plugins directory.");
    }

    AuthenticationManager authMgr = null;

    for (final Iterator<AuthenticationManagerPluginFactory<? extends Plugin>> iterator = factories
            .iterator(); iterator.hasNext();) {
        final AuthenticationManagerPluginFactory<? extends Plugin> factory = (AuthenticationManagerPluginFactory<? extends Plugin>) iterator
                .next();
        final AuthenticationManager tmp = factory.newInstance(securityConfiguration);
        if (tmp != null) {
            if (authMgr != null) {
                throw new ConfigurationException("Cannot configure more than one authentication manager."
                        + " Both " + tmp.getClass() + " and " + authMgr.getClass() + " are configured."
                        + " Remove configuration for one of the authentication manager, or remove the plugin JAR"
                        + " from the classpath.");
            }
            authMgr = tmp;
        }
    }

    if (authMgr == null) {
        throw new ConfigurationException("No authentication managers configured within the configure file.");
    }

    return authMgr;
}

From source file:org.wso2.andes.server.security.access.config.PlainConfiguration.java

@Override
public RuleSet load() throws ConfigurationException {
    RuleSet ruleSet = super.load();

    try {//from  w  w  w .  jav a  2s  .c om
        _st = new StreamTokenizer(new BufferedReader(new FileReader(_file)));
        _st.resetSyntax(); // setup the tokenizer

        _st.commentChar(COMMENT); // single line comments
        _st.eolIsSignificant(true); // return EOL as a token
        _st.lowerCaseMode(true); // case insensitive tokens
        _st.ordinaryChar('='); // equals is a token
        _st.ordinaryChar(CONTINUATION); // continuation character (when followed by EOL)
        _st.quoteChar('"'); // double quote
        _st.quoteChar('\''); // single quote
        _st.whitespaceChars('\u0000', '\u0020'); // whitespace (to be ignored) TODO properly
        _st.wordChars('a', 'z'); // unquoted token characters [a-z]
        _st.wordChars('A', 'Z'); // [A-Z]
        _st.wordChars('0', '9'); // [0-9]
        _st.wordChars('_', '_'); // underscore
        _st.wordChars('-', '-'); // dash
        _st.wordChars('.', '.'); // dot
        _st.wordChars('*', '*'); // star
        _st.wordChars('@', '@'); // at
        _st.wordChars(':', ':'); // colon

        // parse the acl file lines
        Stack<String> stack = new Stack<String>();
        int current;
        do {
            current = _st.nextToken();
            switch (current) {
            case StreamTokenizer.TT_EOF:
            case StreamTokenizer.TT_EOL:
                if (stack.isEmpty()) {
                    break; // blank line
                }

                // pull out the first token from the bottom of the stack and check arguments exist
                String first = stack.firstElement();
                stack.removeElementAt(0);
                if (stack.isEmpty()) {
                    throw new ConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
                }

                // check for and parse optional initial number for ACL lines
                Integer number = null;
                if (StringUtils.isNumeric(first)) {
                    // set the acl number and get the next element
                    number = Integer.valueOf(first);
                    first = stack.firstElement();
                    stack.removeElementAt(0);
                }

                if (StringUtils.equalsIgnoreCase(ACL, first)) {
                    parseAcl(number, stack);
                } else if (number == null) {
                    if (StringUtils.equalsIgnoreCase(GROUP, first)) {
                        parseGroup(stack);
                    } else if (StringUtils.equalsIgnoreCase(CONFIG, first)) {
                        parseConfig(stack);
                    } else {
                        throw new ConfigurationException(
                                String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
                    }
                } else {
                    throw new ConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
                }

                // reset stack, start next line
                stack.clear();
                break;
            case StreamTokenizer.TT_NUMBER:
                stack.push(Integer.toString(Double.valueOf(_st.nval).intValue()));
                break;
            case StreamTokenizer.TT_WORD:
                stack.push(_st.sval); // token
                break;
            default:
                if (_st.ttype == CONTINUATION) {
                    int next = _st.nextToken();
                    if (next == StreamTokenizer.TT_EOL) {
                        break; // continue reading next line
                    }

                    // invalid location for continuation character (add one to line beacuse we ate the EOL)
                    throw new ConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
                } else if (_st.ttype == '\'' || _st.ttype == '"') {
                    stack.push(_st.sval); // quoted token
                } else {
                    stack.push(Character.toString((char) _st.ttype)); // single character
                }
            }
        } while (current != StreamTokenizer.TT_EOF);

        if (!stack.isEmpty()) {
            throw new ConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
        }
    } catch (IllegalArgumentException iae) {
        throw new ConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
    } catch (FileNotFoundException fnfe) {
        throw new ConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, getFile().getName()), fnfe);
    } catch (IOException ioe) {
        throw new ConfigurationException(String.format(CANNOT_LOAD_MSG, getFile().getName()), ioe);
    }

    return ruleSet;
}

From source file:org.wso2.andes.server.security.access.config.PlainConfiguration.java

private void parseGroup(List<String> args) throws ConfigurationException {
    if (args.size() < 2) {
        throw new ConfigurationException(String.format(NOT_ENOUGH_GROUP_MSG, getLine()));
    }//from   ww  w.  j  a v a2s.c  o  m

    getConfiguration().addGroup(args.get(0), args.subList(1, args.size()));
}

From source file:org.wso2.andes.server.security.access.config.PlainConfiguration.java

private void parseAcl(Integer number, List<String> args) throws ConfigurationException {
    if (args.size() < 3) {
        throw new ConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, getLine()));
    }//from  w ww. j a v  a2  s  .  c  om

    Permission permission = Permission.parse(args.get(0));
    String identity = args.get(1);
    Operation operation = Operation.parse(args.get(2));

    if (number != null && !getConfiguration().isValidNumber(number)) {
        throw new ConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, getLine()));
    }

    if (args.size() == 3) {
        getConfiguration().grant(number, identity, permission, operation);
    } else {
        ObjectType object = ObjectType.parse(args.get(3));
        ObjectProperties properties = toObjectProperties(args.subList(4, args.size()));

        getConfiguration().grant(number, identity, permission, operation, object, properties);
    }
}