-
Oct 10th, 2006, 07:16 AM
#1
SecurityException when remote acceding to mbean
I have an application deployed in the OC4J 10.1.3 and its starts a JMX server using Spring 1.2.7 and publish a class. The application-context xml file is:
<!-- start a JMX Server -->
<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServer FactoryBean">
<property name="defaultDomain">
<value>t2aMBeanService</value>
</property>
</bean>
<bean id="rmiRegistry"
class="org.springframework.remoting.rmi.RmiRegistr yFactoryBean" />
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorSe rverFactoryBean"
depends-on="rmiRegistry">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/monitorConnector" />
</bean>
<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporte r">
<property name="beans">
<map>
<entry key="MyApp:MBean=monitor">
<ref bean="monitorData" />
</entry>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.In terfaceBasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>
com.monitoring.MonitorDataMBean
</value>
</property>
</bean>
</property>
</bean>
In the console i can see the mbean and if i using the following code in an standalone class I can connect and obtain de value of the attributes published.
remoteMBeanName = new ObjectName(serverMonitorBean);
Map environment = new HashMap();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory" );
environment.put(Context.PROVIDER_URL, "rmi://localhost:1099");
url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/monitorConnector");
c = JMXConnectorFactory.connect(url, environment);
proxy = new RemoteMBeanProxy(remoteMBeanName, c.getMBeanServerConnection());
proxyName = new ObjectName("Synthesis:MBean=monitor");
gatheringMBeanServer = MBeanServerFactory.createMBeanServer();
gatheringMBeanServer.registerMBean(proxy, proxyName);
Object o = gatheringMBeanServer.getAttribute(proxyName, "Receiving")
The problem occur when i run the code in another application deployed in the same OC4J. I can connect, but and exception occur in the registration of the remoteMbean:
gatheringMBeanServer.registerMBean(proxy, proxyName);
The exception is:
java.lang.SecurityException: Unauthorized access from application: console to MBean: MyApp:MBean=MyMonitor
I added to the code the credentials to connect but i obtain the same exception
Hashtable credentials= new Hashtable();
credentials.put("login","oc4jadmin");
credentials.put("password","welcome");
environment.put(JMXConnector.CREDENTIALS, credentials);
How can i resolve this issue?
-
Oct 10th, 2006, 08:38 AM
#2
Solution
This is the solution:
url = new JMXServiceURL("service:jmx:rmi://localhost:23791/oc4j/MyApp");
Hashtable env = new Hashtable();
Hashtable credentials = new Hashtable();
credentials.put("login", "oc4jadmin");
credentials.put("password", "welcome");
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACK AGES, "oracle.oc4j.admin.jmx.remote");
env.put(JMXConnector.CREDENTIALS, credentials);
connector = JMXConnectorFactory.newJMXConnector(url, env);
connector.connect();
//Retrieve the MBeanServerConnection instance that acts as a proxy
//for the OC4J MBeanServer we are connecting to.
MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
proxyName = new ObjectName("MyApp:MBean=MyMonitor");
MBeanInfo object222 = mBeanServerConnection.getMBeanInfo(proxyName);
mBeanServerConnection.getAttribute(proxyName,"Rece iving");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules