Documentation


SEARCH

TABLE OF CONTENT

    1. Getting started 2. Basic concepts 3. Request dispatching 4. Context container 5. Dual MVC 6. Component model: 7. Security 8. Configuration 9. Session handling 10. I18n 11. Cache 12. Logging 13. Error handling 14. Advanced Topics 15. API reference

      Tutorials: Frequently Asqued Questions

      See also:


      Authorization in Lion

      A Role Based Access Control

      Table of Contents

      What's Authorization?

      Authorization is finding out if the person, once identified, is permitted to access to a system resource (to view a page, to call a model service, ...).
      This is usually determined by finding out if that person is a part of a particular group, if that person has paid admission, or has a particular level of security clearance. Authorization is equivalent to checking the guest list at an exclusive party, or checking for your ticket when you go to the opera.

      As well as other software pieces, there are several patterns to implement the authorization.
      One of the most commonly used is the known as Role Based Access Control (RBAC).

      What's a Role Based Access Control?

      Role Based Access Control (or just RBAC) is a method to control access to resources on an information system. It's a model for controlling access to resources where permitted actions on resources are identified with roles rather than with individual subject identities.

      It was developed in Lion to overcome the complexities of managing individual user permissions and their assignments. The RBAC effort is motivated by concurrent efforts to:

      • Simplify authorization management
      • Reduce administrative costs
      • Improve security
      • Provide low-level authorization granularity

      The operational benefits of RBAC have long been recognized since it simplifies the complexity of managing user permissions, thus providing reduced administrative cost and time.

      RBAC allow us to define roles to users as well as permissions to system resources:

      • User: An user represents the client (commonly the end-user) of your web application. In Lion, the user is an instance of a class implementing the __IUser, but usually a class extending the __User.
      • Role: A role is a collection of permissions. As such, a role serves no purpose unless permissions are assigned to it. An example role might be a 'Message Board Topic Administrator.' The role might be assigned permissions to View, Update, and Delete Message Board Topic resources that have company scope. Ultimately, a user assigned the 'Message Board Topic Administrator' role would be able to view, update, and delete any topic for any message board in the company. Roles are assigned to users. Roles can also be compounded by other roles (junior roles), inheriting all their permissions.
      • Permission: The ability or right to perform some action on some resource, possibly only under certain specified conditions.
      • System Resource: A system resource is a generic term for any object represented in the web application. In Lion, a system resource is a class implementing the __ISystemResource (usually a class extending the __SystemResource).

      Roles

      Roles are associated to users. Basically, a role is a very flexible way to assign permissions to users.

      Roles can also be grouped in hierarchies to make easy the permission assignment:

      • A junior role is when, in a role hierarchy, Role A is junior to Role B if Role B inherits all the permissions associated with Role A.
      • A senior role is when, in a role hierarchy, Role A is senior to Role B if Role A inherits all the permissions associated with Role B.

      All roles can be defined declaratively inside the role-definitions configuration section.

      i.e. imagine a configuration for a Forum Application: users can read and write messages while administrator can delete and modify messages. Of course, administrator can also read and write messages.

      1. <?xml version "1.0" standalone="yes"?>
      2. <configuration>
      3.  
      4.   <role-definitions>
      5.     
      6.     <role id="FORUM_USER">
      7.       <permissions>
      8.         <permission id="READ_POSTS"/>
      9.         <permission id="WRITE_POSTS"/>
      10.       </permissions>
      11.     </role>
      12.     
      13.     <role id="FORUM_ADMIN">
      14.       <permissions>
      15.         <permission id="DELETE_POSTS"/>
      16.         <permission id="MODIFY_POSTS"/>
      17.       </permissions>
      18.       <junior-roles>
      19.         <ref id="FORUM_USER"/>
      20.       </junior-roles>
      21.     </role>
      22.  
      23.   </role-definitions>

      In this example, the FORUM_USER role is junior role to FORUM_ADMIN.
      Users with the FORUM_USER role will have the READ_POSTS and WRITE_POSTS permissions. It is, they will be able to read and write post in the forum.
      At the same time, users with the FORUM_ADMIN role will have DELETE_POSTS and MODIFY_POSTS permissions as well as READ_POSTS and WRITE_POSTS (inherited from FORUM_USER junior role). It is, they will be able to delete and modify post in the forum as well as read and write posts.

      Junior roles capability is very usefull: By adding a new permission to a junior role, all the senior roles will inherit that permission, becoming the permissions management more maintenable.

      Permissions

      Permissions are associated to roles (as we have seen in the previous section) and to system resources (defining the required permission to grant the access to a system resource).

      In Lion, also in general, a system resource can have just one permission associated.
      Instead of allowing the assignment of multiple permissions to system resources, we can define permissions hierarchies:

      • A junior permission is when, in a permission hierarchy, Permission A is junior to Permission B if all the system resources requiring the Permission A are accessible by having the permission B.
      • A senior permission is when, in a permission hierarchy, Permission A is senior to Permission B if all the system resources requiring the Permission B are accessible by having the permission A.

      All permissions can be defined declaratively inside the permission-definitions configuration section.

      i.e. continuing with our Forum, let's define permissions:

      1. <?xml version "1.0" standalone="yes"?>
      2. <configuration>
      3.  
      4.  <permission-definitions>
      5.  
      6.     <permission id="READ_POSTS"/>
      7.     <permission id="WRITE_POSTS"/>
      8.     <permission id="DELETE_POSTS"/>
      9.     <permission id="MODIFY_POSTS"/>
      10.     
      11.     <permission id="ADMIN_POSTS">
      12.       <junior-permissions>
      13.         <ref id="DELETE_POSTS"/>
      14.         <ref id="MODIFY_POSTS"/>
      15.       </junior-permissions>
      16.     </permission>
      17.     
      18.   </permission-definitions>
      19.   
      20. </configuration>

      In this example, DELETE_POSTS and MODIFY_POSTS permissions are junior permissions to ADMIN_POSTS.
      i.e., roles with the ADMIN_POSTS permission will be able to access to system resources that require the DELETE_POSTS or MODIFY_POSTS permissions, because ADMIN_POSTS is senior permission to DELETE_POSTS and MODIFY_POSTS.

      The PERMISSION_ALL permission

      There is an special permission in Lion: PERMISSION_ALL.
      This permission is a senior permission to every permission within your project. A role with this permission is able to access to all system resources. So, take care assigning this permission :)

      Ah! do not define a permission with this name, is reserved for this special permission.


      System Resources

      As defined previously, A system resource is a generic term for any object represented in the web application.
      In terms of authorization, let's focus on a system resource as an object protected by the RBAC.
      In Lion, a system resource is just a class implementing the __ISystemResource, but usually a class extending the __SystemResource.

      The following classes extends the __SystemResource:

      Protecting Action Controllers

      We can assign a permission to each action controller declarativelly by ussing the permission tag within the controller definition.

      i.e.

      1. <?xml version "1.0" standalone="yes"?>
      2. <configuration>
      3.  
      4.   <controller-definitions>
      5.  
      6.     <controller code="adminForum" class="AdminForumController">
      7.       <permission id="ADMIN_POSTS"/>  
      8.     </controller>
      9.  
      10.   </controller-definitions>
      11.   
      12. </configuration>
      In this example, we are protecting the AdminForumController with the ADMIN_POSTS permission. So, just users with that permission could execute actions within this controller.

      Note that protecting action controllers is similar to protect pages, since the client request for actions, nor pages.


      Protecting Model Services

      We can assign a permission to each model service declarativelly by ussing the permission tag within the model All __View derived classes are protected by the RBAC because the __View class is a child class of the __SystemResource.

      i.e.

      1. <?xml version "1.0" standalone="yes"?>
      2.  
      3. <configuration>
      4.  
      5.   <model-services>
      6.   
      7.     <class name="ForumManager">
      8.  
      9.       <service name="getPosts" class-method="getPosts">
      10.         <permission id="READ_POSTS"/>
      11.       </service>
      12.  
      13.       <service name="createPost" class-method="createPost">
      14.         <permission id="WRITE_POSTS"/>
      15.       </service>
      16.  
      17.     </class>
      18.   
      19.   </model-services>
      20.   
      21. </configuration>
      In this example, we are protecting the service getPosts with the READ_POSTS permission while we are protecting the service createPost with the WRITE_POSTS permission. So, a call to the model service createPost is allowed just if the user in session has the permission WRITE_POSTS, it is, if the user has a role that contains that permission.

      Protecting model services becomes interesting when we have to expose some of them, i.e. by webservices.


      Protecting page zones

      We can protect zones within a page by ussing the protected section component.

      This component is used as a tag (protectedsection component tag) in a template, protecting the area closed between the begin and the end tag.

      i.e.

      1. <html>
      2. <body>
      3.  
      4. This content is not protectedEverybody can see it.
      5.  
      6. <comp:protectedsection permission="READ_PROTECTED_CONTENT">
      7.  
      8. The content closed here by the protectedsection tags is just 
      9. shown to users with the READ_PROTECTED_CONTENT permission.
      10.  
      11. </comp:protectedsection>
      12.  
      13. </body>
      14. </html>
      In this example, we have put a protectedsection component that requires the READ_PROTECTED_CONTENT permission.
      It means that users without this permission couldn't see the content protected.