<!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;">
    Re: ClassCastException
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/hnb">Pierre Guillemot</a> in <i>Datasource Configuration</i> - <a href="https://community.jboss.org/message/717296#717296">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>It's me again, i am still facing the same issue while trying to implement a secure domain for my application :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml">20:34:55,853 TRACE [org.jboss.security.SecurityRolesAssociation] Setting threadlocal:{}
20:34:55,863 DEBUG [org.jboss.security.integration.JNDIBasedSecurityManagement] Creating SDC for domain=youfoodinc_domain
20:34:55,864 TRACE [org.jboss.security.plugins.JaasSecurityManager] Constructing
20:34:55,864 DEBUG [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] CallbackHandler: org.jboss.security.auth.callback.JBossCallbackHandler@174e5edb
20:34:55,864 DEBUG [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] CachePolicy set to: org.jboss.security.auth.AuthenticationTimedCachePolicy@6edc77c4
20:34:55,995 DEBUG [org.jboss.security.integration.JNDIBasedSecurityManagement] setCachePolicy, c=org.jboss.security.auth.AuthenticationTimedCachePolicy@6edc77c4
20:34:55,997 TRACE [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] Begin isValid, principal:test@test.fr, cache info: null
20:34:55,997 TRACE [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] defaultLogin, principal=test@test.fr
20:34:55,998 TRACE [org.jboss.security.auth.login.XMLLoginConfigImpl] Begin getAppConfigurationEntry(youfoodinc_domain), size=12
20:34:56,050 TRACE [org.jboss.security.auth.login.XMLLoginConfigImpl] End getAppConfigurationEntry(youfoodinc_domain), authInfo=AppConfigurationEntry[]:
[0]
LoginModule Class: org.jboss.security.auth.spi.DatabaseServerLoginModule
ControlFlag: LoginModuleControlFlag : required
Options:
name=principalsQuery, value=SELECT password FROM _user WHERE email='test@test.fr'
name=dsJndiName, value=java:/MySqlDs
name=rolesQuery, value=SELECT _role, 'Roles' FROM _user WHERE email='test@test.fr'

20:34:56,058 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] initialize
20:34:56,099 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] Security domain: youfoodinc_domain
20:34:56,099 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] DatabaseServerLoginModule, dsJndiName=java:/MySqlDs
20:34:56,099 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] principalsQuery=SELECT password FROM _user WHERE email='test@test.fr'
20:34:56,100 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] rolesQuery=SELECT _role, 'Roles' FROM _user WHERE email='test@test.fr'
20:34:56,149 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] suspendResume=true
20:34:56,151 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] login
20:34:56,152 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] suspendAnyTransaction
20:34:56,153 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] resumeAnyTransaction
20:34:56,154 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] abort
20:34:56,155 TRACE [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] Login failure: javax.security.auth.login.LoginException: java.lang.ClassCastException: org.jboss.jpa.injection.InjectedEntityManagerFactory cannot be cast to javax.sql.DataSource
&#160;&#160;&#160; at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:172)
&#160;&#160;&#160; at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:245)
&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
&#160;&#160;&#160; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
&#160;&#160;&#160; at java.lang.reflect.Method.invoke(Method.java:597)
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
&#160;&#160;&#160; at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
&#160;&#160;&#160; at java.security.AccessController.doPrivileged(Native Method)
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.defaultLogin(JaasSecurityManagerBase.java:553)
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.authenticate(JaasSecurityManagerBase.java:487)
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.isValid(JaasSecurityManagerBase.java:365)
&#160;&#160;&#160; at org.jboss.security.plugins.JaasSecurityManager.isValid(JaasSecurityManager.java:160)
&#160;&#160;&#160; at org.jboss.web.tomcat.security.JBossWebRealm.authenticate(JBossWebRealm.java:399)
&#160;&#160;&#160; at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:256)
&#160;&#160;&#160; at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:485)
&#160;&#160;&#160; at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
&#160;&#160;&#160; at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
&#160;&#160;&#160; at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
&#160;&#160;&#160; at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
&#160;&#160;&#160; at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
&#160;&#160;&#160; at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
&#160;&#160;&#160; at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
&#160;&#160;&#160; at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
&#160;&#160;&#160; at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
&#160;&#160;&#160; at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
&#160;&#160;&#160; at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
&#160;&#160;&#160; at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
&#160;&#160;&#160; at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
&#160;&#160;&#160; at java.lang.Thread.run(Thread.java:662)

&#160;&#160;&#160; at javax.security.auth.login.LoginContext.invoke(LoginContext.java:872) [:1.6.0_31]
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186) [:1.6.0_31]
&#160;&#160;&#160; at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683) [:1.6.0_31]
&#160;&#160;&#160; at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_31]
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680) [:1.6.0_31]
&#160;&#160;&#160; at javax.security.auth.login.LoginContext.login(LoginContext.java:579) [:1.6.0_31]
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.defaultLogin(JaasSecurityManagerBase.java:553) [:3.0.0.CR2]
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.authenticate(JaasSecurityManagerBase.java:487) [:3.0.0.CR2]
&#160;&#160;&#160; at org.jboss.security.plugins.auth.JaasSecurityManagerBase.isValid(JaasSecurityManagerBase.java:365) [:3.0.0.CR2]
&#160;&#160;&#160; at org.jboss.security.plugins.JaasSecurityManager.isValid(JaasSecurityManager.java:160) [:6.0.0.Final]
&#160;&#160;&#160; at org.jboss.web.tomcat.security.JBossWebRealm.authenticate(JBossWebRealm.java:399) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:256) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:485) [:6.0.0.Final]
&#160;&#160;&#160; at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
&#160;&#160;&#160; at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
&#160;&#160;&#160; at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
&#160;&#160;&#160; at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
&#160;&#160;&#160; at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
&#160;&#160;&#160; at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
&#160;&#160;&#160; at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
&#160;&#160;&#160; at java.lang.Thread.run(Thread.java:662) [:1.6.0_31]

20:34:56,200 TRACE [org.jboss.security.plugins.auth.JaasSecurityManagerBase.youfoodinc_domain] End isValid, false
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I stil have the same Persistence Unit and Datasource.</p><p>I modified the login-conf.xml to include :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-comment">&lt;!--YouFood inc--&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;application-policy name="youfoodinc_domain"&gt;</span>&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;authentication&gt;</span>&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required"&gt;</span>&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;module-option name="dsJndiName"&gt;</span>java:/MySqlDs<span class="jive-xml-tag">&lt;/module-option&gt;</span> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;module-option name="principalsQuery"&gt;</span>SELECT password FROM _user WHERE email='test@test.fr'<span class="jive-xml-tag">&lt;/module-option&gt;</span>&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;module-option name="rolesQuery"&gt;</span>SELECT _role, 'Roles' FROM _user WHERE email='test@test.fr'<span class="jive-xml-tag">&lt;/module-option&gt;</span> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/login-module&gt;</span> 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/authentication&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/application-policy&gt;</span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I modified jboss-web.xml :</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="jive-xml-tag">&lt;jboss-web&gt;</span>
&#160; <span class="jive-xml-tag">&lt;context-root&gt;</span>/YouFoodInc<span class="jive-xml-tag">&lt;/context-root&gt;</span>
&#160; <span class="jive-xml-tag">&lt;security-domain&gt;</span>java:/jaas/youfoodinc_domain<span class="jive-xml-tag">&lt;/security-domain&gt;</span>
<span class="jive-xml-tag">&lt;/jboss-web&gt;</span>
</code></pre><p>As well as web.xml, which is a bit long, i will put it if someone' asking for.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>It's a very weird error, I have no idea why it happened. Seems like it's using another jar ? I haven't changed my AS's jar (except for the mysql driver inside lib).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any idea anyone ??</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/717296#717296">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Datasource Configuration at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>