Now, the strange thing is that ds is null no matter what the datasource is set to in login-config.xml. Even not setting it (making it default to java:/DefaultDS (with HSQL)) yields a NPE at this point.

What's even more strange is that a JPA/Hibernate model in the same EAR uses the same datasource, and this works flawlessly.

That's strange. I would have expected a NamenotFoundException or NamingException if it was a problem with the lookup. Can you post the output of the JNDI tree, which can be accessed as follows:

- Go to http://< server>:< port>/jmx-console (Ex: http://localhost:8080/jmx-console)- Search for service=JNDIView on the jmx-console page- Click on that link- On the page that comes up click on the Invoke button beside the list() method- The page that comes up will show the contents of the JNDI tree.

Post the output here.

Also, try removing the DOCTYPE declaration from your ds.xml file as follows and see if it works:

Seeing this I added a method breakpoint in the bind() method and restarted JBoss. The only breakpoint I got was for "java:/Mail".

So to check this, I changed the dsJndiName for the DatabaseServerLoginModule to "java:/Mail". Restarted and initiated a new login - and presto; ClassCastException instead of NPE. (noting that javax.mail.Session cannot be cast to javax.sql.Datasource).

So I presume this would be indicative of some fault in the JNDI configuration - although I don't quite see why...?

Well, at least I now know that the cause of the problem is somehow embedded in my EAR.

Log excerpt that shows first a login attempt to the EAR contained GWT application, then a login attempt to the JMX console.Both uses the same security-domain, but the first fails with the afore mentioned NPE and the last with a gracefull error message (expected)

I get exactly the same error message when trying to use the Databaseserver loginmodule. I use JBoss 4.2.3. In the log there is the following:

javax.security.auth.login.LoginException: java.lang.NullPointerException
at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:141)
at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:206)

It seems from the source file, that the Datasource returned is null. It's the following source in the login module:

I try to use database as user repository in Drools 4 BRMS or Drools 5 Guvnor. Got similar configuration as mactex except that I had to point policy from login-config.xml in the components.xml file of the guvnor/brms:

a little update. Now I know that ctx.lookup(dsJndiName); returns null. dsJndiName is bounded otherwise if I write there some wrong string like ctx.lookup("blablabla'); I get error that "blablabla" was not bound, so my dsJndiName is bounded, but empty?