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

📄 pagepermission.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        return m_actionString;    }    /**     * Returns the name of the wiki page represented by this permission.     * @return the page name     */    public final String getPage()    {        return m_page;    }    /**     * Returns the name of the wiki containing the page represented by     * this permission; may return the wildcard string.     * @return the wiki     */    public final String getWiki()    {        return m_wiki;    }    /**     * Returns the hash code for this PagePermission.     * @return {@inheritDoc}     */    public final int hashCode()    {        //  If the wiki has not been set, uses a dummy value for the hashcode        //  calculation.  This may occur if the page given does not refer        //  to any particular wiki        String wiki = m_wiki != null ? m_wiki : "dummy_value";        return m_mask + ( ( 13 * m_actionString.hashCode() ) * 23 * wiki.hashCode() );    }    /**     * <p>     * PagePermission can only imply other PagePermissions; no other permission     * types are implied. One PagePermission implies another if its actions if     * three conditions are met:     * </p>     * <ol>     * <li>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.</li>     * <li>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.</li>     * <li>All of other PagePermission's actions are equal to, or a subset of,     * those of this permission</li>     * </ol>     * @see java.security.Permission#implies(java.security.Permission)     *      * @param permission {@inheritDoc}     * @return {@inheritDoc}     */    public final boolean implies( Permission permission )    {        // Permission must be a PagePermission        if ( !( permission instanceof PagePermission ) )        {            return false;        }        // Build up an "implied mask"        PagePermission p = (PagePermission) permission;        int impliedMask = impliedMask( m_mask );        // If actions aren't a proper subset, return false        if ( ( impliedMask & p.m_mask ) != p.m_mask )        {            return false;        }        // See if the tested permission's wiki is implied        boolean impliedWiki = isSubset( m_wiki, p.m_wiki );        // If this page is "*", the tested permission's        // page is implied        boolean impliedPage = isSubset( m_page, p.m_page );        return  impliedWiki && impliedPage;    }    /**     * Returns a new {@link AllPermissionCollection}.     * @see java.security.Permission#newPermissionCollection()     * @return {@inheritDoc}     */    @Override    public PermissionCollection newPermissionCollection()    {        return new AllPermissionCollection();    }    /**     * Prints a human-readable representation of this permission.     * @see java.lang.Object#toString()     *      * @return Something human-readable     */    public final String toString()    {        String wiki = ( m_wiki == null ) ? "" : m_wiki;        return "(\"" + this.getClass().getName() + "\",\"" + wiki + WIKI_SEPARATOR + m_page + "\",\"" + getActions() + "\")";    }    /**     * Creates an "implied mask" based on the actions originally assigned: for     * example, delete implies modify, comment, upload and view.     * @param mask binary mask for actions     * @return binary mask for implied actions     */    protected static final int impliedMask( int mask )    {        if ( ( mask & DELETE_MASK ) > 0 )        {            mask |= MODIFY_MASK;        }        if ( ( mask & RENAME_MASK ) > 0 )        {            mask |= EDIT_MASK;        }        if ( ( mask & MODIFY_MASK ) > 0 )        {            mask |= EDIT_MASK | UPLOAD_MASK;        }        if ( ( mask & EDIT_MASK ) > 0 )        {            mask |= COMMENT_MASK;        }        if ( ( mask & COMMENT_MASK ) > 0 )        {            mask |= VIEW_MASK;        }        if ( ( mask & UPLOAD_MASK ) > 0 )        {            mask |= VIEW_MASK;        }        return mask;    }    /**     * Determines whether one target string is a logical subset of the other.     * @param superSet the prospective superset     * @param subSet the prospective subset     * @return the results of the test, where <code>true</code> indicates that     *         <code>subSet</code> is a subset of <code>superSet</code>     */    protected static final boolean isSubset( String superSet, String subSet )    {        // If either is null, return false        if ( superSet == null || subSet == null )        {            return false;        }        // If targets are identical, it's a subset        if ( superSet.equals( subSet ) )        {            return true;        }        // If super is "*", it's a subset        if ( superSet.equals( WILDCARD ) )        {            return true;        }        // If super starts with "*", sub must end with everything after the *        if ( superSet.startsWith( WILDCARD ) )        {            String suffix = superSet.substring( 1 );            return subSet.endsWith( suffix );        }        // If super ends with "*", sub must start with everything before *        if ( superSet.endsWith( WILDCARD ) )        {            String prefix = superSet.substring( 0, superSet.length() - 1 );            return subSet.startsWith( prefix );        }        return false;    }    /**     * Private method that creates a binary mask based on the actions specified.     * This is used by {@link #implies(Permission)}.     * @param actions the actions for this permission, separated by commas     * @return the binary actions mask     */    protected static final int createMask( String actions )    {        if ( actions == null || actions.length() == 0 )        {            throw new IllegalArgumentException( "Actions cannot be blank or null" );        }        int mask = 0;        String[] actionList = StringUtils.split( actions, ACTION_SEPARATOR );        for( String action : actionList )        {            if ( action.equalsIgnoreCase( VIEW_ACTION ) )            {                mask |= VIEW_MASK;            }            else if ( action.equalsIgnoreCase( EDIT_ACTION ) )            {                mask |= EDIT_MASK;            }            else if ( action.equalsIgnoreCase( COMMENT_ACTION ) )            {                mask |= COMMENT_MASK;            }            else if ( action.equalsIgnoreCase( MODIFY_ACTION ) )            {                mask |= MODIFY_MASK;            }            else if ( action.equalsIgnoreCase( UPLOAD_ACTION ) )            {                mask |= UPLOAD_MASK;            }            else if ( action.equalsIgnoreCase( DELETE_ACTION ) )            {                mask |= DELETE_MASK;            }            else if ( action.equalsIgnoreCase( RENAME_ACTION ) )            {                mask |= RENAME_MASK;            }            else            {                throw new IllegalArgumentException( "Unrecognized action: " + action );            }        }        return mask;    }}

⌨️ 快捷键说明

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