예제 #1
0
 /**
  * Escribe la respuesta/headers para pedir autenticacion al usuario.
  *
  * @param respuesta_rest $rta
  *
  * @return mixed
  */
 public function requerir_autenticacion(respuesta_rest $rta)
 {
     //importante las comillas dobles
     $header = 'Digest realm="' . $this->realm . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5($this->realm) . '"';
     $rta->add_headers(array('WWW-Authenticate' => $header));
     $rta->set_data(array('mensaje' => 'autenticación cancelada'));
 }
예제 #2
0
 public function testErrorNegocio()
 {
     $r = new respuesta_rest();
     $error = array('error' => 'e');
     $r->error_negocio($error);
     $this->assertEquals(400, $r->get_status());
     $this->assertEquals($error, $r->get_data());
 }
예제 #3
0
 public function configurar_respuesta(respuesta_rest $rta)
 {
     $datos = array('error' => $this->code, 'mensaje' => $rta->getMessageForCode($this->code), 'descripcion' => $this->getMessage());
     if (!empty($this->detalle)) {
         $datos['detalle'] = $this->detalle;
     }
     $rta->set_data($datos);
     $rta->set_status($this->code);
     return $this;
 }
예제 #4
0
파일: rest.php 프로젝트: emma5021/toba
 public function __construct($settings = array())
 {
     self::$instancia = $this;
     //		$this->autoload();
     $this->container = new Set();
     $this->container['settings'] = array_merge(static::get_default_settings(), $settings);
     // Request default
     $this->container->singleton('request', function ($c) {
         $req = new request();
         $req->set_encoding_datos($c['settings']['encoding']);
         return $req;
     });
     // Respuesta default
     $this->container->singleton('response', function ($c) {
         $respuesta = new respuesta_rest();
         $respuesta->set_encoding_datos($c['settings']['encoding']);
         $respuesta->set_api_version($c['settings']['api_version']);
         return $respuesta;
     });
     // Ruteador default
     $this->container->singleton('router', function ($c) {
         $r = new ruteador($c->lector_recursos, new rest_instanciador());
         return $r;
     });
     // Proveedor de autenticacion --> SE DEBE INDICAR UNO EXTERNAMEN
     $this->container->singleton('autenticador', function ($c) {
         throw new rest_error_interno("Se debe indicar un autenticador que provea los usuarios del negocio");
     });
     // Proveedor de autorizacion
     $this->container->singleton('autorizador', function ($c) {
         $autorizador = new autorizacion_anonima();
         return $autorizador;
     });
     // Firewall default
     $this->container->singleton('firewall', function ($c) {
         $autorizador = new firewall($c->autenticador, $c->autorizador, $c->settings['url_protegida']);
         return $autorizador;
     });
     // Logger
     $this->container->singleton('logger', function ($c) {
         return new logger_vacio();
     });
     $this->container->singleton('lector_recursos', function ($c) {
         return new lector_recursos_archivo($c['settings']['path_controladores'], $c['settings']['prefijo_controladores']);
     });
     $this->container->singleton('controlador_documentacion', function ($c) {
         return new controlador_docs($c['settings']['path_controladores'], $c['settings']['url_api']);
     });
     // Vistas default
     $this->container->singleton('vista', function ($c) {
         $formato = $c['settings']['formato_respuesta'];
         $respuesta = $c['response'];
         switch ($formato) {
             case 'json':
                 return new vista_json($respuesta);
             case 'xml':
                 return new vista_xml($respuesta);
         }
     });
 }
예제 #5
0
 /**
  * Escribe la respuesta/headers para pedir autenticacion al usuario.
  *
  * @param respuesta_rest $rta
  *
  * @return mixed
  */
 public function requerir_autenticacion(respuesta_rest $rta)
 {
     $rta->set_data(array('mensaje' => $this->mensaje));
 }
예제 #6
0
 /**
  * Escribe la respuesta/headers para pedir autenticacion al usuario.
  *
  * @param respuesta_rest $rta
  *
  * @return mixed
  */
 public function requerir_autenticacion(respuesta_rest $rta)
 {
     $rta->set_data(array('mensaje' => 'autenticación cancelada, falta información'));
 }
예제 #7
0
 /**
  * Escribe la respuesta/headers para pedir autenticacion al usuario.
  *
  * @param respuesta_rest $rta
  *
  * @return mixed
  */
 public function requerir_autenticacion(respuesta_rest $rta)
 {
     $rta->add_headers(array('WWW-Authenticate' => 'Basic realm="Usuario de la API"'));
     $rta->set_data(array('mensaje' => 'autenticación cancelada'));
 }
예제 #8
0
 /**
  * Escribe la respuesta/headers para pedir autenticacion al usuario.
  *
  * @param respuesta_rest $rta
  *
  * @return mixed
  */
 public function requerir_autenticacion(respuesta_rest $rta)
 {
     $rta->set_status(401);
     // quizá haya que agregar más detalles al error: http://hdknr.github.io/docs/identity/bearer.html#id5
     $rta->add_headers(array('WWW-Authenticate' => 'Bearer'));
 }