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.