Announcement Announcement Module
Collapse
No announcement yet.
SecurityException when remote acceding to mbean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #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");

    Comment

    Working...
    X