Struts a simple login blocker

Source: Internet
Author: User

This is an interceptor code for a login to intercept.

I wrote the action into a configuration file, and by comparing the actionname to achieve the interception function

Package Com.shop.web.intercept;import Java.util.arraylist;import Java.util.list;import java.util.ResourceBundle; Import Com.opensymphony.xwork2.action;import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actioninvocation;import Com.opensymphony.xwork2.actionsupport;import Com.opensymphony.xwork2.interceptor.abstractinterceptor;import Com.shop.web.action.baseaction;public Class Autheninterceptor extends Abstractinterceptor {private list<string> Permissionuris = new arraylist<string> (); @Overridepublic void Init () {ResourceBundle res = Resourcebundle.getbundle ("Permissionuris"); for (String key: Res.keyset ()) {Permissionuris.add (res.getstring (key));} Super.init ();} @Overridepublic string intercept (Actioninvocation invocation) throws Exception {String ActionName = Invocation.getproxy (). Getactionname (); if (Permissionuris.contains (ActionName)) {//If ActionName is in the release list, release return Invocation.invoke ();} Not in the release list verify if you are logged in if (Actioncontext.getcontext (). GetSession (). Get (BaseactIon. Login_user) {==null) {return action.login;//returns the login result}return invocation.invoke ();//Returns the result of the action execution}}


Struts a simple login blocker

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.