Class HttpMethodPermissionFilter

java.lang.Object
All Implemented Interfaces:
javax.servlet.Filter, org.apache.shiro.lang.util.Nameable, PathConfigProcessor

A filter that translates an HTTP Request's Method (e.g. GET, POST, etc.) into an corresponding action (verb) and uses that verb to construct a permission that will be checked to determine access.

This Filter is primarily provided to support REST environments where the type (Method) of request translates to an action being performed on one or more resources. This paradigm works well with Shiro's concepts of using permissions for access control and can be leveraged to easily perform permission checks.

This filter functions as follows:

  1. The incoming HTTP request's Method (GET, POST, PUT, DELETE, etc.) is discovered.
  2. The Method is translated into a more 'application friendly' verb, such as 'create', edit', 'delete', etc.
  3. The verb is appended to any configured permissions for the currently matching path.
  4. If the current Subject isPermitted to perform the resolved action, the request is allowed to continue.

For example, if the following filter chain was defined, where 'rest' was the name given to a filter instance of this class:

 /user/** = rest[user]
Then an HTTP GET request to /user/1234 would translate to the constructed permission user:read (GET is mapped to the 'read' action) and execute the permission check Subject.isPermitted("user:read") in order to allow the request to continue.

Similarly, an HTTP POST to /user would translate to the constructed permission user:create (POST is mapped to the 'create' action) and execute the permission check Subject.isPermitted("user:create") in order to allow the request to continue.

Method To Verb Mapping

The following table represents the default HTTP Method-to-action verb mapping:
HTTP MethodMapped ActionExample PermissionRuntime Check
headreadperm1perm1:read
getreadperm2perm2:read
putupdateperm3perm3:update
postcreateperm4perm4:create
mkcolcreateperm5perm5:create
optionsreadperm6perm6:read
tracereadperm7perm7:read
Since:
1.0