Journal

Xaraya
Browse in : All > Categories > Xaraya

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xd and user-summary-[publicationtype].xd. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-)

Title: Xaraya: Privileges and Content Filtering

Author: jrojr

Date: September 14, 2005 3:23:08 AM or Wed, 14 September 2005 03:23:08

Summary: 

Security checks and masks are there to facilitate the filtering of content to your users in Xaraya.

Body: 

In many websites that are community-based, administrators must create different levels of access for content to control how their members interact with the website. For example, a website may have the following categories of users:

A Hypothetical Example

Usually, the presence of Xaraya's administration panel is determined behind the scenes in PHP, but:

Solution? Use a Security Check

This kind of situation is solved easily through the use of Xaraya security checks. A security check takes a predefined security mask as an argument and compares the privileges specified by the mask against a user's own privileges. If the user's privileges pass the security check, they are allowed to see the content. If not, the content is hidden.

What are Security Masks?

Security masks are a specification of the minimum privileges required to pass a security check. They are defined individually by each Xaraya module at the time of the module's installation. Scrolling through a module's xarinit.php file will eventually lead you to several lines of xarRegisterMask functions — these are the masks that are available for the module.

Anatomy of xarRegisterMask

Below is an example mask from the xarinit.php file from the Articles module, analyzed in parameter order:

xarRegisterMask('EditArticles','All','articles','Article','All','ACCESS_EDIT');

In a sentence, the mask above will pass all users that have at least edit privileges on all articles in the articles module, and it will block all other users.

Security Checks and Security Masks

Once you've discovered the name of a particular security mask, you can use it to perform security checks:

<xar:sec id="unique1" mask="EditArticles" catch="false" component="mycomponent">
    <a href="#xarModURL('articles', 'admin', 'modify', array('aid' => $aid))#&quot;&gt;Edit this Article</a>
&lt;/xar:sec&gt;

In the <xar:sec> tag above, there are three attributes:

If the user's credentials are sufficient, they will see the link to edit the article. For all other users, the link is not displayed, accomplishing the goals set out above.

For more information about security checks, take a look at the reference for the <xar:code><xar:sec></xar:code> tag, as well as Xaraya's Security RFC.

Notes: 

More fields may be available via dynamicdata ..