Search in sources :

Example 31 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project vespa by vespa-engine.

the class JettyHttpServer method setupJmx.

private static void setupJmx(Server server, ServerConfig serverConfig) {
    if (serverConfig.jmx().enabled()) {
        System.setProperty("java.rmi.server.hostname", "localhost");
        server.addBean(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
        server.addBean(new ConnectorServer(createJmxLoopbackOnlyServiceUrl(serverConfig.jmx().listenPort()), "org.eclipse.jetty.jmx:name=rmiconnectorserver"));
    }
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Example 32 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project cia by Hack23.

the class CitizenIntelligenceAgencyServer method init.

/**
 * Inits the.
 *
 * @throws Exception
 *             the exception
 */
public final void init() throws Exception {
    initialised = true;
    server = new Server();
    Security.addProvider(new BouncyCastleProvider());
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    final HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(28443);
    final HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStorePath("target/keystore.jks");
    sslContextFactory.setTrustStorePath("target/keystore.jks");
    sslContextFactory.setKeyStorePassword("changeit");
    sslContextFactory.setTrustStorePassword("changeit");
    sslContextFactory.setKeyManagerPassword("changeit");
    sslContextFactory.setCertAlias("jetty");
    sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
    sslContextFactory.setIncludeProtocols("TLSv1.2");
    final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
    sslConnector.setPort(PORT);
    server.setConnectors(new ServerConnector[] { sslConnector });
    final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
    handler.setExtraClasspath("target/classes");
    handler.setParentLoaderPriority(true);
    handler.setConfigurationDiscovered(true);
    handler.setClassLoader(Thread.currentThread().getContextClassLoader());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 33 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project Openfire by igniterealtime.

the class JMXManager method start.

private void start() {
    setContainer(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
    int jmxPort = JMXManager.getPort();
    String jmxUrl = "/jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
    Map<String, Object> env = new HashMap<>();
    if (JMXManager.isSecure()) {
        env.put("jmx.remote.authenticator", new JMXAuthenticator() {

            @Override
            public Subject authenticate(Object credentials) {
                if (!(credentials instanceof String[])) {
                    if (credentials == null) {
                        throw new SecurityException("Credentials required");
                    }
                    throw new SecurityException("Credentials should be String[]");
                }
                final String[] aCredentials = (String[]) credentials;
                if (aCredentials.length < 2) {
                    throw new SecurityException("Credentials should have at least two elements");
                }
                String username = aCredentials[0];
                String password = aCredentials[1];
                try {
                    AuthFactory.authenticate(username, password);
                } catch (Exception ex) {
                    Log.error("Authentication failed for " + username);
                    throw new SecurityException();
                }
                if (AdminManager.getInstance().isUserAdmin(username, true)) {
                    return new Subject(true, Collections.singleton(new JMXPrincipal(username)), Collections.EMPTY_SET, Collections.EMPTY_SET);
                } else {
                    Log.error("Authorization failed for " + username);
                    throw new SecurityException();
                }
            }
        });
    }
    try {
        jmxServer = new ConnectorServer(new JMXServiceURL("rmi", null, jmxPort, jmxUrl), env, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
        jmxServer.start();
    } catch (Exception e) {
        Log.error("Failed to start JMX connector", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXAuthenticator(javax.management.remote.JMXAuthenticator) JMXPrincipal(javax.management.remote.JMXPrincipal) Subject(javax.security.auth.Subject) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Example 34 with MBeanContainer

use of org.eclipse.jetty.jmx.MBeanContainer in project killbill by killbill.

the class HttpServer method configureJMX.

private void configureJMX(final MBeanServer mbeanServer) {
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(mbeanServer);
    server.addBean(mbContainer);
    // Add loggers MBean to server (will be picked up by MBeanContainer above)
    server.addBean(Log.getLogger(HttpServer.class));
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer)

Aggregations

MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)34 Server (org.eclipse.jetty.server.Server)21 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)11 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)10 MBeanServer (javax.management.MBeanServer)9 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)9 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)9 File (java.io.File)8 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)8 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)7 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 ConnectorServer (org.eclipse.jetty.jmx.ConnectorServer)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 JMXServiceURL (javax.management.remote.JMXServiceURL)4 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 Connector (org.eclipse.jetty.server.Connector)3 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)3