Class PagePermission

java.lang.Object
java.security.Permission
org.apache.wiki.auth.permissions.PagePermission
All Implemented Interfaces:
java.io.Serializable, java.security.Guard

public final class PagePermission
extends java.security.Permission
implements java.io.Serializable

Permission to perform an operation on a single page or collection of pages in a given wiki. Permission actions include: viewedit (edit the text of a wiki page), commentuploadmodify (edit text and upload attachments), delete  and rename.

The target of a permission is a single page or collection in a given wiki. The syntax for the target is the wiki name, followed by a colon (:) and the name of the page. "All wikis" can be specified using a wildcard (*). Page collections may also be specified using a wildcard. For pages, the wildcard may be a prefix, suffix, or all by itself. Examples of targets include:

*:*
*:JanneJalkanen
*:Jalkanen
*:Janne*
mywiki:JanneJalkanen
mywiki:*Jalkanen
mywiki:Janne*

For a given target, certain permissions imply others:

  • delete and rename imply edit
  • modify implies edit and upload
  • edit implies comment and view
  • comment and upload imply view
  • Targets that do not include a wiki prefix never imply others.
Since:
2.3
See Also:
Serialized Form
  • Field Summary

    Fields
    Modifier and Type Field Description
    static PagePermission COMMENT
    A static instance of the comment permission.
    static java.lang.String COMMENT_ACTION
    Action name for the comment permission.
    protected static int COMMENT_MASK  
    static PagePermission DELETE
    A static instance of the delete permission.
    static java.lang.String DELETE_ACTION
    Action name for the delete permission.
    protected static int DELETE_MASK  
    static PagePermission EDIT
    A static instance of the edit permission.
    static java.lang.String EDIT_ACTION
    Action name for the edit permission.
    protected static int EDIT_MASK  
    static PagePermission MODIFY
    A static instance of the modify permission.
    static java.lang.String MODIFY_ACTION
    Action name for the modify permission.
    protected static int MODIFY_MASK  
    static PagePermission RENAME
    A static instance of the rename permission.
    static java.lang.String RENAME_ACTION
    Action name for the rename permission.
    protected static int RENAME_MASK  
    static PagePermission UPLOAD
    A static instance of the upload permission.
    static java.lang.String UPLOAD_ACTION
    Action name for the upload permission.
    protected static int UPLOAD_MASK  
    static PagePermission VIEW
    A static instance of the view permission.
    static java.lang.String VIEW_ACTION
    Action name for the view permission.
    protected static int VIEW_MASK  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected PagePermission()
    For serialization purposes.
      PagePermission​(java.lang.String page, java.lang.String actions)
    Creates a new PagePermission for a specified page name and set of actions.
      PagePermission​(Page page, java.lang.String actions)
    Creates a new PagePermission for a specified page and set of actions.
  • Method Summary

    Modifier and Type Method Description
    protected static int createMask​(java.lang.String actions)
    Private method that creates a binary mask based on the actions specified.
    boolean equals​(java.lang.Object obj)
    Two PagePermission objects are considered equal if their actions (after normalization), wiki and target are equal.
    java.lang.String getActions()
    Returns the actions for this permission: "view", "edit", "comment", "modify", "upload" or "delete".
    java.lang.String getPage()
    Returns the name of the wiki page represented by this permission.
    java.lang.String getWiki()
    Returns the name of the wiki containing the page represented by this permission; may return the wildcard string.
    int hashCode()
    Returns the hash code for this PagePermission.
    protected static int impliedMask​(int mask)
    Creates an "implied mask" based on the actions originally assigned: for example, delete implies modify, comment, upload and view.
    boolean implies​(java.security.Permission permission)
    PagePermission can only imply other PagePermissions; no other permission types are implied.
    protected static boolean isSubset​(java.lang.String superSet, java.lang.String subSet)
    Determines whether one target string is a logical subset of the other.
    java.security.PermissionCollection newPermissionCollection()
    java.lang.String toString()
    Prints a human-readable representation of this permission.

    Methods inherited from class java.security.Permission

    checkGuard, getName

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • PagePermission

      protected PagePermission()
      For serialization purposes.
    • PagePermission

      public PagePermission​(java.lang.String page, java.lang.String actions)
      Creates a new PagePermission for a specified page name and set of actions. Page should include a prepended wiki name followed by a colon (:). If the wiki name is not supplied or starts with a colon, the page refers to no wiki in particular, and will never imply any other PagePermission.
      Parameters:
      page - the wiki page
      actions - the allowed actions for this page
    • PagePermission

      public PagePermission​(Page page, java.lang.String actions)
      Creates a new PagePermission for a specified page and set of actions.
      Parameters:
      page - The wikipage.
      actions - A set of actions; a comma-separated list of actions.
  • Method Details

    • equals

      public boolean equals​(java.lang.Object obj)
      Two PagePermission objects are considered equal if their actions (after normalization), wiki and target are equal.
      Specified by:
      equals in class java.security.Permission
      Parameters:
      obj -
      Returns:
    • getActions

      public java.lang.String getActions()
      Returns the actions for this permission: "view", "edit", "comment", "modify", "upload" or "delete". The actions will always be sorted in alphabetic order, and will always appear in lower case.
      Specified by:
      getActions in class java.security.Permission
      Returns:
    • getPage

      public java.lang.String getPage()
      Returns the name of the wiki page represented by this permission.
      Returns:
      the page name
    • getWiki

      public java.lang.String getWiki()
      Returns the name of the wiki containing the page represented by this permission; may return the wildcard string.
      Returns:
      the wiki
    • hashCode

      public int hashCode()
      Returns the hash code for this PagePermission.
      Specified by:
      hashCode in class java.security.Permission
      Returns:
    • implies

      public boolean implies​(java.security.Permission permission)

      PagePermission can only imply other PagePermissions; no other permission types are implied. One PagePermission implies another if its actions if three conditions are met:

      1. The other PagePermission's wiki is equal to, or a subset of, that of this permission. This permission's wiki is considered a superset of the other if it contains a matching prefix plus a wildcard, or a wildcard followed by a matching suffix.
      2. The other PagePermission's target is equal to, or a subset of, the target specified by this permission. This permission's target is considered a superset of the other if it contains a matching prefix plus a wildcard, or a wildcard followed by a matching suffix.
      3. All of other PagePermission's actions are equal to, or a subset of, those of this permission
      Specified by:
      implies in class java.security.Permission
      Parameters:
      permission -
      Returns:
      See Also:
      Permission.implies(java.security.Permission)
    • newPermissionCollection

      public java.security.PermissionCollection newPermissionCollection()
      Overrides:
      newPermissionCollection in class java.security.Permission
      Returns:
      See Also:
      Permission.newPermissionCollection()
    • toString

      public java.lang.String toString()
      Prints a human-readable representation of this permission.
      Overrides:
      toString in class java.security.Permission
      Returns:
      Something human-readable
      See Also:
      Object.toString()
    • impliedMask

      protected static int impliedMask​(int mask)
      Creates an "implied mask" based on the actions originally assigned: for example, delete implies modify, comment, upload and view.
      Parameters:
      mask - binary mask for actions
      Returns:
      binary mask for implied actions
    • isSubset

      protected static boolean isSubset​(java.lang.String superSet, java.lang.String subSet)
      Determines whether one target string is a logical subset of the other.
      Parameters:
      superSet - the prospective superset
      subSet - the prospective subset
      Returns:
      the results of the test, where true indicates that subSet is a subset of superSet
    • createMask

      protected static int createMask​(java.lang.String actions)
      Private method that creates a binary mask based on the actions specified. This is used by implies(Permission).
      Parameters:
      actions - the actions for this permission, separated by commas
      Returns:
      the binary actions mask