<!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;">
    createTopicConnection - username, password
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/adfasdfasdfhjasdfhasddfhasdfaj">Hugo Boss</a> in <i>JBoss Messaging</i> - <a href="https://community.jboss.org/message/818006#818006">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 style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i'm using JMS to distribute messages. All worked fine (subscribing, receiving) but when i receive a message and i call a service-method i got an AuthenticationException because i'm logged in as anonymous (all services are secured).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Ok, so i need to login myself... i think there are two possibilities... just do a login before i call the service out of the onMessage-method or to create the topicConnection with username and password. But both failed... </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The programm always says something like unable to validate user: &lt;username&gt;. Here the exception:</p><p>2013-05-16 15:12:42,699 ERROR&#160; [org.hornetq.core.protocol.core.impl.HornetQPacketHandler] Failed to create session : HornetQException[errorCode=105 message=Unable to validate user: backoffice]</p><p>&#160;&#160;&#160; at org.hornetq.core.security.impl.SecurityStoreImpl.authenticate(SecurityStoreImpl.java:147)</p><p>&#160;&#160;&#160; at org.hornetq.core.server.impl.HornetQServerImpl.createSession(HornetQServerImpl.java:858)</p><p>&#160;&#160;&#160; at org.hornetq.core.protocol.core.impl.HornetQPacketHandler.handleCreateSession(HornetQPacketHandler.java:187)</p><p>&#160;&#160;&#160; at org.hornetq.core.protocol.core.impl.HornetQPacketHandler.handlePacket(HornetQPacketHandler.java:85)</p><p>&#160;&#160;&#160; at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:508)</p><p>&#160;&#160;&#160; at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:556)</p><p>&#160;&#160;&#160; at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:517)</p><p>&#160;&#160;&#160; at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:534)</p><p>&#160;&#160;&#160; at org.hornetq.core.remoting.impl.invm.InVMConnection$1.run(InVMConnection.java:169)</p><p>&#160;&#160;&#160; at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100)</p><p>&#160;&#160;&#160; at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)</p><p>&#160;&#160;&#160; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)</p><p>&#160;&#160;&#160; at java.lang.Thread.run(Thread.java:722)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I don't know where jBoss is looking for the user, because the user exists (in the database) and the remote login from the clients works with this user.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here the source of the creating of the connection to jms:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public void start(InitialContext iniCtx) throws NamingException, JMSException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Object tmp = iniCtx.lookup("ConnectionFactory");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tConn = tcf.createTopicConnection(USERNAME, PASSWORD);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //tConn = tcf.createTopicConnection();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tConn.setClientID(this.getClass().getName());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; topic = (Topic) iniCtx.lookup(getTopicName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tSession = tConn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // subscriber = tSession.createDurableSubscriber(topic, getSubscriptionName(), getJMSTypeString(), false);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; subscriber = tSession.createSubscriber(topic, getJMSTypeString(), true);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; subscriber.setMessageListener(this);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tConn.start();</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here the login variant, but doesn't work either:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>protected void login() throws LoginException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginContext loginContext = new LoginContext("backofficexyz", new MyLoginCallBackHandler());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; loginContext.login();</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>private class BemaLoginCallBackHandler implements CallbackHandler {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160; @Override</p><p>&#160;&#160;&#160; public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (int i = 0; i &lt; callbacks.length; i++) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (callbacks[i] instanceof TextOutputCallback) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextOutputCallback toc = (TextOutputCallback) callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch (toc.getMessageType()) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.INFORMATION:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.info(toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.ERROR:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.error(toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case TextOutputCallback.WARNING:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.warn(toc.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; default:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new IOException("Unsupported message type: " + toc.getMessageType());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else if (callbacks[i] instanceof NameCallback) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NameCallback nc = (NameCallback) callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; nc.setName(USERNAME);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else if (callbacks[i] instanceof PasswordCallback) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PasswordCallback pc = (PasswordCallback) callbacks[i];</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pc.setPassword(PASSWORD.toCharArray());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Anybody an idea? JBoss Version is jBoss 7.1.4</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/818006#818006">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Messaging at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>