Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will provide a brief descriptions of how to use the Authorization, however more detailed information would need to be inferred by reviewing SocialEngine's code. As a note, while we don't compile documentation for SocialEngine, our developers have used the PHPDocumentor style syntax through out our code and you can use an IDE like Neatbeans (http://netbeans.org/) to quickly access that information.</p> <p>SocialEngine has a few controller action helper classes that are used for query authorization within action controllers:</p> <ul> <li>application/modules/Authorization/Controller/Action/Helper/RequireAuth.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireAbstract.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireAdmin.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireSubject.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireUser.php</li> </ul> <p>For the most part the only ones you'll concern yourself with are these:</p> <ul> <li>application/modules/Authorization/Controller/Action/Helper/RequireAuth.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireSubject.php</li> <li>application/modules/Core/Controller/Action/Helper/RequireUser.php</li> </ul> <p>A good example of how these helpers are used can be found in the Album_AlbumController class: application/modules/Album/controllers/AlbumController.php</p> <pre><code>public function init() { if( !$this-&gt;_helper-&gt;requireAuth()-&gt;setAuthParams('album', null, 'view')-&gt;isValid() ) return; if( 0 !== ($photo_id = (int) $this-&gt;_getParam('photo_id')) &amp;&amp; null !== ($photo = Engine_Api::_()-&gt;getItem('album_photo', $photo_id)) ) { Engine_Api::_()-&gt;core()-&gt;setSubject($photo); } else if( 0 !== ($album_id = (int) $this-&gt;_getParam('album_id')) &amp;&amp; null !== ($album = Engine_Api::_()-&gt;getItem('album', $album_id)) ) { Engine_Api::_()-&gt;core()-&gt;setSubject($album); } } public function editAction() { if( !$this-&gt;_helper-&gt;requireUser()-&gt;isValid() ) return; if( !$this-&gt;_helper-&gt;requireSubject('album')-&gt;isValid() ) return; if( !$this-&gt;_helper-&gt;requireAuth()-&gt;setAuthParams(null, null, 'edit')-&gt;isValid() ) return; </code></pre> <p>The code in the init function simply set's the requirements for accessing the page, and then within the editAction function, checks are ran against the authorization data. The requireSubject and requireUser helpers are pretty straight forward:</p> <ol> <li>requireSubject expects that subject for the page is set which in the above example gets done in the init function </li> <li>requireUser checks to see if the viewer is a logged in user</li> </ol> <p>The requireAuth helper is a little less straight forward. I'll omit most of the abstract inner-workings for the sake of brevity. In the end, the helper points to the Authorization_Api_Core::isAllowed function: application/modules/Authorization/Core/Api.php</p> <pre><code>/** * Gets the specified permission for the context * * @param Core_Model_Item_Abstract|string $resource The resource type or object that is being accessed * @param Core_Model_Item_Abstract $role The item (user) performing the action * @param string $action The name of the action being performed * @return mixed 0/1 for allowed, or data for settings */ public function isAllowed($resource, $role, $action = 'view') </code></pre> <p>The $resource and $role objects that the function expects are instances of Zend_Db_Table_Row which is termed Models within SocialEngine and are expected to be located in the Models directory of a module. When the isAllowed function is invoked, the authorization api will query the database against the engine4_authorization_allow, engine4_authorization_levels and engine4_authorization_permissions tables.</p> <ol> <li>The engine4_authorization_levels table contains the member levels created by SocialEngine out of the box, as well as custom member levels created from the Manage > Member Levels section in the admin panel.</li> <li>The engine4_authorization_permissions table contain all the default and admin specified permission handling, such as member level settings. </li> <li>The engine4_authorization_allow contains the the permission data for individual objects. For example information about who is able to view a photo album would be placed there. Whether or not a engine4_authorization_allow.role_id (maps to item id for a model) is allowed to access the engine4_authorization_allow.resource_id (maps to item id for a model) is determined by the engine4_authorization_allow.value column which should contain a number 0-5.</li> </ol> <p>application/modules/Authorization/Api/Core.php</p> <pre><code>class Authorization_Api_Core extends Core_Api_Abstract { /** * Constants */ const LEVEL_DISALLOW = 0; const LEVEL_ALLOW = 1; const LEVEL_MODERATE = 2; const LEVEL_NONBOOLEAN = 3; const LEVEL_IGNORE = 4; const LEVEL_SERIALIZED = 5; </code></pre> <p>0) Not allowed to access the linked resource. This is the same as the row not existing in the allow table</p> <p>1) Allowed too access the linked resource</p> <p>2) Allowed to access and moderate resources (ie. Superadmin, Admin and Moderator member level)</p> <p>3-5) Get ignored as disallowed. These expect some custom logic in order to handle authorization appropriately.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload