<!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="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss 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;">
Remote EJB/JMS JBoss AS 7.1.1 problem
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/brunothebear">brunothebear</a> in <i>JBoss AS 7 Development</i> - <a href="https://community.jboss.org/message/779066#779066">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello,</p><p>Past couple of weeks ive been trying to migrate project from JBoss 4.2.2GA to JBoss 7 AS. Everything went pretty much fine till i hit the remoting part on which I've stuck for a quite time now.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In JBoss 4.2.2 project uses custom login module to authenticate remote calls.</p><p>The promblem is that i have trouble to get the username/password to the server so the user can eb authenticated.</p><p>Ive somewhat sorted otu the EJB invocation and i do it like this.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>standalone.xml</p><pre class="jive-pre"><code class="jive-code jive-xml"> <span class="jive-xml-tag"><security-realms></span>
         ...
            <span class="jive-xml-tag"><security-realm name="TESTRealm"></span>
                <span class="jive-xml-tag"><authentication></span>
                    <span class="jive-xml-tag"><jaas name="testdomain"/></span>
                <span class="jive-xml-tag"></authentication></span>
            <span class="jive-xml-tag"></security-realm></span>
        <span class="jive-xml-tag"></security-realms></span>
....
        <span class="jive-xml-tag"><subsystem xmlns="urn:jboss:domain:remoting:1.1"></span>
            <span class="jive-xml-tag"><connector name="remoting-connector" socket-binding="remoting" security-realm="TESTRealm"/></span>
        <span class="jive-xml-tag"></subsystem></span>
<span class="jive-xml-tag"><subsystem xmlns="urn:jboss:domain:security:1.1"></span>
            <span class="jive-xml-tag"><security-domains></span>
                <span class="jive-xml-tag"><security-domain name="other"></span>
                    <span class="jive-xml-tag"><authentication></span>
                        <span class="jive-xml-tag"><login-module code="UsersRoles" flag="required"/></span>
                    <span class="jive-xml-tag"></authentication></span>
                <span class="jive-xml-tag"></security-domain></span>
                <span class="jive-xml-tag"><security-domain name="jboss-web-policy"></span>
                    <span class="jive-xml-tag"><authorization></span>
                        <span class="jive-xml-tag"><policy-module code="Delegating" flag="required"/></span>
                    <span class="jive-xml-tag"></authorization></span>
                <span class="jive-xml-tag"></security-domain></span>
                <span class="jive-xml-tag"><security-domain name="jboss-ejb-policy"></span>
                    <span class="jive-xml-tag"><authorization></span>
                        <span class="jive-xml-tag"><policy-module code="Delegating" flag="required"/></span>
                    <span class="jive-xml-tag"></authorization></span>
                <span class="jive-xml-tag"></security-domain></span>
                <span class="jive-xml-tag"><security-domain name="testdomain"></span>
                    <span class="jive-xml-tag"><authentication></span>
                        <span class="jive-xml-tag"><login-module code="com.test.proj.CustomLoginModule" flag="required"></span>
                            <span class="jive-xml-tag"><module-option name="password-stacking" value="useFirstPass"/></span>
                            <span class="jive-xml-tag"><module-option name="hashAlgorithm" value="MD5"/></span>
                            <span class="jive-xml-tag"><module-option name="hashEncoding" value="hex"/></span>
                            <span class="jive-xml-tag"><module-option name="ignorePasswordCase" value="true"/></span>
                        <span class="jive-xml-tag"></login-module></span>
                    <span class="jive-xml-tag"></authentication></span>
                <span class="jive-xml-tag"></security-domain></span>
            <span class="jive-xml-tag"></security-domains></span>
        <span class="jive-xml-tag"></subsystem></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Client part:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">                Hashtable< String, Object>props = <font color="navy"><b>new</b></font> Hashtable< String, Object>();
                props.put(<font color="red">"jboss.naming.client.ejb.context"</font>, <font color="navy"><b>true</b></font>);
                props.put(Context.URL_PKG_PREFIXES, <font color="red">"org.jboss.ejb.client.naming"</font>);
                <font color="navy"><b>final</b></font> String firstPassword = <font color="navy"><b>new</b></font> String(password);
                org.jboss.as.naming.InitialContext  ctx = <font color="navy"><b>new</b></font> org.jboss.as.naming.InitialContext();
                Properties jbossProperties = <font color="navy"><b>new</b></font> Properties();
                jbossProperties.load(EjbSupportImpl.class.getResourceAsStream(<font color="red">"/jboss-ejb-client.properties"</font>));
                jbossProperties.put(<font color="red">"remote.connection.default.username"</font>, name);
                jbossProperties.put(<font color="red">"remote.connection.default.password"</font>, firstPassword);
 
 
                <font color="navy"><b>final</b></font> EJBClientConfiguration ejbClientConfiguration = <font color="navy"><b>new</b></font> PropertiesBasedEJBClientConfiguration(jbossProperties);
                <font color="navy"><b>final</b></font> ContextSelector<EJBClientContext> ejbClientContextSelector = <font color="navy"><b>new</b></font> ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
                EJBClientContext.setSelector(ejbClientContextSelector);
                <font color="navy"><b>final</b></font> String jndiName = <font color="red">"ejb:ear/ejb-module/TestBean!com.test.proj.TestBean?stateful"</font>;
                <font color="navy"><b>final</b></font> Object o = ctx.lookup(jndiName);
               TestBean test= (TestBean) o;
                test.testMethod();
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>jboss-ejb-client-properties:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=true
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>With all the above everything works fine, the part that bothers me is this</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">                org.jboss.as.naming.InitialContext  ctx = <font color="navy"><b>new</b></font> org.jboss.as.naming.InitialContext();
</code></pre><p>if i use javax.naming.InitialContext instead of JBoss</p><p>i get</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed]
          at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
          at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
          at javax.naming.InitialContext.init(InitialContext.java:223)
          at javax.naming.InitialContext.<init>(InitialContext.java:197)
          at com.point_fi.tms.client.communication.EjbSupport.newInitialContext(EjbSupport.java:162)
          at com.point_fi.tms.client.communication.EjbSupportImpl$MyLoginService.authenticate(EjbSupportImpl.java:243)
          at com.point_fi.tms.client.communication.EjbSupportImpl.login(EjbSupportImpl.java:179)
          at com.point_fi.tms.client.communication.EjbSupportImpl.getInstance(EjbSupportImpl.java:64)
          at com.point_fi.tms.client.Application.<init>(Application.java:35)
          at com.point_fi.tms.client.Application.getInstance(Application.java:59)
          at com.point_fi.tms.client.TMSClient.main(TMSClient.java:51)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
          at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:87)
          at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
          at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
          at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
          at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
          ... 16 more
 
</code></pre><p>no errors on serverside.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Anyways im ok with using method above for EJBs but then the problem comes with remote JMS where i cant acquire the connection factory i require from server via JNDI</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Connection factory in standalone.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml">                    <span class="jive-xml-tag"><connection-factory name="RemoteConnectionFactory"></span>
                        <span class="jive-xml-tag"><connectors></span>
                            <span class="jive-xml-tag"><connector-ref connector-name="netty"/></span>
                        <span class="jive-xml-tag"></connectors></span>
                        <span class="jive-xml-tag"><entries></span>
                            <span class="jive-xml-tag"><entry name="RemoteConnectionFactory"/></span>
                            <span class="jive-xml-tag"><entry name="java:jboss/exported/jms/RemoteConnectionFactory"/></span>
                        <span class="jive-xml-tag"></entries></span>
                    <span class="jive-xml-tag"></connection-factory></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>and the way i trie to look it up</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">                Hashtable<String, Object> env = <font color="navy"><b>new</b></font> Hashtable<String, Object>();
            env.put(Context.INITIAL_CONTEXT_FACTORY,<font color="red">"org.jboss.naming.remote.client.InitialContextFactory"</font>);
            env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL,<font color="red">"remote://localhost:4447"</font>));
            env.put(Context.SECURITY_PRINCIPAL, <font color="red">"test"</font>);
            env.put(Context.SECURITY_CREDENTIALS, <font color="red">"123456"</font>);
            InitialContext ctx = <font color="navy"><b>new</b></font> InitialContext(env);
            String connectionFactoryString = <font color="red">"jms/RemoteConnectionFactory"</font>;
            ConnectionFactoryconnectionFactory = (ConnectionFactory) ctx.lookup(connectionFactoryString);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In which case im getting exception like the one above</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed]
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Can anyone help me figure out how to properly get the ConnectionFactories/queues etc.. via remote JDNI?</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/779066#779066">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS 7 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>