⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagepermission.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*     JSPWiki - a JSP-based WikiWiki clone.    Licensed to the Apache Software Foundation (ASF) under one    or more contributor license agreements.  See the NOTICE file    distributed with this work for additional information    regarding copyright ownership.  The ASF licenses this file    to you under the Apache License, Version 2.0 (the    "License"); you may not use this file except in compliance    with the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0    Unless required by applicable law or agreed to in writing,    software distributed under the License is distributed on an    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY    KIND, either express or implied.  See the License for the    specific language governing permissions and limitations    under the License.   */package com.ecyrd.jspwiki.auth.permissions;import java.io.Serializable;import java.security.Permission;import java.security.PermissionCollection;import java.util.Arrays;import org.apache.commons.lang.StringUtils;import com.ecyrd.jspwiki.WikiPage;/** * <p> * Permission to perform an operation on a single page or collection of pages in * a given wiki. Permission actions include: <code>view</code>,&nbsp; * <code>edit</code> (edit the text of a wiki page),&nbsp;<code>comment</code>,&nbsp; * <code>upload</code>,&nbsp;<code>modify</code>&nbsp;(edit text and upload * attachments),&nbsp;<code>delete</code>&nbsp; * and&nbsp;<code>rename</code>. * </p> * <p> * 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: * </p> * <blockquote><code>*:*<br/> * *:JanneJalkanen<br/> * *:Jalkanen<br/> * *:Janne*<br/> * mywiki:JanneJalkanen<br/> * mywiki:*Jalkanen<br/> * mywiki:Janne*</code> * </blockquote> * <p> * For a given target, certain permissions imply others: * </p> * <ul> * <li><code>delete</code>&nbsp;and&nbsp;<code>rename</code>&nbsp;imply&nbsp;<code>edit</code></li> * <li><code>modify</code>&nbsp;implies&nbsp;<code>edit</code>&nbsp;and&nbsp;<code>upload</code></li> * <li><code>edit</code>&nbsp;implies&nbsp;<code>comment</code>&nbsp;and&nbsp;<code>view</code></li> * <li><code>comment</code>&nbsp;and&nbsp;<code>upload</code>&nbsp;imply&nbsp;<code>view</code></li> * Targets that do not include a wiki prefix <i>never </i> imply others. * </ul> * @author Andrew Jaquith * @since 2.3 */public final class PagePermission extends Permission implements Serializable{    private static final long          serialVersionUID = 2L;    /** Action name for the comment permission. */    public static final String         COMMENT_ACTION = "comment";    /** Action name for the delete permission. */    public static final String         DELETE_ACTION  = "delete";    /** Action name for the edit permission. */    public static final String         EDIT_ACTION    = "edit";    /** Action name for the modify permission. */    public static final String         MODIFY_ACTION  = "modify";    /** Action name for the rename permission. */    public static final String         RENAME_ACTION  = "rename";    /** Action name for the upload permission. */    public static final String         UPLOAD_ACTION  = "upload";    /** Action name for the view permission. */    public static final String         VIEW_ACTION    = "view";    protected static final int         COMMENT_MASK   = 0x4;    protected static final int         DELETE_MASK    = 0x10;    protected static final int         EDIT_MASK      = 0x2;    protected static final int         MODIFY_MASK    = 0x40;    protected static final int         RENAME_MASK    = 0x20;    protected static final int         UPLOAD_MASK    = 0x8;    protected static final int         VIEW_MASK      = 0x1;    /** A static instance of the comment permission. */    public static final PagePermission COMMENT        = new PagePermission( COMMENT_ACTION );    /** A static instance of the delete permission. */    public static final PagePermission DELETE         = new PagePermission( DELETE_ACTION );    /** A static instance of the edit permission. */    public static final PagePermission EDIT           = new PagePermission( EDIT_ACTION );    /** A static instance of the rename permission. */    public static final PagePermission RENAME         = new PagePermission( RENAME_ACTION );    /** A static instance of the modify permission. */    public static final PagePermission MODIFY         = new PagePermission( MODIFY_ACTION );    /** A static instance of the upload permission. */    public static final PagePermission UPLOAD         = new PagePermission( UPLOAD_ACTION );    /** A static instance of the view permission. */    public static final PagePermission VIEW           = new PagePermission( VIEW_ACTION );    private static final String        ACTION_SEPARATOR = ",";    private static final String        WILDCARD       = "*";    private static final String        WIKI_SEPARATOR = ":";    private static final String        ATTACHMENT_SEPARATOR = "/";    private final String               m_actionString;    private final int                  m_mask;    private final String               m_page;    private final String               m_wiki;    /** For serialization purposes. */    protected PagePermission()    {        this("");    }        /**     * Private convenience constructor that creates a new PagePermission for all wikis and pages     * (*:*) and set of actions.     * @param actions     */    private PagePermission( String actions )    {        this( WILDCARD + WIKI_SEPARATOR + WILDCARD, 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.     * @param page the wiki page     * @param actions the allowed actions for this page     */    public PagePermission( String page, String actions )    {        super( page );        // Parse wiki and page (which may include wiki name and page)        // Strip out attachment separator; it is irrelevant.                // FIXME3.0: Assumes attachment separator is "/".        String[] pathParams = StringUtils.split( page, WIKI_SEPARATOR );        String pageName;        if ( pathParams.length >= 2 )        {            m_wiki = pathParams[0].length() > 0 ? pathParams[0] : null;            pageName = pathParams[1];        }        else        {            m_wiki = null;            pageName = pathParams[0];        }        int pos = pageName.indexOf( ATTACHMENT_SEPARATOR );        m_page = ( pos == -1 ) ? pageName : pageName.substring( 0, pos );        // Parse actions        String[] pageActions = StringUtils.split( actions.toLowerCase(), ACTION_SEPARATOR );        Arrays.sort( pageActions, String.CASE_INSENSITIVE_ORDER );        m_mask = createMask( actions );        StringBuffer buffer = new StringBuffer();        for( int i = 0; i < pageActions.length; i++ )        {            buffer.append( pageActions[i] );            if ( i < ( pageActions.length - 1 ) )            {                buffer.append( ACTION_SEPARATOR );            }        }        m_actionString = buffer.toString();    }    /**     * Creates a new PagePermission for a specified page and set of actions.     * @param page The wikipage.     * @param actions A set of actions; a comma-separated list of actions.     */    public PagePermission( WikiPage page, String actions )    {        this( page.getWiki() + WIKI_SEPARATOR + page.getName(), actions );    }    /**     * Two PagePermission objects are considered equal if their actions (after     * normalization), wiki and target are equal.     * @param obj {@inheritDoc}     * @return {@inheritDoc}     */    public final boolean equals( Object obj )    {        if ( !( obj instanceof PagePermission ) )        {            return false;        }        PagePermission p = (PagePermission) obj;        return  p.m_mask == m_mask && p.m_page.equals( m_page )                && p.m_wiki != null && p.m_wiki.equals( m_wiki );    }    /**     * 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.     *     * @return {@inheritDoc}     */    public final String getActions()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -