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