Use Struts to intercept namespace for permission Control

Source: Internet
Author: User

Sometimes I need to perform the same permission control under several packages. For example, on a shopping website, we need to go to the personal center, place orders, evaluate products, and so on. However, these modules are not in the same package. The interceptor provided by Struts can implement Interception Under action. Although we can configure this interceptor in every package, it is quite troublesome. In this case, we can use the Interceptor to block the package. You can add the required permission control package to the interceptor.

First, we need to configure the interceptor in struts. xml.

                                                                                                                                                 /index                 index                                             /login.jsp              

The main configured above, so the package must inherit the main, that is, extends = "main", otherwise it cannot be implemented.

In struts. xml, the interceptor stack is used, which contains two interceptors: the default defaultStack and the authorizationInterceptor for permission control.

Interceptor implementation class: SystemInterceptor. java

   SystemInterceptor           serialVersionUID = -1819593755738908387L        String WITHOUT = "/index, /author, /common, /indexzp";                          String intercept(ActionInvocation invocation)          String namespace = invocation.getProxy().getNamespace();                 (WITHOUT.indexOf(namespace) >= 0                        Map<?, ?> session =         UserBean user = (UserBean) session.get("currentUser"          (user == ){                         "loginfailure"           invocation.invoke();     }
 

The interceptor implementation class above specifies several namespaces that do not require permission control. In addition, all other namespaces need to be implemented.

Permission control.

Other packages only need to inherit the main to implement permission control.

                       /jsp/grzx/updatePassword.jsp             /jsp/grzx/updatePassword.jsp             /zp/myWorksHome.action             /jsp/grzx/updatePhoto.jsp             /jsp/grzx/updateInfo.jsp              

Note: Because this interceptor is mainly controlled based on namespace, you need to add namespace When configuring the package.

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.