Intrusion detection and simple implementation in Java Web

Source: Internet
Author: User

First, Introduction

In Java Web applications, especially Web site development, we sometimes need to add an intrusion detection program to the application to prevent the malicious refresh of the ability to prevent illegal users from constantly sending data to the Web application. Of course, intrusion detection can be implemented in many ways, including software, hardware firewall, intrusion detection strategy is also a lot. Here we mainly introduce the Java Web application in the way of software to achieve simple intrusion detection and defense.

The implementation principle of this method is very simple, that is, when the user accesses the web system, it records each user's information, then controls it, and then determines whether the user is a malicious refresh according to the set strategy (for example, 10 times refresh page 1 seconds).

Our intrusion detection program should be placed before the execution of all Java Web programs, and where that users will not continue to execute other parts of the Java Web without a malicious refresh, otherwise it would be meaningless. This requires a plug-in to the intrusion detection program into the Java Web application, so that every time users visit the Java Web, the first to the intrusion detection program to report to the rules to release.

There are roughly two types of Java Web applications, a pure JSP (+java Bean) approach, one based on frames (such as struts, easyjweb, and so on). The first approach to the Java Web can be implemented through the filter interface in the Java servlet, which implements a filter interface, inserts an intrusion detection program into its Dofilter method, and then web.xml it in a simple configuration. In a framework-based Web application, because all applications have a portal, intrusion detection programs can be inserted directly into the framework entry engine, enabling the framework itself to support intrusion detection capabilities. Of course, it can also be implemented by implementing the filter interface.

In the Easyjweb framework, has been placed into a simple intrusion detection program, so here we take the Easyjweb framework as an example, introduce the specific implementation methods and source code, the complete codes can be found in the Easyjweb source.

In Easyjweb Java Web applications (such as http://www.easyjf.com/bbs/), by default you will be prompted with the following error if you refresh the page too often:

Easyjweb Frame Friendship Tips!:-):

You refresh the page too quickly, please wait 60 seconds before refreshing the page!

Please inquire about http://www.easyjf.com

Second, the user accesses the information record Userconnect.java class

This class is a simple Java Bean that mainly represents the user's information, including user name, IP, first access time, last logon time, logon times, user status, and so on. All

The code is as follows:

Package com.easyjf.web
Import java.util.Date
/**
*
*
Title: User authentication information
*
Description: Record User login information, Judge user Login status
*
Copyright:copyright (c) 2006
*
Company:www.easyjf.com
* @author Cai Shiyu
* @versi On 1.0
*/
public class Userconnect {
private string userName;
private string IP;
Private Date Firstfai Luretime;
Private Date Lastlogintime;
Private int failuretimes;//The number of user logon failures
private int status=0;//User state 0 is normal,-1 means locking
public int getfailuretimes () { br> return failuretimes;
}
public void setfailuretimes (int failuretimes) {
This.failuretimes = failuretimes;
}
Public Date Getfirstfailuretime () {
return firstfailuretime
}
public void Setfirstfailuretime (Date firstfailuretime) {
This.firstfailuretime = firstfailuretime;
}
Public String GetIP () {
return IP;
}
public void setIp (String IP) {
This.ip = IP;
}
Public Date Getlastlogintime () {
return LastlOgintime;
}
public void Setlastlogintime (Date lastlogintime) {
This.lastlogintime = lastlogintime;
}
Public String GetUserName () {
return userName
}
public void Setusername (String userName) {
This.username = userName;
}
public int GetStatus () {
return status;
}
public void setstatus (int status) {
This.status = status;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.