Failed to authenticate
somostetoikilato May 11, 2012 9:57 AMHi,
I try to read the version from the jboss.system:type=Server MBean of a remote JBoss server (version 5).
The jmx-console authentication is set by
<application-policy name="jmx-console">
<authentication>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
flag="required">
<module-option name="usersProperties">props/jmx-console-users.properties</module-option>
<module-option name="rolesProperties">props/jmx-console-roles.properties</module-option>
</login-module>
</authentication>
</application-policy>
and in the props/jmx-console-users.properties file I enabled the admin=admin line. After restarting the
server (-c default) I can access the jmx-console and I have the version of the JBoss.
But when I try to read the same version using an external JAVA client I get the following error:
Failed to authenticate principal=null, securityDomain=jmx-console
The client used:
package sf.jboss.mbean.test;
public class Main {
public static void main(String[] args) {
RemoteJBoss rj = new RemoteJBoss("localhost", 1099, "admin", "admin");
System.out.println(rj.getVersion());
rj = null;
}
}
The RemoteJBoss class:
package sf.jboss.mbean.test;
import java.util.Properties;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class RemoteJBoss {
String mHostName = null;
int mJndiPort = 0;
String mUserName = null;
String mPassword = null;
public RemoteJBoss(String pHost, int pPort, String pUsername, String pPassword) {
this.mHostName = pHost;
this.mJndiPort = pPort;
this.mUserName = pUsername;
this.mPassword = pPassword;
}
private Context getContext() throws NamingException {
Properties oProperties = new Properties();
oProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
oProperties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
oProperties.setProperty(Context.PROVIDER_URL, String.format("jnp://%s:%d/", this.mHostName, this.mJndiPort));
oProperties.setProperty(Context.SECURITY_PRINCIPAL, this.mUserName);
oProperties.setProperty(Context.SECURITY_CREDENTIALS, this.mPassword);
oProperties.setProperty(Context.SECURITY_PROTOCOL, "java:/jaas/jmx-console");
return new InitialContext(oProperties);
}
private MBeanServerConnection getMbeanServerConnection(String pJndiName) {
MBeanServerConnection oMBeanServerConnection = null;
try {
oMBeanServerConnection = (MBeanServerConnection)this.getContext().lookup(pJndiName);
} catch (NamingException e) {
e.printStackTrace();
}
return oMBeanServerConnection;
}
public String getVersion() {
String oVersion = "NO_VERSION";
MBeanServerConnection server = this.getMbeanServerConnection("jmx/rmi/RMIAdaptor");
try {
ObjectName on = new ObjectName("jboss.system:type=Server");
oVersion = (String)server.getAttribute(on, "Version");
} catch (Exception e) {
//e.printStackTrace();
System.out.println(e.getMessage());
}
return oVersion;
}
}
Can (and would) somebody help me?
Thank you.
SK