Ejemplo n.º 1
0
 /**
  * Method initialize security context. Check session for user token and
  * initialize authentication and authorization classes
  */
 public function initialize($configuration)
 {
     Event::fire('framework.security.initialize.before', array());
     if (!empty($configuration->security)) {
         $this->_csrf = new CSRF();
         $this->_passwordManager = new PasswordManager($configuration->security);
     } else {
         throw new \Exception('Error in configuration file');
     }
     $session = Registry::get('session');
     $user = $session->get('authUser');
     $authentication = new Authentication\Authentication();
     $this->_authentication = $authentication->initialize($configuration);
     $authorization = new Authorization\Authorization();
     $this->_authorization = $authorization->initialize($configuration);
     if ($user instanceof BasicUser) {
         $this->_user = $user;
         Event::fire('framework.security.initialize.user', array($user));
     }
     if ($this->_authorization->type == 'resourcebase') {
         Event::add('framework.router.findroute.after', function ($path) {
             $role = $this->getAuthorization()->checkForResource($path);
             if ($role !== null) {
                 if ($this->isGranted($role) !== true) {
                     throw new \THCFrame\Security\Exception\Unauthorized();
                 }
             }
         });
     }
     Event::fire('framework.security.initialize.after', array());
     return $this;
 }
 /**
  * 
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->name = $options['credentials']->name;
     $this->pass = $options['credentials']->pass;
 }