SPRINGMVC's Interceptor

Source: Internet
Author: User

 Public classLogininterceptorImplementsHandlerinterceptor {/*** Execute before action method, implement authentication interception in this method*/@Override Public BooleanPrehandle (httpservletrequest request, httpservletresponse response, Object handler)throwsException {//Get SessionHttpSession session =request.getsession (); //User identity InformationActiveuser Activeuser =(Activeuser) Session.getattribute (Config.activeuser_key); if(activeuser!=NULL){//indicates that the user is logged on            return true;//Release continued access        }        //gets the URL of the user requestString URL =Request.getrequesturi (); //Example:/project/first.action//determine if the URL is public address, if it is public address release//Get public AddressList<string> openurl_list =resourcesutil.gekeylist (config.anonymous_actions); //Verify the URL of the request is within the public address         for(String open_url:openurl_list) {if(Url.indexof (Open_url) >=0){                return true; }        }        //Challenge to login pageRequest.getrequestdispatcher ("/web-inf/jsp/base/login.jsp"). Forward (request, response); return false; }    /*** Execute the action method before returning the view*/@Override Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandvi EW Modelandview)throwsException {//re-edit view based on personalization requirements to return to the browser            }    /*** Execute the action method to complete the execution of this method*/@Override Public voidaftercompletion (httpservletrequest request, httpservletresponse response, Object handler, Exception ex) throwsException {//record the operation log in this method            }}
 Public classPermissioninterceptorImplementsHandlerinterceptor {/*** Permission Interception method*/@Override Public BooleanPrehandle (httpservletrequest request, httpservletresponse response, Object handler)throwsException {//verifies whether the address requested by the user is a public address//gets the URL of the user requestString URL =Request.getrequesturi (); //Example:/project/first.action//determine if the URL is public address, if it is public address release//Get public AddressList<string> openurl_list =resourcesutil.gekeylist (config.anonymous_actions); //Verify the URL of the request is within the public address         for(String open_url:openurl_list) {if(Url.indexof (Open_url) >=0){                return true;//if it's a public address, release it .            }        }                //whether the checksum is a public permission//get public permission addressList<string> commonurl_list =resourcesutil.gekeylist (config.common_actions); //verifies that the requested URL is within a public permission address         for(String common_url:commonurl_list) {if(Url.indexof (Common_url) >=0){                return true;//if it's a public access address, then release .            }        }                //whether the user has permission to operate//get the user's permissions from the session//Get SessionHttpSession session =request.getsession (); //User identity InformationActiveuser Activeuser =(Activeuser) Session.getattribute (Config.activeuser_key); List<Operation> operations =activeuser.getoperationlist (); //Verify that the URL of the request is within the user Action permission address         for(Operation Operation_index:operations) {String operation=Operation_index.getactionurl (); if(Url.indexof (Operation) >=0){                return true;//if the user's operating rights address is released            }        }                //Prompt user for no permission to do this//jump to the No Action Permission action pageRequest.getrequestdispatcher ("/web-inf/jsp/base/refuse.jsp"). Forward (request, response); return false; } @Override Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandvi EW Modelandview)throwsException {//TODO auto-generated Method Stub} @Override Public voidaftercompletion (httpservletrequest request, httpservletresponse response, Object handler, Exception ex) throwsException {//TODO auto-generated Method Stub            }    }

SPRINGMVC's Interceptor

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.