Source for file auth_object_linker.php

Documentation is available at auth_object_linker.php

  1. <?php
  2.     /**
  3.     * Sloodle object authorization linker.
  4.     * Allows authorised objects in SL to delegate authorisation to other objects,
  5.     *  or allows new objects in SL to initiate their own authorisation.
  6.     * (Creates a new entry in the 'sloodle_active_object' DB table.)
  7.     *
  8.     * @package sloodleclassroom
  9.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Edmund Edgar
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.     
  17.     // If fully authorising a new object ('delegating' trust),
  18.     //  then the following parameters are required:
  19.     //
  20.     //  sloodlecontrollerid = the ID of the controller through which the current object may access Sloodle
  21.     //  sloodlepwd = the prim password or object-specific session key to authenticate access
  22.     //  sloodleobjuuid = the UUID of the object being authorised
  23.     //  sloodleobjname = the name of the object being authorised
  24.     //  sloodleobjpwd = a password for the new object
  25.     //
  26.     // The following parameters are optional:
  27.     //
  28.     //  sloodleobjtype = the type identifier for the object being authorised. Can be overridden later.
  29.     //
  30.     // With the above information, a new entry is made, indicating that the object is fully authorised.
  31.     // The new object can ONLY be authorised against the controller the request is received on.
  32.     // If successful, the status code returned is 1, and the data line will contain the authorisation ID of the object which has been authorised.
  33.     
  34.     // If an object needs the user to perform web-authorisation, then it can create an unauthorised entry.
  35.     // To do this, the following parameters are required:
  36.     //
  37.     //  sloodleobjuuid = the UUID of the object being authorised
  38.     //  sloodleobjname = the name of the object being authorised
  39.     //  sloodleobjpwd = a new password for the object (NOT including its UUID)
  40.     //
  41.     // The following parameter is optional:
  42.     //
  43.     //  sloodleobjtype = the type identifier for the object. Can be overridden later.
  44.     //
  45.     // With this information, a new entry is made which is not linked to a particular user account.
  46.     // As such, the entry is deemed 'unauthorised' and cannot be used until authorised.
  47.     // If successful, status code 1 is returned, and the ID of the active object entry is returned on the data line.
  48.     // The object should use this to build a URL to send the user to Sloodle for manual object authorisation.
  49.     // Unauthorised entries will expire within 5 minutes and be deleted.
  50.     
  51.     
  52.     /** Lets Sloodle know we are in a linker script. */
  53.     define('SLOODLE_LINKER_SCRIPT'true);
  54.     
  55.     /** Grab the Sloodle/Moodle configuration. */
  56.     require_once('../sl_config.php');
  57.     /** Include the Sloodle PHP API. */
  58.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  59.     
  60.     // Attempt to authenticate the request
  61.     // (only require authentication if controller ID and/or password is set)
  62.     $authrequired (isset($_REQUEST['sloodlecontrollerid']|| isset($_REQUEST['sloodlepwd']));
  63.     $sloodle new SloodleSession();
  64.     $request_auth $sloodle->authenticate_request($authrequired);
  65.     
  66.     // Get the extra parameters
  67.     $sloodleobjuuid $sloodle->request->required_param('sloodleobjuuid');
  68.     $sloodleobjname $sloodle->request->required_param('sloodleobjname');
  69.     $sloodleobjpwd $sloodle->request->required_param('sloodleobjpwd');
  70.     $sloodleobjtype $sloodle->request->optional_param('sloodleobjtype''');
  71.     $sloodlecloneconfig $sloodle->request->optional_param('sloodlecloneconfig''')// uuid of an object whose config we want to clone. combined with a layout id of 0. used for rezzing a mothership from a set
  72.  
  73.     // When the set rezzes an item from a layout, it can pass this parameter saying what layout entry the object represented.
  74.     // We'll use that to auto-configure the object based on the layout entry configurations.
  75.     $sloodlelayoutentryid $sloodle->request->optional_param('sloodlelayoutentryid',-1,PARAM_INT);
  76.     
  77.     // If the request was authenticated, then the object is being fully authorised.
  78.     // Otherwise, it is simply a 'pending' authorisation.
  79.     if ($request_auth{
  80.         // If the request is coming from an authorised object, then use that user as the authoriser for this one
  81.         $sloodlepwd $sloodle->request->required_param('sloodlepwd');
  82.         $pwdparts explode('|'$sloodlepwd2);
  83.         if (count($pwdparts>= && strlen($pwdparts[0]== 36// Do we have a UUID?
  84.             $userid $sloodle->course->controller->get_authorizing_user($pwdparts[0]);
  85.             if ($userid$sloodle->user->load_user($userid);
  86.         }
  87.         
  88.         // Authorise the object on the controller
  89.         $authid $sloodle->course->controller->register_object($sloodleobjuuid$sloodleobjname$sloodle->user$sloodleobjpwd$sloodleobjtype);
  90.         $alreadyconfigured "0";
  91.         if ($sloodlelayoutentryid 0{
  92.             if ($sloodle->course->controller->configure_object_from_layout_entry($authid$sloodlelayoutentryid)) {
  93.                 // This flag will tell the rezzer to tell the object that it's already configured
  94.                 // That way the object will know not to tell the user to configure it.
  95.                 $alreadyconfigured "1";
  96.             }
  97.         else if ( ($sloodlelayoutentryid == 0&& ($sloodlecloneconfig != '') ) // use 0 to mean we want to configure based on the parent who authorized us, rather than on a layout. Doing this to make the mothership worked when rezzed by a Sloodle Set, but we may want to do the same kind of thing with Registration Booths etc.
  98.             if ($result $sloodle->course->controller->configure_object_from_parent($authid$sloodlecloneconfig)) {
  99.                 // This flag will tell the rezzer to tell the object that it's already configured
  100.                 // That way the object will know not to tell the user to configure it.
  101. $alreadyconfigured $result;
  102.                 $alreadyconfigured "1";
  103.             else {
  104.                 $alreadyconfigured "0";
  105.             }
  106.  
  107.     }
  108.         if ($authid{
  109.             $sloodle->response->set_status_code(1);
  110.             $sloodle->response->set_status_descriptor('OK');
  111.             $sloodle->response->add_data_line($authid);
  112.             $sloodle->response->add_data_line($alreadyconfigured);
  113.         else {
  114.             $sloodle->response->set_status_code(-201);
  115.             $sloodle->response->set_status_descriptor('OBJECT_AUTH');
  116.             $sloodle->response->add_data_line('Failed to register new active object.');
  117.         }
  118.     else {
  119.         // Create a new unauthorised entry
  120.         $authid $sloodle->course->controller->register_unauth_object($sloodleobjuuid$sloodleobjname$sloodleobjpwd$sloodleobjtype);
  121.         if ($authid != 0{
  122.             $sloodle->response->set_status_code(1);
  123.             $sloodle->response->set_status_descriptor('OK');
  124.             $sloodle->response->add_data_line($authid);
  125.             $sloodle->response->add_data_line($alreadyconfigured="0");
  126.         else {
  127.             $sloodle->response->set_status_code(-201);
  128.             $sloodle->response->set_status_descriptor('OBJECT_AUTH');
  129.             $sloodle->response->add_data_line('Failed to register new active object.');
  130.         }
  131.     }
  132.     
  133.     // Render the output
  134.     sloodle_debug('<pre>');
  135.     $sloodle->response->render_to_output();
  136.     sloodle_debug('</pre>');
  137.  
  138. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:00 +0100 by phpDocumentor 1.4.0