Hi everybody, I am chaitanya, I want to implement j_security_check in my web application. Previously I used sessions to provide security for my web application. Now I want to migrate to j_security_check. Can anybody please tell me how I can do this. Where can I get enough matter to do this.
I searched the web here and there the whole day. At last I coded these pieces which are not working. I don’t know whether these are right or wrong. Please can any one tell me what mistake I have done and where can I study online.
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>J_Security_Check</display-name>
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
<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>
<security-constraint>
<web-resource-collection>
<web-resource-name>AdminPages</web-resource-name>
<url-pattern>/admin/*</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>ADMINISTRATOR</role-name>
</auth-constraint>
</security-constraint>
</web-app>
META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Realm
className="org.apache.catalina.realm.JDBCRealm"
debug="99"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql:///jscheck"
connectionName="root"
connectionPassword="abhinava"
userTable="users"
userNameCol="username"
userCredCol="password"
userRoleTable="user_roles"
roleNameCol="rolename"
/>
WebContent/login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Enter your Details
<form name=abc action="j_security_check" method=post>
user id:<input type=text name=j_username><br>
password:<input type=password name=j_password><br>
<input type=submit value=submit>
</form>
</body>
</html>
WebContent/error.jsp
<html>
<head>
<title>Error Page For Examples</title>
</head>
<body bgcolor="white">
Invalid username and/or password, please try
<a >again</a>.
</body>
</html>
WebContent/admin/index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Welcome
</body>
</html>
Can anybody please help me. Can anybody please forward a small application which implements j_security_check to my mail id kittu_564@yahoo.in
Thank you all in advance.