Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
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;
 }