Search in sources :

Example 6 with BrokerConfig

use of com.sun.messaging.jmq.jmsserver.config.BrokerConfig in project openmq by eclipse-ee4j.

the class BrokerMonitor method shutdownMonitor.

public static void shutdownMonitor() {
    if (task != null) {
        task.cancel();
    }
    active.clear();
    BrokerConfig cfg = Globals.getConfig();
    cfg.removeListener(METRICS_TIME_PROP, cl);
    cfg.removeListener(PERSIST_PROP, cl);
    cfg.removeListener(TTL_PROP, cl);
    cl = null;
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig)

Example 7 with BrokerConfig

use of com.sun.messaging.jmq.jmsserver.config.BrokerConfig in project openmq by eclipse-ee4j.

the class KeystoreUtil method getKeystorePassword.

public static String getKeystorePassword() throws IOException {
    if (pass_phrase == null) {
        BrokerConfig bcfg;
        Password pw = null;
        bcfg = Globals.getConfig();
        // Get Passphrase from property setting
        pass_phrase = bcfg.getProperty(KEYSTORE_PASSWORD_PROP);
        // if passphrase is null then get it thro' user interaction
        int retry = 0;
        pw = new Password();
        if (pw.echoPassword()) {
            System.err.println(Globals.getBrokerResources().getString(BrokerResources.W_ECHO_PASSWORD));
        }
        while ((pass_phrase == null || pass_phrase.equals("")) && retry <= 5) {
            System.err.print(br.getString(BrokerResources.M_ENTER_KEY_PWD, getKeystoreLocation()));
            System.err.flush();
            if (Broker.getBroker().background) {
                // We're running in the background and can't
                // read the password. We still prompt for it
                // so it's more obvious what's going on
                // (instead of just silently failing)
                // See 4451214
                System.err.print("\n");
                break;
            }
            pass_phrase = pw.getPassword();
            // Limit the number of times we try reading the passwd.
            // If the VM is run in the background the readLine()
            // will always return null and we'd get stuck
            // in the loop
            retry++;
        }
    }
    return (pass_phrase);
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) Password(com.sun.messaging.jmq.util.Password)

Example 8 with BrokerConfig

use of com.sun.messaging.jmq.jmsserver.config.BrokerConfig in project openmq by eclipse-ee4j.

the class ConnectorServerInfo method initURL.

/*
     * Initialize the JMXServiceURL associated with this connector. This class was initialized with just the connector
     * 'name' which has nothing to do with JMX, but merely a reference into the broker configuration properties.
     *
     * There are various properties that can be used to configure or construct the URL - the properties map more or less to
     * the constructor of the JMXServiceURL class:
     *
     * public JMXServiceURL(String protocol, String host, int port, String urlPath)
     *
     * So, for example, the default JMX connector is named "jmxrmi" and the properties that can be used to configure it's
     * URL are:
     *
     * imq.jmx.connector.<connector server name>.protocol imq.jmx.connector.<connector server name>.port
     * imq.jmx.connector.<connector server name>.urlpath imq.jmx.connector.<connector server name>.url
     *
     * Out of the above, only the following is made public:
     *
     * imq.jmx.connector.<connector server name>.urlpath
     *
     * because the only protocol supported in MQ 4.0 is rmi, and the port is pretty much ignored for RMI connectors. No real
     * reason url is not made public other than the fact that we want to simplify things and it is not really needed.
     *
     * If urlpath is not specified via the above property, a default exists and can be constructed with
     * Agent.getDefaultJMXUrlPathBase().
     *
     * One point worth noting is that this fixed or JNDI form of the url is only used when a RMI registry (or some form of
     * JNDI repository) is used to store the RMI stub for the connector.
     *
     * Example entry in configuration properties:
     *
     * imq.jmx.connector.jmxrmi.urlpath=/foo/bar/connector1
     */
private void initURL() throws BrokerException {
    String protocol = null, urlpath = null, jmxurl = null;
    int port = 0;
    JMXServiceURL url;
    BrokerConfig config = Globals.getConfig();
    String jmxHostname = Globals.getJMXHostname();
    if (configuredURL != null) {
        return;
    }
    jmxurl = config.getProperty(CONNECTOR_PROPBASE + name + URL_SUFFIX);
    if (jmxurl == null) {
        protocol = config.getProperty(CONNECTOR_PROPBASE + name + PROTOCOL_SUFFIX, "rmi");
        /*
             * Get port value, defaulting to 0 if none was specified.
             *
             * The javadoc for JMXServiceURL says that getPort() will return 0 if none was specified.
             */
        port = config.getIntProperty(CONNECTOR_PROPBASE + name + PORT_SUFFIX, 0);
        urlpath = config.getProperty(CONNECTOR_PROPBASE + name + URLPATH_SUFFIX);
        if (urlpath == null) {
            /*
                 * If imq.jmx.rmiregistry.start or imq.jmx.rmiregistry.use is set to true, the default urlpath is:
                 * /jndi/rmi://<brokerhost>:<rmiport>/<brokerhost>/<brokerport>/<connector name>
                 */
            if (agent.startRmiRegistry() || agent.useRmiRegistry()) {
                urlpath = agent.getDefaultJMXUrlPathBase() + name;
            }
        }
    }
    try {
        if (jmxurl != null) {
            url = new JMXServiceURL(jmxurl);
        } else {
            if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
                url = new JMXServiceURL(protocol, jmxHostname, port, urlpath);
            } else {
                url = new JMXServiceURL(protocol, null, port, urlpath);
            }
        }
    } catch (MalformedURLException mfe) {
        throw new BrokerException(rb.getString(rb.W_JMX_CREATE_URL_FOR_CONNECTOR_FAILED, name), mfe);
    }
    configuredURL = url;
}
Also used : MalformedURLException(java.net.MalformedURLException) BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 9 with BrokerConfig

use of com.sun.messaging.jmq.jmsserver.config.BrokerConfig in project openmq by eclipse-ee4j.

the class ConnectorServerInfo method initConnectorServer.

/*
     * Initialize the connector server. This method assumes the URL has been initialized.
     *
     * The following properties can be used to further configure the connector server: imq.jmx.connector.<connector server
     * name>.useSSL imq.jmx.connector.<connector server name>.brokerHostTrusted imq.jmx.connector.<connector server
     * name>.backlog
     *
     */
private void initConnectorServer() throws BrokerException {
    JMXConnectorServer cs;
    BrokerConfig config = Globals.getConfig();
    MBeanServer mbs = agent.getMBeanServer();
    HashMap env = new HashMap();
    boolean useSSL, brokerHostTrusted;
    String jmxHostname = Globals.getJMXHostname();
    int backlog;
    if (connectorServer != null) {
        return;
    }
    if (mbs == null) {
        throw new BrokerException(rb.getString(rb.X_JMX_CANT_CREATE_CONNECTOR_SVR, name));
    }
    useSSL = config.getBooleanProperty(CONNECTOR_PROPBASE + name + SSL_SUFFIX, false);
    /*
         * Query property that specifies if the broker is to be trusted. If this property is not set, by default the broker is
         * *not* trusted.
         */
    brokerHostTrusted = config.getBooleanProperty(CONNECTOR_PROPBASE + name + BROKER_HOST_TRUSTED_SUFFIX, false);
    backlog = config.getIntProperty(CONNECTOR_PROPBASE + name + BACKLOG_SUFFIX, 0);
    try {
        /*
             * We only support the RMI protocol in MQ 4.0
             */
        if (configuredURL.getProtocol().equals("rmi")) {
            boolean useAuth = true;
            if (useAuth) {
                env.put(JMXConnectorServer.AUTHENTICATOR, new MQJMXAuthenticator(this));
            }
            /*
                 * Use MQ specific server socket factory only if: - SSL is enabled - need to specify a specific host/IP on a multihome
                 * system
                 */
            if ((useSSL) || (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL))) {
                MQRMIServerSocketFactory ssf = new MQRMIServerSocketFactory(jmxHostname, backlog, useSSL);
                env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
            }
            /*
                 * Use MQ specific client socket factory only if: - need to specify a specific host/IP on a multihome system
                 */
            if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
                MQRMIClientSocketFactory csf = new MQRMIClientSocketFactory(jmxHostname, brokerHostTrusted, useSSL);
                env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
                if ((Globals.isJMSRAManagedBroker() || Globals.isNucleusManagedBroker()) && agent.useRmiRegistry()) {
                    env.put("com.sun.jndi.rmi.factory.socket", csf);
                }
            } else {
                /*
                     * Use MQ specific client socket factory only if: - SSL is enabled and brokerHostTrusted is true If brokerHostTrusted is
                     * false, use the JDK provided javax.rmi.ssl.SslRMIClientSocketFactory
                     */
                if (useSSL) {
                    if (brokerHostTrusted) {
                        MQRMIClientSocketFactory csf = new MQRMIClientSocketFactory(jmxHostname, brokerHostTrusted, useSSL);
                        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
                    } else {
                        javax.rmi.ssl.SslRMIClientSocketFactory sslcf = new javax.rmi.ssl.SslRMIClientSocketFactory();
                        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, sslcf);
                        if ((Globals.isJMSRAManagedBroker() || Globals.isNucleusManagedBroker()) && agent.useRmiRegistry()) {
                            env.put("com.sun.jndi.rmi.factory.socket", sslcf);
                        }
                    }
                }
            }
        }
        cs = JMXConnectorServerFactory.newJMXConnectorServer(configuredURL, env, mbs);
    } catch (Exception e) {
        throw new BrokerException(rb.getString(rb.W_JMX_ERROR_CREATING_CONNECTOR, name), e);
    }
    cs.addNotificationListener(listener, null, this);
    connectorServer = cs;
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) MalformedURLException(java.net.MalformedURLException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) IOException(java.io.IOException) MQRMIClientSocketFactory(com.sun.messaging.jmq.management.MQRMIClientSocketFactory)

Example 10 with BrokerConfig

use of com.sun.messaging.jmq.jmsserver.config.BrokerConfig in project openmq by eclipse-ee4j.

the class MQAuthenticator method authenticateCMDUserIfset.

public static boolean authenticateCMDUserIfset() {
    BrokerConfig bcfg = Globals.getConfig();
    String cmduser = bcfg.getProperty(CMDUSER_PROPERTY);
    if (cmduser == null) {
        return true;
    }
    Logger logger = Globals.getLogger();
    if (cmduser.trim().length() == 0) {
        logger.log(Logger.FORCE, BrokerResources.X_BAD_PROPERTY_VALUE, CMDUSER_PROPERTY + "=" + cmduser);
        return false;
    }
    /*
         * if (!bcfg.getBooleanProperty(Globals.KEYSTORE_USE_PASSFILE_PROP)) { logger.log(Logger.FORCE,
         * rb.E_AUTH_CMDUSER_PASSFILE_NOT_ENABLED, Globals.KEYSTORE_USE_PASSFILE_PROP, cmduserProp); return false; }
         */
    String cmdpwd = bcfg.getProperty(CMDUSER_PWD_PROPERTY);
    if (cmdpwd == null) {
        logger.log(Logger.FORCE, BrokerResources.X_PASSWORD_NOT_PROVIDED, CMDUSER_PROPERTY + "=" + cmduser);
        return false;
    }
    String cmdsvc = bcfg.getProperty(CMDUSER_SVC_PROPERTY);
    if (cmdsvc == null) {
        cmdsvc = "admin";
    }
    List activesvcs = ServiceManager.getAllActiveServiceNames();
    if (activesvcs == null || !activesvcs.contains(cmdsvc)) {
        logger.log(Logger.FORCE, BrokerResources.E_NOT_ACTIVE_SERVICE, cmdsvc, CMDUSER_PROPERTY + "=" + cmduser);
        return false;
    }
    String str = ServiceManager.getServiceTypeString(cmdsvc);
    if (str == null || ServiceType.getServiceType(str) != ServiceType.ADMIN) {
        String[] args = { cmdsvc, str, CMDUSER_PROPERTY + "=" + cmduser };
        logger.log(Logger.FORCE, BrokerResources.E_NOT_ADMIN_SERVICE, args);
        return false;
    }
    try {
        MQAuthenticator a = new MQAuthenticator(cmdsvc, ServiceType.ADMIN);
        a.authenticate(cmduser, cmdpwd);
        if (DEBUG) {
            logger.log(Logger.FORCE, BrokerResources.I_AUTH_OK, CMDUSER_PROPERTY + "=" + cmduser, cmdsvc);
        }
        return true;
    } catch (Exception e) {
        if (DEBUG) {
            logger.logStack(Logger.FORCE, BrokerResources.W_AUTH_FAILED, cmduser, cmdsvc, e);
        } else {
            logger.log(Logger.FORCE, BrokerResources.W_AUTH_FAILED, cmduser, cmdsvc);
        }
        return false;
    }
}
Also used : BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) List(java.util.List) Logger(com.sun.messaging.jmq.util.log.Logger) LoginException(javax.security.auth.login.LoginException) AccessControlException(java.security.AccessControlException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

BrokerConfig (com.sun.messaging.jmq.jmsserver.config.BrokerConfig)13 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 Logger (com.sun.messaging.jmq.util.log.Logger)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Properties (java.util.Properties)2 FileTransactionLogWriter (com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter)1 BrokerShutdownRuntimeException (com.sun.messaging.jmq.jmsserver.util.BrokerShutdownRuntimeException)1 LoggerManager (com.sun.messaging.jmq.jmsserver.util.LoggerManager)1 MQRMIClientSocketFactory (com.sun.messaging.jmq.management.MQRMIClientSocketFactory)1 Password (com.sun.messaging.jmq.util.Password)1 SizeString (com.sun.messaging.jmq.util.SizeString)1 AccessControlException (java.security.AccessControlException)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LoginException (javax.security.auth.login.LoginException)1