예제 #1
0
 /**
  * This method return a singleton instance of __RoleManager instance
  *
  * @return __RoleManager a reference to the current __RoleManager instance
  */
 public static function &getInstance()
 {
     if (self::$_instance == null) {
         // Use "Lazy initialization"
         self::$_instance = new __RoleManager();
     }
     return self::$_instance;
 }
 public function &loadAnonymousUser()
 {
     $return_value = new __User();
     //If there is not need to authenticate the user, will set the admin role:
     if (__ContextManager::getInstance()->getContext('LION_ADMIN_AREA')->getPropertyContent('LION_ADMIN_AUTH_REQUIRED') == false) {
         $admin_role = __RoleManager::getInstance()->getRole('ADMIN');
         $return_value->addRole($admin_role);
     }
     $return_value->setCredentials(new __AnonymousCredentials());
     return $return_value;
 }
 /**
  * Get an array of roles corresponding to a given user
  * 
  * @return array
  */
 public function _loadRoles($dbh, $user_id)
 {
     $return_value = array();
     $statement = $dbh->prepare("SELECT * \n                                    FROM roles \n                                    WHERE user_id = ?");
     $statement->execute(array($user_id));
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     $roles_info = $stmt->fetchAll();
     foreach ($roles_info as $role_info) {
         $role = __RoleManager::getInstance()->getRole($role_info['role']);
         $return_value[] = $role;
     }
     return $return_value;
 }
 /**
  * Get the user identity and returns a user corresponding
  * to the given identity.
  * 
  * Note that the returned user contains his
  * credentials in order to be used by the security
  * framework
  * 
  */
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $user = null;
     if ($user_identity instanceof __UsernameIdentity) {
         //get the login string from the user identity:
         $login = $user_identity->getUsername();
         //check if the login correspond to any of our
         //valid logins:
         if (key_exists($login, $this->_user_and_passwords)) {
             //create a user instance and set the credentials:
             $user = new __User();
             $credentials = new __PasswordCredentials();
             $credentials->setPassword($this->_user_and_passwords[$login]);
             $user->setCredentials($credentials);
             //get the role identified as REGISTERED_USER:
             $role = __RoleManager::getInstance()->getRole('REGISTERED_USER');
             //assign the role to the user:
             $user->addRole($role);
         }
     }
     return $user;
 }