org.apache.struts2.interceptor
类 RolesInterceptor
java.lang.Object
com.opensymphony.xwork2.interceptor.AbstractInterceptor
org.apache.struts2.interceptor.RolesInterceptor
- 所有已实现的接口:
- com.opensymphony.xwork2.interceptor.Interceptor, Serializable
public class RolesInterceptor
- extends com.opensymphony.xwork2.interceptor.AbstractInterceptor
This interceptor ensures that the action will only be executed if the user has the correct role.
Interceptor parameters:
- allowedRoles - a comma-separated list of roles to allow
- disallowedRoles - a comma-separated list of roles to disallow
When both allowedRoles and disallowedRoles are configured, then disallowedRoles
takes precedence, applying the following logic:
(if ((inRole(role1) || inRole(role2) || ... inRole(roleN)) &&
!inRole(roleA) && !inRole(roleB) && ... !inRole(roleZ))
{ //permit ...
There are three extensions to the existing interceptor:
- isAllowed(HttpServletRequest,Object) - whether or not to allow
the passed action execution with this request
- handleRejection(ActionInvocation) - handles an unauthorized
request.
- areRolesValid(List roles) - allows subclasses to lookup roles
to ensure they are valid. If not valid, RolesInterceptor will log the error and
cease to function. This helps prevent security misconfiguration flaws.
<!-- START SNIPPET: example -->
<!-- only allows the admin and member roles -->
<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="completeStack"/>
<interceptor-ref name="roles">
<param name="allowedRoles">admin,member</param>
</interceptor-ref>
<result name="success">good_result.ftl</result>
</action>
<!-- END SNIPPET: example -->
- 另请参见:
- 序列化表格
从类 com.opensymphony.xwork2.interceptor.AbstractInterceptor 继承的方法 |
destroy, init |
RolesInterceptor
public RolesInterceptor()
setAllowedRoles
public void setAllowedRoles(String roles)
setDisallowedRoles
public void setDisallowedRoles(String roles)
intercept
public String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
throws Exception
- 指定者:
- 接口
com.opensymphony.xwork2.interceptor.Interceptor
中的 intercept
- 指定者:
- 类
com.opensymphony.xwork2.interceptor.AbstractInterceptor
中的 intercept
- 抛出:
Exception