本文整理汇总了Java中javax.management.remote.JMXAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Java JMXAuthenticator类的具体用法?Java JMXAuthenticator怎么用?Java JMXAuthenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JMXAuthenticator类属于javax.management.remote包,在下文中一共展示了JMXAuthenticator类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServerListener
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
/**
* 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);
}
示例2: authenticate
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
public Subject authenticate(Object credentials) {
final JMXAuthenticator authenticator =
new JMXPluggableAuthenticator(environment);
final Subject subject = authenticator.authenticate(credentials);
checkAccessFileEntries(subject);
return subject;
}
示例3: determineAuthenticator
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
/**
* 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();
}
示例4: ServerConnection
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
/**
* 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;
}
示例5: start
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
@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();
}
示例6: main
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
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");
}
示例7: main
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
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");
}
示例8: startJMXRmiService
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
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();
}
}
示例9: start
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
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);
}
}
示例10: start
import javax.management.remote.JMXAuthenticator; //导入依赖的package包/类
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);
}
}