[jboss-user] [Datasource Configuration] - Realm configuration problems using DataSourceRealm
do-not-reply at jboss.com
Mon May 10 04:51:13 EDT 2010
Patrick Mingard [http://community.jboss.org/people/Lordsephiroth] created the discussion
"Realm configuration problems using DataSourceRealm"
To view the discussion, visit: http://community.jboss.org/message/541991#541991
My name is Patrick, from Switzerland, and I'm new on Java EE and JBoss. I started a few weeks ago to learn how to devlop in Java EE and succeeded in much tests. I first tried to make a small servlet in a WAR archive, then having an EJB-JAR archive as well with entities and stateless session beans, together packaged in EAR archive. Everything is going perfectly well and my testing application, a small currency-change application, is working (add currencies, define currencies rates and conversion).
Now, I'm trying to go a bit further by protecting my servlets with username and password.
First, here is my environment :
MyEclipse (but packaging everything using ANT)
JPA / EJB 3
Hypersonic Database (for testing and learning, this DB is fine I guess)
My JNDI env contains this entry (in JMX console, service JNDI view) :
h1. java: Namespace
+- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
Now, I try to configure the Realm element. I have to say here that I read a lot of time that context.xml should be place in /META-INF/ directory (here : http://docs.jboss.org/jbossweb/en/html/docs/config/context.html).
All my tests asserts that context.xml is never taken into account when I place it in /META-INF/ but is evaluated when placed in /WEB-INF/. I'm not sure if it is important, but for the rest of my question, consider the context.xml is placed in /WEB-INF/ directory.
Here is the code :
And here is the security part of web.xml (rest is mostly servlet mapping) :
<display-name>Security constraint for all servlets</display-name>
I also tried using dataSourceName="DefaultDS" or jdbc/DefaultDS or java:comp/env/DefaultDS, I always get the same error when I log in
login.jsp file is perfectly standard and contains :
<form action="j_security_check" method="post">
<td>User name : </td>
<td><input type="text" name="j_username" /></td>
<td>Password : </td>
<td><input type="password" name="j_password" /></td>
<td><input type="submit" value="connect" /></td>
When I try to log in, I always get this error :
javax.naming.NameNotFoundException: Le Nom java:DefaultDS n'est pas lié à ce context.
Well, the exception message is in french, but it means (java:DefaultDS name is not bound to this context) or close to this.
I guess this problem is due to the fact that the security Realm is placed in the web container context, which has by default no access to the database. I have no problem accessign the database through my entities in my EJB-JAR application. Let me know if i'm wrong.
Fine, I guess I have to make a reference to the database in the context of my web container (I have to say I'm really not used to context and this part of java programming is kind of... obscure.. to not say... annoying).
So my web.xml is modified with this additional lines :
<description>The default DS</description>
Now the only exception I get is during deployment :
java.lang.RuntimeException: mapped-name is required for java:DefaultDS of deployment testEJB-web.war
Well... let me guess I need a mapped-name attribute in my web.xml.
I made this change :
<description>The default DS</description>
And I'm back with my first exception stating java:DefaultDS is not bound to this context. I tried to place DefaultDS, java:comp/env/DefaultDS or jdbc/DefaultDS and almost any combining of these possibilities in the res-ref-name, mapped-name and realm name attributes in my files. I always get an exception when I try to log in.
So, let me come to my question : what can I do for this realm configuration ? I'm really stuck now ;)
Last precision : I heard about a jboss-web.xml file in the WEB-INF directory that could replace the web.xml resource configuration and tried some things like :
But did not see any message of any kind (exception or info or warn or whatever) stating that my file was parsed by the JBoss server.
Any help would be really appreciated, I'm kind of wasting so much time (almost 4 days entirely for this problem) without solving it.
Thanks, and sorry if I made some language mistakes, I guess my english is not bad, but not perfect either ;)
Reply to this message by going to Community
Start a new discussion in Datasource Configuration at Community
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the jboss-user