With the deepening of Enterprise Informatization, various information systems have become essential tools for improving enterprise operation and management efficiency, more and more enterprise core secrets, such as sales opportunities, customer data, and design solutions, are stored, filed, and transferred through the information system. Once these core information is leaked, it will inevitably cause great losses to the enterprise. In the age of science and technology, information is the lifeblood of enterprise survival, and the security of information will inevitably become an issue that enterprises attach great importance. Nowadays, with the implementation of various information security measures, information leaks have been transferred from external leaks to internal personnel leaks. For external hackers and viruses to obtain valuable information, they must penetrate through multiple firewalls to escape the pursuit of multiple anti-virus tools, and then filter the information; internal Personnel know what information is valuable. If necessary security protection is not provided, some insiders can easily obtain the information they need.
According to a recent survey, almost half of professionals from all walks of life admit that they will take away information, including documents, sales agreements, contract lists, and other materials, when switching jobs, and tell them to the next boss. The survey also found that employees can easily download "competitive" information and take it to their next job.
Information security has a long way to go. To ensure the security of the information system, we need to consider many aspects such as firewall, encrypted transmission, and anti-SQL injection. However, many security solutions are designed to keep the door safe, such as identity authentication and digital certificates, whether it is the traditional user name and password method, fingerprint and retina scanning technology based on biometric identification, even USB keys commonly used in various e-government fields are widely used in accessing the system gate. Once identity recognition is completed, it is easy to hear about and there are few solutions. This article focuses not on how to perform identity authentication, but how to ensure that users only operate within the permitted range after the authentication is completed, that is, after entering the system gate, the fine-grained permission control solution in the system is not an operation that can perform any function.
The common permission system design mode focuses on roles, that is, roles are a set of people with the same permissions:
1. One role can contain multiple operators, and one operator can also belong to multiple roles.
2. A role can have operation permissions for multiple functions, and a function can also be owned by multiple roles.
When you log on, You can query the roles of the logon user to obtain a set of all functions of the user, such:
The functional menu design of most business systems is based on level 3, that is, level 1 function menu, level 2 function menu, and level 3 function menu. Generally, level 1 and level 2 function menus are only used for function classification, there is no function access address, and the third-level menu is the real entry to the function. The general permission system controls permissions by controlling the display and hiding of function menus corresponding to each personnel. To implement fine-grained permission control, you can add the layer-4: page elements to the layer-3 function menu when designing the function list. These page elements are used to identify each function button on the function page, adding, modifying, deleting, and querying can be regarded as page elements. When assigning permissions to a role, the fourth layer also includes unified permission management. If you have permissions for this page element, the button is displayed on the page. If you do not have the function permission for the page element, the button is not displayed.
For features that do not have access permissions or pages that do not have front-end hiding, you also need to perform permission verification during background access, otherwise, attackers can bypass the page and directly access the page by entering a URL. SpringMVC + Annotation can be easily implemented using the following code:
Step 1: Create a SpringMVC Interceptor to intercept all functional requests that require permission verification.
Step 2: Create an Annotation class acting on the Method level for passing in the function ID
@ Retention (RetentionPolicy. RUNTIME) @ Target (ElementType. METHOD) public @ interface Permission {/*** function ID, this function ID, function ID * @ return * @ version V1.0.0 * @ date Jan 13,201 4 4:59:35 */String value ();}Step 3: use static constants to establish a one-to-one relationship between functional IDs in the database and execution methods
Public class FuncConstants {/*** System Management-role management-Add a role */public final static String Xtgl_Jsgl_AddJs = "4399d98bb0d84114acb4243081e83bc9 "; /*** System Management-department management-department list */public final static String Xtgl_Bmgl_BmList = "dbc4bf80f8b6418788b79de204d42432 ";}
Step 4: Verify permissions in SpringMVC interceptor
/*** FreeMarker view interceptor, perform some general processing before page display * @ version V1.0.0 * @ date Dec 12,201 3 4:20:04 */public class extends HandlerInterceptorAdapter {public void afterCompletion (HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, exception arg3) throws Exception {} public void postHandle (HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView view) Throws Exception {String contextPath = request. getContextPath (); if (view! = Null) {request. setAttribute ("base", contextPath) ;}} public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {// process Permission Annotation, implement method-level Permission control HandlerMethod method = (HandlerMethod) handler; permission Permission = method. getMethodAnnotation (Permission. class); // if it is null, this method does not need to perform permission verification if (permission = null) {return true;} // verify if it has the permission if (! WebUtil. hasPower (request, permission. value () {response. sendRedirect (request. getContextPath () + "/business/nopermission.html"); return false;} return true; // note that true must be returned here; otherwise, the request will stop // return true ;}}
So far, the fine-grained Permission System Based on button and method verification has been completed!