Exemplo n.º 1
0
 public function getAuthenticationObject(Request $request)
 {
     $registry = Registry::getInstance();
     // if the authentication_source is set in the request, then it takes precedence
     $override = $request->getParam("authentication_source");
     if ($override == null) {
         // otherwise, see if one has been set in session from a previous login
         $session_auth = $request->getSessionData("auth");
         if ($session_auth != "") {
             $override = $session_auth;
         }
     }
     // make sure it's in our list, or if blank still, we get the default
     $name = $registry->getAuthenticationSource($override);
     // sanitize
     $name = preg_replace('/\\W/', '', $name);
     // main class
     $class_name = 'Application\\Model\\Authentication' . '\\' . ucfirst($name);
     // local custom version
     $local_file = "custom/Authentication/{$name}.php";
     if (file_exists($local_file)) {
         require_once $local_file;
         $class_name = 'Local\\Authentication' . '\\' . ucfirst($name);
         if (!class_exists($class_name)) {
             throw new \Exception("the custom authentication scheme '{$name}' should have a class called '{$class_name}'");
         }
     }
     // make it
     $authentication = new $class_name($request);
     if (!$authentication instanceof Scheme) {
         throw new \Exception("class '{$class_name}' for the '{$name}' authentication scheme must extend Authentication");
     }
     return $authentication;
 }
Exemplo n.º 2
0
 /**
  * Create a User
  * 
  * @param Request $request		[optional] create user from existing session
  */
 public function __construct(Request $request = null)
 {
     self::$request = $request;
     if ($request != "") {
         // user attributes
         $this->username = $request->getSessionData("username");
         $this->role = $request->getSessionData("role");
         $this->ip_address = $request->server()->get('REMOTE_ADDR');
         // local ip range from config
         $registry = Registry::getInstance();
         $this->ip_range = $registry->getConfig("LOCAL_IP_RANGE", false, null);
         // temporarily authenticate users
         if ($this->username == "") {
             // on campus
             if ($this->isInLocalIpRange() == true) {
                 $this->username = self::genRandomUsername(self::LOCAL);
                 $this->role = self::LOCAL;
             } else {
                 $this->username = self::genRandomUsername(self::GUEST);
                 $this->role = self::GUEST;
             }
             $request->setSessionData("username", $this->username);
             $request->setSessionData("role", $this->role);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Create UserOptions object saving Request with session data
  * @param Request $request
  */
 public function __construct(Request $request)
 {
     $this->container = $request->getContainer('pazpar2options');
     if ($request->getParam('sourcetype') != '') {
         $this->setSessionData('source_type', $request->getParam('sourcetype'));
         // if changing sourcetype, clear all old target selections
         $this->unsetSessionData('selectedby');
     } else {
         if (!$this->existsInSessionData('source_type')) {
             $config = Config::getInstance();
             $this->setSessionData('source_type', $config->getDefaultSourceType());
         }
     }
     // if this is a submit, change the session values as required
     if ($request->getParam('changetargets') != '') {
         $selectedby = $request->getParam('selectedby');
         if ($selectedby == 'names') {
             $targets = $request->getParam('target', null, true);
             $this->setSessionData('names', $targets);
             $this->setSessionData('selectedby', $selectedby);
         } else {
             if ($selectedby == 'subjects') {
                 $subjects = $request->getParam('subject', null, true);
                 $this->setSessionData('subjects', $subjects);
                 $this->setSessionData('selectedby', $selectedby);
             } else {
                 if ($selectedby == 'entitlements') {
                     $entitlements = $request->getParam('entitlement', null, true);
                     $this->setSessionData('entitlements', $entitlements);
                     $this->setSessionData('selectedby', $selectedby);
                 }
             }
         }
     }
     // retrieve the session values
     // set the actual targets to use
     if ($this->existsInSessionData('selectedby')) {
         $key = $this->getSessionData('selectedby');
     } else {
         $this->setSessionData('selectedby', 'names');
         $this->setSessionData('names', array('all'));
         $key = 'names';
     }
     $this->calculateTargets($key, $this->getSessionData($key), $this->getSessionData('source_type'));
 }
Exemplo n.º 4
0
 /**
  * Construct a URL, taking into account routes, based on supplied parameters
  * 
  * @param array $params				the elements of the url
  * @param bool $full				[optional] should be full url
  * @param bool $force_secure		[optional] should be https://
  * @param array $options			route/assemble options
  */
 public function url_for(array $params, $full = false, $force_secure = false, $options = array())
 {
     // use the default route if no option supplied
     if (count($options) == 0) {
         $options["name"] = "default";
     }
     if (null === $this->router) {
         return '';
     }
     // this only returns the route, no querystring
     $url = $this->router->assemble($params, $options);
     // remove trailing '/index' from generated URLs.
     if (6 <= strlen($url) && '/index' == substr($url, -6)) {
         $url = substr($url, 0, strlen($url) - 6);
     }
     // append query string
     $query_string = array();
     // figure out which of our params matched the route
     $request = new Request();
     $request->setUri($url);
     $route_match = $this->router->match($request);
     // remove those from the supplied params
     if ($route_match instanceof RouteMatch) {
         $in_route = array_keys($route_match->getParams());
         foreach ($params as $key => $value) {
             if (!in_array($key, $in_route)) {
                 $query_string[$key] = $value;
             }
         }
     } else {
         $query_string = $params;
     }
     // take any remaining as the query string
     if (count($query_string) > 0) {
         $url .= "?";
         $x = 0;
         foreach ($query_string as $name => $value) {
             if ($value == "") {
                 continue;
             }
             if ($x > 0) {
                 $url .= '&';
             }
             // value is array
             if (is_array($value)) {
                 foreach ($value as $v) {
                     $url .= $name . '=' . urlencode($v) . '&';
                 }
             } else {
                 $url .= $name . '=' . urlencode($value);
             }
             $x++;
         }
     }
     // is it supposed to be a full url?
     if ($full == true) {
         $base = $this->getServerUrl($force_secure);
         $url = $base .= $url;
     }
     return $url;
 }
Exemplo n.º 5
0
 /**
  * Transform XML to HTML
  * 
  * @param mixed $xml  XML-like data
  * @param string $path_to_xsl
  * @param array $params
  */
 protected function transform($xml, $path_to_xsl, array $params = array())
 {
     $registry = Registry::getInstance();
     $import_array = array();
     // the xsl lives here
     $distro_xsl_dir = $this->_script_path . "/";
     $local_xsl_dir = realpath(getcwd()) . "/views/";
     // language file
     $request = new Request();
     $language = $request->getParam("lang");
     if ($language == "") {
         $language = $registry->defaultLanguage();
     }
     // english file is included by default (as a fallback)
     array_push($import_array, "labels/eng.xsl");
     // if language is set to something other than english
     // then include that file to override the english labels
     if ($language != "eng" && $language != '') {
         array_push($import_array, "labels/{$language}.xsl");
     }
     // make sure we've got a reference to the local includes too
     array_push($import_array, "includes.xsl");
     // transform
     $xsl = new Xsl($distro_xsl_dir, $local_xsl_dir);
     return $xsl->transformToXml($xml, $path_to_xsl, $this->format, $params, $import_array);
 }