<!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;">
ClassNotFoundException on Context.lookup() after login with custom Principal
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/ozay">Ozan Ayyüce</a> in <i>JNDI and Naming</i> - <a href="https://community.jboss.org/message/647666#647666">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;"> </p><p>we have a client-server-setup and are migrating to AS 6.1.0. Unfortunately, a JNDI lookup fails with a ClassNotFoundException as root cause.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Previously, we had extended SimplePrincipal to add some fields. In our client, we use the LoginContext with a custom password handler to authenticate at the AS.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">handler = <font color="navy"><b>new</b></font> CustomUserPasswordHandler(user, pwd, mandatorID);
 
<font color="navy"><b>final</b></font> LoginContext loginContext = <font color="navy"><b>new</b></font> LoginContext(LOGIN_CONFIGURATION, handler);
 
<font color="navy"><b>try</b></font>
<font color="navy">{</font>
    loginContext.login();
<font color="navy">}</font>
<font color="navy"><b>catch</b></font> (<font color="navy"><b>final</b></font> LoginException ex)
<font color="navy">{</font>
    <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> IllegalStateException(<font color="red">"Could not initialize clients login module: "</font> + ex);
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>the client auth.conf specifies a custom login module:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">client-login <font color="navy">{</font>
   
    de.xxx.xxx.secure.CustomClientLoginModule required
    ;
    org.jboss.security.ClientLoginModule  required
    password-stacking=<font color="red">"useFirstPass"</font>
    ;
<font color="navy">}</font>;
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Our custom login module creates our custom Principal:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Override
<font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> login() <font color="navy"><b>throws</b></font> LoginException
<font color="navy">{</font>
    loginFailed = <font color="navy"><b>true</b></font>;
 
    getUserInfo();
 
    loginPrincipal = <font color="navy"><b>new</b></font> CustomPrincipal(mandator, customAttr, username);
 
    sharedState.put(<font color="red">"javax.security.auth.login.name"</font>, loginPrincipal);
    sharedState.put(<font color="red">"javax.security.auth.login.password"</font>, loginCredential);
 
    loginFailed = <font color="navy"><b>false</b></font>;
    <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>After login, any call to Context.lookup() results in a ServiceUnavailableException:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">     theNewsTopic = (Topic) ctx.lookup(Names.JMS_TOPIC_UPDATE_USER)
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code"> javax.naming.ServiceUnavailableException: Unexpected failure [Root exception is java.lang.ClassNotFoundException: de.xxx.xxx.secure.CustomPrincipal]
17:52:58,299 ERROR [STDERR]     at org.jboss.naming.interceptors.ExceptionInterceptor.invoke(ExceptionInterceptor.java:71)
17:52:58,299 ERROR [STDERR]     at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:68)
17:52:58,299 ERROR [STDERR]     at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:74)
17:52:58,299 ERROR [STDERR]     at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:101)
17:52:58,299 ERROR [STDERR]     at $Proxy0.lookup(Unknown Source)
17:52:58,299 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)
17:52:58,299 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
17:52:58,299 ERROR [STDERR]     at javax.naming.InitialContext.lookup(InitialContext.java:392)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.jms.JMSConsumer.getTopic(JMSConsumer.java:143)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.jms.JMSConsumer.initTopic(JMSConsumer.java:193)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.jms.JMSConsumer.<init>(JMSConsumer.java:120)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.jms.UpdateConsumer.<init>(UpdateConsumer.java:97)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.RemoteClient$Consumer.initRemoteMessageConsumers(RemoteClient.java:266)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.InitThread.initUpdateFramework(InitThread.java:165)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.InitThread.loadData(InitThread.java:178)
17:52:58,299 ERROR [STDERR]     at de.xxx.xxx.client.InitThread.run(InitThread.java:296)
17:52:58,299 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: de.xxx.xxx.secure.CustomPrincipal
17:52:58,299 ERROR [STDERR]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
17:52:58,299 ERROR [STDERR]     at java.security.AccessController.doPrivileged(Native Method)
17:52:58,299 ERROR [STDERR]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
17:52:58,299 ERROR [STDERR]     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
17:52:58,299 ERROR [STDERR]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
17:52:58,299 ERROR [STDERR]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
17:52:58,299 ERROR [STDERR]     at java.lang.Class.forName0(Native Method)
17:52:58,299 ERROR [STDERR]     at java.lang.Class.forName(Class.java:247)
17:52:58,299 ERROR [STDERR]     at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:304)
17:52:58,299 ERROR [STDERR]     at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1172)
17:52:58,299 ERROR [STDERR]     at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:886)
17:52:58,299 ERROR [STDERR]     at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:505)
17:52:58,299 ERROR [STDERR]     at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:450)
17:52:58,299 ERROR [STDERR]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
17:52:58,299 ERROR [STDERR]     at java.lang.Class.forName0(Native Method)
17:52:58,299 ERROR [STDERR]     at java.lang.Class.forName(Class.java:247)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
17:52:58,299 ERROR [STDERR]     at org.jboss.invocation.MarshalledInvocation.readExternal(MarshalledInvocation.java:665)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
17:52:58,299 ERROR [STDERR]     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
17:52:58,299 ERROR [STDERR]     at org.jboss.invocation.http.servlet.InvokerServlet.processRequest(InvokerServlet.java:137)
17:52:58,299 ERROR [STDERR]     at org.jboss.invocation.http.servlet.InvokerServlet.doPost(InvokerServlet.java:232)
17:52:58,299 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
17:52:58,299 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
17:52:58,299 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
17:52:58,299 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
17:52:58,299 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
17:52:58,299 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
17:52:58,299 ERROR [STDERR]     at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
17:52:58,299 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
17:52:58,299 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
17:52:58,299 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
17:52:58,299 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
17:52:58,299 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:662)
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>When the lookup() call is made before LoginContext.login() was run, the queried JNDI entry is returned like expected:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>try</b></font>
<font color="navy">{</font>
    Topic theNewsTopic = (Topic) ClientLookup.getInitialContext().lookup(Names.JMS_TOPIC_UPDATE_USER);
    String string = theNewsTopic.toString();
<font color="navy">}</font>
<font color="navy"><b>catch</b></font> (NamingException e)
<font color="navy">{</font>
    <font color="darkgreen">// no error happens here</font>
    LOG.error(<font color="red">"Your log-message: "</font>, e);
<font color="navy">}</font>
 
<font color="navy"><b>final</b></font> LoginContext loginContext = <font color="navy"><b>new</b></font> LoginContext(LOGIN_CONFIGURATION, handler);
 
loginContext.login();
 
<font color="navy"><b>try</b></font>
<font color="navy">{</font>
    Topic theNewsTopic = (Topic) ClientLookup.getInitialContext().lookup(Names.JMS_TOPIC_UPDATE_USER);
    String string = theNewsTopic.toString();
<font color="navy">}</font>
<font color="navy"><b>catch</b></font> (NamingException e)
<font color="navy">{</font>
    <font color="darkgreen">// fails with ServiceUnavailableException: Unexpected failure [Root exception is java.lang.ClassNotFoundException de.xxx.xxx.secure.CustomPrincipal]</font>
    LOG.error(<font color="red">"Your log-message: "</font>, e);
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Needless to say, CustomPrincipal is in the classpath, and is created once when the login call is made.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Any advice would be very helpful as we are out of ideas on how to narrow the error down.</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/647666#647666">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>