Im using Tomcat and a MySQL database that contains
usernames/passwords/roles for form-based authentication. Logging in with
correct username/password successfully directs to index.jsp (from
login.jsp). Logging in with incorrect username/password successfully
directs to error.jsp (from login.jsp). However, an unsuccessful login
followed by attempting to login with the correct username/password leads to
an HTTP Status 404 j_security_check error that says the requested resource
is not available. Does anyone know what may be wrong? Here are the details
of my configuration.
Software
-Windows 7
-MySQL 5.6
-Tomcat 7.042
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" antiResourceLocking="true" path="/webapp">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/database"
connectionName="username"
connectionPassword="password"
userTable="users"
userNameCol="user_name"
userCredCol="user_pass"
userRoleTable="user_roles"
roleNameCol="role_name"/>
</Context>
login.jsp
<html>
<head>
<title>mywebapp demo</title>
<meta http-equiv=ÓContent-TypeÓ content=Ótext/html;
charset=UTF-8Ó>
</head>
<body>
<div class=ÓcontentÓ>
<b>Please login to continue</b>
<form method="post" action="j_security_check">
<table>
<tr>
<td><label
for="username">Username:</label></td>
<td><input id="username"
type="text" name="j_username" /><td>
</tr>
<tr>
<td><label
for="password">Password:</label></td>
<td><input id="password"
type="password" name="j_password" /><td>
<td><input type="submit"
value="Login" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
web.xml (for the webapp)
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>webapp</display-name>
<description>Form-Based Authentication with mySQL</description>
<resource-ref>
<description>mySQL Database</description>
<res-ref-name>jdbc/database</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-constraint>
<web-resource-collection>
<web-resource-name>webapps</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>rolename</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
|