<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Connecting to secured JMX MBeans
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/apinke">Amit P</a> in <i>JMX Development</i> - <a href="http://community.jboss.org/message/534104#534104">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi ,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have to access certain MBeans that secured by basic auth on jmx-console. I can access them using a standalone client as decribed</p><p>here : <a class="jive-link-external-small" href="http://www.len.ro/2006/12/jmx-invocation-with-secured-console/">http://www.len.ro/2006/12/jmx-invocation-with-secured-console/</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here is how it has worked for me till now :</p><p>I have a standalone java client&#160; that I start up with a -D<span style="color: #2a00ff; font-size: 10pt; ">java.security.auth.login.config=&lt;path_to_auth_conf&gt;</span></p><p><span style="color: #2a00ff; font-size: 10pt; ">The auth.conf has no new entires and its the default one that is present in the default/conf</span></p><p><span style="color: #2a00ff; font-size: 10pt; ">I create the CallBackHandler with the user and pwd and set the LoginContext</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 10pt;"><p>LoginContext lc = <strong><span style="color: #7f0055; font-size: 10pt; ">new</span><span style="font-size: 10pt;"> LoginContext(</span><span style="color: #2a00ff; font-size: 10pt; ">"jmx-console"</span><span style="font-size: 10pt;">, handler); //have tried "other" also .</span></strong></p><p><span style="font-size: 10pt;"><p>lc.<span style="text-decoration: underline;">login</span>();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style=": ; font-size: 2; "><p align="left"><span style="text-decoration: underline;">Hashtable</span> env =</p></span><p align="left"><strong style=": ; color: #7f0055; font-size: 10pt; ">new</strong><span style="font-size: 10pt;"> <span style="text-decoration: underline;">Hashtable</span>();<span style="font-size: 2; "><p align="left">String factory = "</p></span></span></p><p align="left"><span style="color: #2a00ff; font-size: 10pt; ">org.jnp.interfaces.NamingContextFactory"</span><span style="font-size: 10pt;">;<span style="font-size: 2; "><p align="left"><span style="text-decoration: underline;">env.put(Context.</span></p></span></span></p><p align="left"><em style=": ; color: #0000c0; font-size: 10pt; ">INITIAL_CONTEXT_FACTORY</em><span style="font-size: 10pt; text-decoration: underline; ">, factory);<span style="font-size: 2; "><p align="left"><span style="text-decoration: underline;">env.put(Context.</span></p></span></span></p><p align="left"><em style=": ; color: #0000c0; font-size: 10pt; ">PROVIDER_URL</em><span style="font-size: 10pt;">, </span><span style="color: #0000c0; font-size: 10pt; ">jndiUrl</span><span style="font-size: 10pt; text-decoration: underline; ">);<span style="font-size: 2; "><p align="left"><span style="text-decoration: underline;">env.put(Context.</span></p></span></span></p><p align="left"><em style=": ; color: #0000c0; font-size: 10pt; ">SECURITY_CREDENTIALS</em><span style="font-size: 10pt;">, </span><span style="color: #0000c0; font-size: 10pt; ">pw</span><span style="font-size: 10pt; text-decoration: underline; ">);<span style="font-size: 2; "><p align="left"><span style="text-decoration: underline;">env.put(Context.</span></p></span></span></p><p align="left"><em style=": ; color: #0000c0; font-size: 10pt; ">SECURITY_PRINCIPAL</em><span style="font-size: 10pt;">, </span><span style="color: #0000c0; font-size: 10pt; ">userId</span><span style="font-size: 10pt; text-decoration: underline; ">);<span style="font-size: 2; "><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span></span></p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><span style=": ; font-size: 2; "><p align="left">Context ctx =</p></span><p align="left"><strong style=": ; color: #7f0055; font-size: 10pt; ">new</strong><span style="font-size: 10pt;"> InitialContext(env);<p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><span style="font-size: 2; "><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="color: #0000c0; font-size: 10pt; ">mbeanServer</span><span style="font-size: 10pt;"> = (MBeanServerConnection) ctx.lookup(</span><span style="color: #2a00ff; font-size: 10pt; ">"jmx/invoker/RMIAdaptor"</span><span style="font-size: 10pt;">);<br/></span></p><p><span style="font-size: 10pt;">Using the above I am able to connect.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 10pt;">When I try the *same* code from within a servlet&#160; it doesnt work. </span></p><p><span style="font-size: 10pt;">I get a principal=null for the domain error , which I think indicates that the user credentials are not getting passed.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 10pt;">Is there any other setting that i have to do in order to connect to a secured JMX server from *within* another JBOSS server ?</span></p><p><span style="font-size: 10pt;">Any changes in user.properties , role.properties ? , any change in the auth-conf ? </span></p><p><span style="font-size: 10pt;">I dont know what changes to make to my local JBoss instance so that the servlet deployed in it can talk to remote JMX MBeans,</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 10pt;">Any guidance and hints are highly appreciated !!</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 10pt;">thanks</span></p><p><span style="font-size: 10pt;">Pat</span></p></p></span></p><span style="font-size: 2; "><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span></span></p><p><span style="color: #2a00ff; font-size: 10pt; "><p><span style="color: #2a00ff; font-size: 10pt; "><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span></p></span></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/534104#534104">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JMX Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2105">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>