Java 类javax.management.remote.JMXAuthenticator 实例源码

项目:OperatieBRP    文件:ServerListener.java   
/**
 * Create a new server listener.
 * @param serverConnector connector
 * @param socketFactory socket factory
 * @param authenticator authenticator
 * @param accessController access controller
 * @param threadPriority  thread priority
 * @throws IOException if an I/O error occurs when constructing the server listener
 */
ServerListener(final ServerConnector serverConnector, final JMXSocketFactory socketFactory, final JMXAuthenticator authenticator,
               final JMXAccessController accessController, final int threadPriority) throws IOException {
    this.serverConnector = serverConnector;
    this.authenticator = authenticator;
    this.accessController = accessController;
    serverId = SERVER_ID.getAndIncrement();

    // Setup executor service
    final ThreadFactory threadFactory = new ConnectionThreadFactory(serverId, threadPriority);
    executorService = Executors.newCachedThreadPool(threadFactory);

    // Setup server socket
    serverSocket = socketFactory.createServerSocket(serverConnector.getAddress());
    serverConnector.updateAddress(serverSocket.getLocalPort());
    serverSocket.setSoTimeout(0);
}
项目:OpenJSharp    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:OperatieBRP    文件:Environment.java   
/**
 * Bepaalt de authenticator op basis van de properties.
 * @param environment De verzameling properties uit de environment
 * @return de authenticator
 */
public static JMXAuthenticator determineAuthenticator(final Map<String, ?> environment) {
    // Custom authenticator via the environment
    final JMXAuthenticator custom = (JMXAuthenticator) environment.get(KEY_AUTHENTICATOR);
    if (custom != null) {
        return custom;
    }

    // Default: no authentication
    return new StaticAuthenticator();
}
项目:OperatieBRP    文件:ServerConnection.java   
/**
 * Create a new server connection.
 * @param socket server socket to communicate via
 * @param connectionId connection id for this connection
 * @param authenticator authenticator
 * @param mBeanServer mbean server
 */
ServerConnection(final Socket socket, final String connectionId, final JMXAuthenticator authenticator,
                 final JMXAccessController accessController, final MBeanServer mBeanServer) throws IOException {
    this.socket = socket;
    this.connectionId = connectionId;
    this.authenticator = authenticator;
    this.accessController = accessController;

    // The socket InputStream and OutputStream are not closed directly. They
    // are closed via method calls on the socket itself.
    input = new MessageInputStream(socket.getInputStream());
    output = new MessageOutputStream(socket.getOutputStream());

    this.mBeanServer = mBeanServer;
}
项目:OperatieBRP    文件:ServerConnector.java   
@Override
public synchronized void start() throws IOException {
    if (serverListenerThread != null) {
        return;
    }

    final JMXSocketFactory socketFactory = Environment.determineSocketFactory(environment);
    final JMXAuthenticator authenticator = Environment.determineAuthenticator(environment);
    final JMXAccessController accessController = Environment.determineAccessController(environment);
    final int threadPriority = Environment.determineThreadPriority(environment);
    serverListener = new ServerListener(this, socketFactory, authenticator, accessController, threadPriority);
    serverListenerThread = new Thread(serverListener, "simple-jmx-server-" + serverListener.getServerId());
    serverListenerThread.setPriority(threadPriority);
    serverListenerThread.start();
}
项目:jdk8u-jdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:openjdk-jdk10    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:openjdk9    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:jdk8u_jdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:lookaside_java-1.8.0-openjdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:cacheonix-core    文件:Server.java   
public static void main(String[] args) throws Exception
{
   prepareUsersFile();

   // The address of the connector server
   JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");

   // Specify the authenticator in the environment Map, using the
   // standard property JMXConnector.AUTHENTICATOR
   Map environment = new HashMap();
   JMXAuthenticator authenticator = new PasswordAuthenticator(new File(PASSWORD_FILE));
   environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);

   // Create and register the connector server
   JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, null);
   ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol());
   MBeanServer server = MBeanServerFactory.createMBeanServer("remote.security.example");
   server.registerMBean(cntorServer, cntorServerName);

   // Setup the rmiregistry to bind in JNDI the RMIConnectorServer stub.
   NamingService naming = new NamingService();
   ObjectName namingName = ObjectName.getInstance(":service=" + NamingService.class.getName());
   server.registerMBean(naming, namingName);
   naming.start();

   // Start the connector server
   cntorServer.start();

   System.out.println("Server up and running");
}
项目:cacheonix-core    文件:Server.java   
public static void main(String[] args) throws Exception
{
   prepareUsersFile();

   // The address of the connector server
   JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");

   // Specify the authenticator in the environment Map, using the
   // standard property JMXConnector.AUTHENTICATOR
   Map environment = new HashMap();
   JMXAuthenticator authenticator = new PasswordAuthenticator(new File(PASSWORD_FILE));
   environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);

   // Create and register the connector server
   JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, null);
   ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol());
   MBeanServer server = MBeanServerFactory.createMBeanServer("remote.security.example");
   server.registerMBean(cntorServer, cntorServerName);

   // Setup the rmiregistry to bind in JNDI the RMIConnectorServer stub.
   NamingService naming = new NamingService();
   ObjectName namingName = ObjectName.getInstance(":service=" + NamingService.class.getName());
   server.registerMBean(naming, namingName);
   naming.start();

   // Setup the interception
   SubjectTrackingMBeanServer interceptor = new SubjectTrackingMBeanServer();
   cntorServer.setMBeanServerForwarder(interceptor);

   // Start the connector server
   cntorServer.start();

   System.out.println("Server up and running");
}
项目:infobip-open-jdk-8    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:jdk8u-dev-jdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:jdk7-jdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:openjdk-source-code-learn    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:OLD-OpenJDK8    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:openjdk-jdk7u-jdk    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:openjdk-icedtea7    文件:ConnectorBootstrap.java   
public Subject authenticate(Object credentials) {
    final JMXAuthenticator authenticator =
            new JMXPluggableAuthenticator(environment);
    final Subject subject = authenticator.authenticate(credentials);
    checkAccessFileEntries(subject);
    return subject;
}
项目:yajsw    文件:AbstractWrappedProcess.java   
private void startJMXRmiService()
{
    try
    {
        int port = _config.getInt("wrapper.jmx.rmi.port",
                Constants.DEFAULT_RMI_PORT);
        if (port > 0)
        {
            Registry rmiRegistry = LocateRegistry.createRegistry(port);
            JMXServiceURL url = new JMXServiceURL(
                    "service:jmx:rmi:///jndi/rmi://localhost:" + port
                            + "/server");
            Map environment = null;
            if (_config.getString("wrapper.jmx.rmi.user", null) != null)
            {
                final String myUser = _config
                        .getString("wrapper.jmx.rmi.user");
                final String myPassword = _config.getString(
                        "wrapper.jmx.rmi.password", "");
                environment = new HashMap();
                JMXAuthenticator authenticator = new JMXAuthenticator()
                {

                    public Subject authenticate(Object credentials)
                    {
                        if (!(credentials instanceof String[]))
                            throw new SecurityException("Bad credentials");
                        String[] creds = (String[]) credentials;
                        if (creds.length != 2)
                            throw new SecurityException("Bad credentials");

                        String user = creds[0];
                        String password = creds[1];

                        if (password == null)
                            password = "";

                        if (!myUser.equals(user))
                            throw new SecurityException("Unknown user "
                                    + user);
                        if (!myPassword.equals(password))
                            throw new SecurityException("Bad password");

                        Set principals = new HashSet();
                        principals.add(new JMXPrincipal(user));
                        return new Subject(true, principals,
                                Collections.EMPTY_SET,
                                Collections.EMPTY_SET);
                    }

                };
                environment.put(JMXConnectorServer.AUTHENTICATOR,
                        authenticator);
            }

            JMXConnectorServer cs = JMXConnectorServerFactory
                    .newJMXConnectorServer(url, environment, _mbeanServer);
            cs.start();

        }
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }

}
项目:Openfire    文件:JMXManager.java   
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);
        }
    }
项目:openfire    文件:JMXManager.java   
private void start() {

    setContainer(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
    getContainer().addBean(org.eclipse.jetty.util.log.Log.getLog());

    int jmxPort = JMXManager.getPort();
    String jmxUrl = "/jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
    Map<String, Object> env = new HashMap<String, Object>();
    if (JMXManager.isSecure()) {
        env.put("jmx.remote.authenticator", new JMXAuthenticator() {
            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 = (String) aCredentials[0];
                String password = (String) 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);
    }
}