• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help with Tomcat 7 DataSourceRealm

 
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a working web app deployed on Tomcat 7 and it's already using successfully connection pooling from a configured datasource. Trouble is when i enforce authentication i simply can't login. I keep being forwarded to the login-error.html. Nothing being dumped to the logs. Please help! Below are the details:

1. web.xml

<security-role>
<role-name>cashier</role-name>
</security-role>

<security-role>
<role-name>supervisor</role-name>
</security-role>

<security-role>
<role-name>administrator</role-name>
</security-role>

<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Zone</web-resource-name>
<url-pattern>/reports/*</url-pattern>
<url-pattern>/register/*</url-pattern>
<url-pattern>/index.html</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>administrator</role-name>
<role-name>supervisor</role-name>
</auth-constraint>
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Zone</web-resource-name>
<url-pattern>/index/*</url-pattern>
<url-pattern>/register/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>cashier</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>FORM</auth-method>
<realm-name>Secure Zone</realm-name>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/login-error.html</form-error-page>
</form-login-config>
</login-config>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

2. context.xml

<Resource name="jdbc/myDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="use"
password="pass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://IPAddress:3306/homeDB?autoReconnect=true"
removeAbandonedTimeout="60" />

3. server.xml

<Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99"
dataSourceName="jdbc/myDS"
userTable="userT" userNameCol="username" userCredCol="password"
userRoleTable="userRT" roleNameCol="rolename" />

4. Authentication & Authorization Tables

CREATE TABLE IF NOT EXISTS userT (
username VARCHAR(20) NOT NULL PRIMARY KEY
,password VARCHAR(20) NOT NULL
);

CREATE TABLE IF NOT EXISTS userRT (
username VARCHAR(20) NOT NULL
,rolename VARCHAR(20) NOT NULL
,PRIMARY KEY (username, rolename)
);

INSERT userT VALUES ('user1', 'user1');
INSERT userRT VALUES ('user1','administrator');


When enter 'user1' for username and 'user1' for password, i keep being sent to the error page.
Here is the login page:

5. Login Page

<table class="login" width="400pt" height="290pt">
<form action="j_security_check" method="post">
<tr>
<th>Enter Username:</th>
<td><input type="text" name="j_username"/></td>
</tr>
<tr>
<th>Enter Password:</th>
<td><input type="password" name="j_password"/></td>
</tr>
<tr>
<td/>
<td><b><input type="submit" value="Submit"/></b></td>
</tr>
</form>
</table>
 
Bell Katapa
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Now am getting something from the log. Any help to fix this?

Dec 23, 2012 1:56:03 PM org.apache.catalina.realm.DataSourceRealm open
SEVERE: Exception performing authentication
javax.naming.NameNotFoundException: Name [jdbc/myDS] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:394)
at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:285)
at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:295)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:450)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
 
Bell Katapa
Ranch Hand
Posts: 58
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just an update. I finally got it working. I put the <Realm> and <Resource> tag contents into the same context.xml file. At this point i still could not login. Then i added one more attribute to the <Realm> tag i.e. localDataSource="true". It worked after that.
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic