Changes between Version 1 and Version 2 of GuardPlugin


Ignore:
Timestamp:
2010-08-19T17:58:20Z (14 years ago)
Author:
Pan Luo
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • GuardPlugin

    v1 v2  
    55The GuardPlugin is a CakePHP plugin to provide flexible authentication framework. With this plugin, developers are able to write their own authentication module easily and fast. The plugin also provides some build-in authentication module, such as Shibboleth and default (original). This plugin is build based on CakePHP 1.3 [http://api13.cakephp.org/class/auth-component AuthComponent] and it provides full back compatibly. If the application is developed on [http://api13.cakephp.org/class/auth-component AuthComponent], no change is required for the existing code.
    66
     7== Requirements ==
     8 * CakePHP 1.3+
     9
    710== Download ==
    811
    912== Install ==
    1013
     14The GuardPlugin should be install into app/plugins/guard
     15
     16The tree structure should look like this:
     17
     18{{{
     19app/plugins/guard
     20|-- config
     21|   `-- guard_default.php
     22|-- controllers
     23|   |-- components
     24|   |   |-- auth_module.php
     25|   |   |-- default_module.php
     26|   |   |-- guard.php
     27|   |   `-- shibboleth_module.php
     28|   `-- guard_controller.php
     29`-- views
     30    |-- elements
     31    |   |-- login_default.ctp
     32    |   `-- login_shibboleth.ctp
     33    `-- guard
     34        `-- login.ctp
     35}}}
     36
     37After the installation of the files, the initial copy of the configuration file should be copy from app/plugins/guard/config/guard_default.php to app/config/guard.php.
     38
     39{{{
     40cp app/plugins/guard/config/guard_default.php app/config/guard.php
     41}}}
     42
    1143== Configuration ==
    1244
     45The plugin configuration file is located in app/config/guard.php. It is a standard CakePHP configuration file reading by [http://book.cakephp.org/view/42/The-Configuration-Class#load-415 Configuration::load] method. All the configurations are defined in $config array.
     46
     47To change which module to use for authentication:
     48
     49{{{
     50$config['Guard.AuthModule.Name'] = "Default" //options are Default and Shibboleth
     51}}}
     52
     53Some of the AuthComponent properties can be override through the configuration file.
     54
    1355== Using Existing Authentication Modules ==
     56Currently, the authentication modules that come with the plugin are:
     57
     58 * Default: CakePHP build-in authentication module ([http://api13.cakephp.org/class/auth-component AuthComponent])
     59 * Shibboleth: Shibboleth authentication module. It needs the HTTP server to be configured as service provider (SP)
    1460
    1561=== Default Module ===
     62This module is using CakePHP build-in authentication component [http://api13.cakephp.org/class/auth-component AuthComponent] to verify the users.
    1663
    1764=== Shibboleth Module ===
     65This module supports [http://shibboleth.internet2.edu/ Shibboleth] as the external authentication method. It requires the HTTP server to be set up as the service provider (SP). The users will be redirected to an external (central) login page when they click on login button. Once they logged in successfully, they will be verified against the internal database to see if they have the valid account and permission to access the resources in the application. The user table and fields can be defined in the configuration file.
    1866
    19 == Develop New Authentication Module ==
     67The configuration parameters for Shibboleth are:
     68{{{
     69#!php
     70$config['Guard.AuthModule.Shibboleth'] = array('sessionInitiatorURL' => 'https://%HOST%/Shibboleth.sso/Login',
     71                                               'logoutURL'           => 'https://%HOST%/Shibboleth.sso/Logout',
     72                                               'fieldMapping'        => array('eppn'        => 'username',
     73                                                                              'affiliation' => 'role',
     74                                                                             ),
     75                                               'mappingRules'        => array('eppn'        => array('/@ubc.ca/' => ''),
     76                                                                              'affiliation' => array('/staff@ubc.ca/' => 'admin'),
     77                                                                             ),
     78                                               'loginError'          => 'You have successfully logged through Shibboleth. But you do not have access this appliction.',
     79                                              );
     80}}}
     81* sessionInitiatorURL: The URL for the Shibboleth login. %HOST% will be replaced to the actual host name
     82* logoutURL: The URL for Shibboleth logout. %HOST% will be replaced to the actual host name
     83* fieldMapping: The array to map the attributes from Shibboleth to database fields. The keys are the Shibboleth attributes and values are the fields in database.
     84* mappingRules: The array of rules for how to convert the values. The rules are regular expressions.
     85* loginError: The error message when user logged in successfully through Shibboleth but do not have an valid account or permission in the application. This is an example to override the [http://api13.cakephp.org/class/auth-component AuthComponent] properties.
     86
     87== Developing New Authentication Module ==
     88All the authentication modules extend !AuthModule, which provides some default properties and methods required by the authentication module.
     89Every authentication must implement  authenticate() method to verify the user. The authentication module should like look this:
     90{{{
     91#!php
     92class MyAuthModule extends AuthModule {
     93  var $name         = 'MyAuth';
     94  var $hasLoginForm = true;
     95  function authenticate() {
     96    // return true if user is verified and false if not.
     97  }
     98}
     99}}}
     100
     101 * $name: The name of the authentication module.
     102 * $hasLoginForm: If this module has login form
     103
     104