Search in sources :

Example 6 with AgentConfigurationError

use of sun.management.AgentConfigurationError in project jdk8u_jdk by JetBrains.

the class ConnectorBootstrap method checkPasswordFile.

private static void checkPasswordFile(String passwordFileName) {
    if (passwordFileName == null || passwordFileName.length() == 0) {
        throw new AgentConfigurationError(PASSWORD_FILE_NOT_SET);
    }
    File file = new File(passwordFileName);
    if (!file.exists()) {
        throw new AgentConfigurationError(PASSWORD_FILE_NOT_FOUND, passwordFileName);
    }
    if (!file.canRead()) {
        throw new AgentConfigurationError(PASSWORD_FILE_NOT_READABLE, passwordFileName);
    }
    FileSystem fs = FileSystem.open();
    try {
        if (fs.supportsFileSecurity(file)) {
            if (!fs.isAccessUserOnly(file)) {
                final String msg = Agent.getText("jmxremote.ConnectorBootstrap.password.readonly", passwordFileName);
                log.config("startRemoteConnectorServer", msg);
                throw new AgentConfigurationError(PASSWORD_FILE_ACCESS_NOT_RESTRICTED, passwordFileName);
            }
        }
    } catch (IOException e) {
        throw new AgentConfigurationError(PASSWORD_FILE_READ_FAILED, e, passwordFileName);
    }
}
Also used : AgentConfigurationError(sun.management.AgentConfigurationError) FileSystem(sun.management.FileSystem) IOException(java.io.IOException) File(java.io.File)

Example 7 with AgentConfigurationError

use of sun.management.AgentConfigurationError in project jdk8u_jdk by JetBrains.

the class ConnectorBootstrap method exportMBeanServer.

private static JMXConnectorServerData exportMBeanServer(MBeanServer mbs, int port, int rmiPort, boolean useSsl, boolean useRegistrySsl, String sslConfigFileName, String[] enabledCipherSuites, String[] enabledProtocols, boolean sslNeedClientAuth, boolean useAuthentication, String loginConfigName, String passwordFileName, String accessFileName, String bindAddress) throws IOException, MalformedURLException {
    /* Make sure we use non-guessable RMI object IDs.  Otherwise
         * attackers could hijack open connections by guessing their
         * IDs.  */
    System.setProperty("java.rmi.server.randomIDs", "true");
    JMXServiceURL url = new JMXServiceURL("rmi", bindAddress, rmiPort);
    Map<String, Object> env = new HashMap<>();
    PermanentExporter exporter = new PermanentExporter();
    env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);
    env.put(EnvHelp.CREDENTIAL_TYPES, new String[] { String[].class.getName(), String.class.getName() });
    boolean useSocketFactory = bindAddress != null && !useSsl;
    if (useAuthentication) {
        if (loginConfigName != null) {
            env.put("jmx.remote.x.login.config", loginConfigName);
        }
        if (passwordFileName != null) {
            env.put("jmx.remote.x.password.file", passwordFileName);
        }
        env.put("jmx.remote.x.access.file", accessFileName);
        if (env.get("jmx.remote.x.password.file") != null || env.get("jmx.remote.x.login.config") != null) {
            env.put(JMXConnectorServer.AUTHENTICATOR, new AccessFileCheckerAuthenticator(env));
        }
    }
    RMIClientSocketFactory csf = null;
    RMIServerSocketFactory ssf = null;
    if (useSsl || useRegistrySsl) {
        csf = new SslRMIClientSocketFactory();
        ssf = createSslRMIServerSocketFactory(sslConfigFileName, enabledCipherSuites, enabledProtocols, sslNeedClientAuth, bindAddress);
    }
    if (useSsl) {
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
    }
    if (useSocketFactory) {
        ssf = new HostAwareSocketFactory(bindAddress);
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
    }
    JMXConnectorServer connServer = null;
    try {
        connServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
        connServer.start();
    } catch (IOException e) {
        if (connServer == null || connServer.getAddress() == null) {
            throw new AgentConfigurationError(CONNECTOR_SERVER_IO_ERROR, e, url.toString());
        } else {
            throw new AgentConfigurationError(CONNECTOR_SERVER_IO_ERROR, e, connServer.getAddress().toString());
        }
    }
    if (useRegistrySsl) {
        registry = new SingleEntryRegistry(port, csf, ssf, "jmxrmi", exporter.firstExported);
    } else if (useSocketFactory) {
        registry = new SingleEntryRegistry(port, csf, ssf, "jmxrmi", exporter.firstExported);
    } else {
        registry = new SingleEntryRegistry(port, "jmxrmi", exporter.firstExported);
    }
    int registryPort = ((UnicastRef) ((RemoteObject) registry).getRef()).getLiveRef().getPort();
    String jmxUrlStr = String.format("service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", url.getHost(), registryPort);
    JMXServiceURL remoteURL = new JMXServiceURL(jmxUrlStr);
    return new JMXConnectorServerData(connServer, remoteURL);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) IOException(java.io.IOException) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory) JMXConnectorServer(javax.management.remote.JMXConnectorServer) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) RemoteObject(java.rmi.server.RemoteObject) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) AgentConfigurationError(sun.management.AgentConfigurationError) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) RemoteObject(java.rmi.server.RemoteObject)

Example 8 with AgentConfigurationError

use of sun.management.AgentConfigurationError in project jdk8u_jdk by JetBrains.

the class ConnectorBootstrap method startRemoteConnectorServer.

/**
     * Initializes and starts a JMX Connector Server for remote
     * monitoring and management.
     **/
public static synchronized JMXConnectorServer startRemoteConnectorServer(String portStr, Properties props) {
    // Get port number
    final int port;
    try {
        port = Integer.parseInt(portStr);
    } catch (NumberFormatException x) {
        throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT, x, portStr);
    }
    if (port < 0) {
        throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT, portStr);
    }
    // User can specify a port to be used to export rmi object,
    // in order to simplify firewall rules
    // if port is not specified random one will be allocated.
    int rmiPort = 0;
    String rmiPortStr = props.getProperty(PropertyNames.RMI_PORT);
    try {
        if (rmiPortStr != null) {
            rmiPort = Integer.parseInt(rmiPortStr);
        }
    } catch (NumberFormatException x) {
        throw new AgentConfigurationError(INVALID_JMXREMOTE_RMI_PORT, x, rmiPortStr);
    }
    if (rmiPort < 0) {
        throw new AgentConfigurationError(INVALID_JMXREMOTE_RMI_PORT, rmiPortStr);
    }
    // Do we use authentication?
    final String useAuthenticationStr = props.getProperty(PropertyNames.USE_AUTHENTICATION, DefaultValues.USE_AUTHENTICATION);
    final boolean useAuthentication = Boolean.valueOf(useAuthenticationStr).booleanValue();
    // Do we use SSL?
    final String useSslStr = props.getProperty(PropertyNames.USE_SSL, DefaultValues.USE_SSL);
    final boolean useSsl = Boolean.valueOf(useSslStr).booleanValue();
    // Do we use RMI Registry SSL?
    final String useRegistrySslStr = props.getProperty(PropertyNames.USE_REGISTRY_SSL, DefaultValues.USE_REGISTRY_SSL);
    final boolean useRegistrySsl = Boolean.valueOf(useRegistrySslStr).booleanValue();
    final String enabledCipherSuites = props.getProperty(PropertyNames.SSL_ENABLED_CIPHER_SUITES);
    String[] enabledCipherSuitesList = null;
    if (enabledCipherSuites != null) {
        StringTokenizer st = new StringTokenizer(enabledCipherSuites, ",");
        int tokens = st.countTokens();
        enabledCipherSuitesList = new String[tokens];
        for (int i = 0; i < tokens; i++) {
            enabledCipherSuitesList[i] = st.nextToken();
        }
    }
    final String enabledProtocols = props.getProperty(PropertyNames.SSL_ENABLED_PROTOCOLS);
    String[] enabledProtocolsList = null;
    if (enabledProtocols != null) {
        StringTokenizer st = new StringTokenizer(enabledProtocols, ",");
        int tokens = st.countTokens();
        enabledProtocolsList = new String[tokens];
        for (int i = 0; i < tokens; i++) {
            enabledProtocolsList[i] = st.nextToken();
        }
    }
    final String sslNeedClientAuthStr = props.getProperty(PropertyNames.SSL_NEED_CLIENT_AUTH, DefaultValues.SSL_NEED_CLIENT_AUTH);
    final boolean sslNeedClientAuth = Boolean.valueOf(sslNeedClientAuthStr).booleanValue();
    // Read SSL config file name
    final String sslConfigFileName = props.getProperty(PropertyNames.SSL_CONFIG_FILE_NAME);
    String loginConfigName = null;
    String passwordFileName = null;
    String accessFileName = null;
    // Initialize settings when authentication is active
    if (useAuthentication) {
        // Get non-default login configuration
        loginConfigName = props.getProperty(PropertyNames.LOGIN_CONFIG_NAME);
        if (loginConfigName == null) {
            // Get password file
            passwordFileName = props.getProperty(PropertyNames.PASSWORD_FILE_NAME, getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME));
            checkPasswordFile(passwordFileName);
        }
        // Get access file
        accessFileName = props.getProperty(PropertyNames.ACCESS_FILE_NAME, getDefaultFileName(DefaultValues.ACCESS_FILE_NAME));
        checkAccessFile(accessFileName);
    }
    final String bindAddress = props.getProperty(PropertyNames.HOST);
    if (log.debugOn()) {
        log.debug("startRemoteConnectorServer", Agent.getText("jmxremote.ConnectorBootstrap.starting") + "\n\t" + PropertyNames.PORT + "=" + port + (bindAddress == null ? "" : "\n\t" + PropertyNames.HOST + "=" + bindAddress) + "\n\t" + PropertyNames.RMI_PORT + "=" + rmiPort + "\n\t" + PropertyNames.USE_SSL + "=" + useSsl + "\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl + "\n\t" + PropertyNames.SSL_CONFIG_FILE_NAME + "=" + sslConfigFileName + "\n\t" + PropertyNames.SSL_ENABLED_CIPHER_SUITES + "=" + enabledCipherSuites + "\n\t" + PropertyNames.SSL_ENABLED_PROTOCOLS + "=" + enabledProtocols + "\n\t" + PropertyNames.SSL_NEED_CLIENT_AUTH + "=" + sslNeedClientAuth + "\n\t" + PropertyNames.USE_AUTHENTICATION + "=" + useAuthentication + (useAuthentication ? (loginConfigName == null ? ("\n\t" + PropertyNames.PASSWORD_FILE_NAME + "=" + passwordFileName) : ("\n\t" + PropertyNames.LOGIN_CONFIG_NAME + "=" + loginConfigName)) : "\n\t" + Agent.getText("jmxremote.ConnectorBootstrap.noAuthentication")) + (useAuthentication ? ("\n\t" + PropertyNames.ACCESS_FILE_NAME + "=" + accessFileName) : "") + "");
    }
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    JMXConnectorServer cs = null;
    JMXServiceURL url = null;
    try {
        final JMXConnectorServerData data = exportMBeanServer(mbs, port, rmiPort, useSsl, useRegistrySsl, sslConfigFileName, enabledCipherSuitesList, enabledProtocolsList, sslNeedClientAuth, useAuthentication, loginConfigName, passwordFileName, accessFileName, bindAddress);
        cs = data.jmxConnectorServer;
        url = data.jmxRemoteURL;
        log.config("startRemoteConnectorServer", Agent.getText("jmxremote.ConnectorBootstrap.ready", url.toString()));
    } catch (Exception e) {
        throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
    }
    try {
        // Export remote connector address and associated configuration
        // properties to the instrumentation buffer.
        Map<String, String> properties = new HashMap<>();
        properties.put("remoteAddress", url.toString());
        properties.put("authenticate", useAuthenticationStr);
        properties.put("ssl", useSslStr);
        properties.put("sslRegistry", useRegistrySslStr);
        properties.put("sslNeedClientAuth", sslNeedClientAuthStr);
        ConnectorAddressLink.exportRemote(properties);
    } catch (Exception e) {
        // Remote connector server started but unable to export remote
        // connector address and associated configuration properties to
        // the instrumentation buffer - non-fatal error.
        log.debug("startRemoteConnectorServer", e);
    }
    return cs;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) RemoteException(java.rmi.RemoteException) NoSuchObjectException(java.rmi.NoSuchObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JMXConnectorServer(javax.management.remote.JMXConnectorServer) StringTokenizer(java.util.StringTokenizer) AgentConfigurationError(sun.management.AgentConfigurationError) MBeanServer(javax.management.MBeanServer)

Example 9 with AgentConfigurationError

use of sun.management.AgentConfigurationError in project jdk8u_jdk by JetBrains.

the class AdaptorBootstrap method checkAclFile.

private static void checkAclFile(String aclFileName) {
    if (aclFileName == null || aclFileName.length() == 0) {
        throw new AgentConfigurationError(SNMP_ACL_FILE_NOT_SET);
    }
    final File file = new File(aclFileName);
    if (!file.exists()) {
        throw new AgentConfigurationError(SNMP_ACL_FILE_NOT_FOUND, aclFileName);
    }
    if (!file.canRead()) {
        throw new AgentConfigurationError(SNMP_ACL_FILE_NOT_READABLE, aclFileName);
    }
    FileSystem fs = FileSystem.open();
    try {
        if (fs.supportsFileSecurity(file)) {
            if (!fs.isAccessUserOnly(file)) {
                throw new AgentConfigurationError(SNMP_ACL_FILE_ACCESS_NOT_RESTRICTED, aclFileName);
            }
        }
    } catch (IOException e) {
        throw new AgentConfigurationError(SNMP_ACL_FILE_READ_FAILED, aclFileName);
    }
}
Also used : AgentConfigurationError(sun.management.AgentConfigurationError) FileSystem(sun.management.FileSystem) IOException(java.io.IOException) File(java.io.File)

Example 10 with AgentConfigurationError

use of sun.management.AgentConfigurationError in project jdk8u_jdk by JetBrains.

the class Agent method startDiscoveryService.

private static void startDiscoveryService(Properties props) throws IOException {
    // Start discovery service if requested
    String discoveryPort = props.getProperty("com.sun.management.jdp.port");
    String discoveryAddress = props.getProperty("com.sun.management.jdp.address");
    String discoveryShouldStart = props.getProperty("com.sun.management.jmxremote.autodiscovery");
    // Decide whether we should start autodicovery service.
    // To start autodiscovery following conditions should be met:
    // autodiscovery==true OR (autodicovery==null AND jdp.port != NULL)
    boolean shouldStart = false;
    if (discoveryShouldStart == null) {
        shouldStart = (discoveryPort != null);
    } else {
        try {
            shouldStart = Boolean.parseBoolean(discoveryShouldStart);
        } catch (NumberFormatException e) {
            throw new AgentConfigurationError("Couldn't parse autodiscovery argument");
        }
    }
    if (shouldStart) {
        // port and address are required arguments and have no default values
        InetAddress address;
        try {
            address = (discoveryAddress == null) ? InetAddress.getByName(JDP_DEFAULT_ADDRESS) : InetAddress.getByName(discoveryAddress);
        } catch (UnknownHostException e) {
            throw new AgentConfigurationError("Unable to broadcast to requested address", e);
        }
        int port = JDP_DEFAULT_PORT;
        if (discoveryPort != null) {
            try {
                port = Integer.parseInt(discoveryPort);
            } catch (NumberFormatException e) {
                throw new AgentConfigurationError("Couldn't parse JDP port argument");
            }
        }
        // Rebuilding service URL to broadcast it
        String jmxremotePort = props.getProperty(JMXREMOTE_PORT);
        String rmiPort = props.getProperty(RMI_PORT);
        JMXServiceURL url = jmxServer.getAddress();
        String hostname = url.getHost();
        String jmxUrlStr = (rmiPort != null) ? String.format("service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", hostname, rmiPort, hostname, jmxremotePort) : String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", hostname, jmxremotePort);
        String instanceName = props.getProperty("com.sun.management.jdp.name");
        try {
            JdpController.startDiscoveryService(address, port, instanceName, jmxUrlStr);
        } catch (JdpException e) {
            throw new AgentConfigurationError("Couldn't start JDP service", e);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) UnknownHostException(java.net.UnknownHostException) AgentConfigurationError(sun.management.AgentConfigurationError) JdpException(sun.management.jdp.JdpException) InetAddress(java.net.InetAddress)

Aggregations

AgentConfigurationError (sun.management.AgentConfigurationError)10 IOException (java.io.IOException)9 UnknownHostException (java.net.UnknownHostException)6 JMXServiceURL (javax.management.remote.JMXServiceURL)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 MalformedURLException (java.net.MalformedURLException)3 NoSuchObjectException (java.rmi.NoSuchObjectException)3 RemoteException (java.rmi.RemoteException)3 HashMap (java.util.HashMap)3 JMXConnectorServer (javax.management.remote.JMXConnectorServer)3 FileSystem (sun.management.FileSystem)3 RemoteObject (java.rmi.server.RemoteObject)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 Properties (java.util.Properties)2 MBeanServer (javax.management.MBeanServer)2 SnmpAcl (com.sun.jmx.snmp.IPAcl.SnmpAcl)1 InetAddressAcl (com.sun.jmx.snmp.InetAddressAcl)1 SnmpAdaptorServer (com.sun.jmx.snmp.daemon.SnmpAdaptorServer)1 BufferedInputStream (java.io.BufferedInputStream)1