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();
}
}
AbstractWrappedProcess.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:yajsw
作者:
评论列表
文章目录