示例#1
0
 /**
  * @route /authenticate
  * @method POST
  */
 public function authenticateAction()
 {
     try {
         $params = $this->getParams();
         $login = $params['login'];
         $password = $params['password'];
         $token = UserRepository::getTokenForApi($login, $password);
         $this->router->response()->json(array('token' => $token));
     } catch (BadCredentialException $ex) {
         //throw new UnauthorizedException('Api Authentication failed', $ex->getMessage(), $ex->getCode(), $ex);
         $errorObject = array('id' => '', 'href' => '', 'status' => '401', 'code' => (string) $ex->getCode(), 'title' => 'Api Authentication failed', 'detail' => $ex->getMessage(), 'links' => '', 'path' => '');
         $this->router->response()->code(401)->json($errorObject);
     }
 }
示例#2
0
文件: Auth.php 项目: rk4an/centreon
 /**
  * Check user password
  *
  * @param $username string The username
  * @param $password string The password
  * @param $token string The token
  */
 protected function checkUser($username, $password, $token)
 {
     //$logger = \Monolog\Registry::getInstance('MAIN');
     try {
         $login = htmlentities($username, ENT_QUOTES, "UTF-8");
         if ($this->autologin == 0 || $this->autologin && $token != "") {
             $this->userInfos = UserRepository::checkUser($login, $password);
         } else {
             $this->userInfos = UserRepository::checkUser($login, $password, $token);
         }
         //$logger->debug("Contact '" . $login . "' logged in - IP : " . filter_input(INPUT_SERVER, "REMOTE_ADDR"));
     } catch (Exception $e) {
         if ($this->debug) {
             //$logger->debug($e->getMessage());
         }
         throw new \Centreon\Internal\Exception($e->getMessage(), $e->getCode());
     }
 }
示例#3
0
文件: Api.php 项目: rk4an/centreon
 /**
  * 
  * @param type $requestMethod
  * @param type $requestVersion
  */
 public function executeRoute($requestMethod, $requestVersion = null)
 {
     try {
         $routeVersion = Router::getApiVersion($requestMethod);
         if (in_array($requestMethod, static::$routeAuth)) {
             $headers = $this->request->headers();
             if (!isset($headers['centreon-x-token'])) {
                 throw new BadRequestException('Missing Token', 'The Token for the request is not present');
             }
             $token = $headers['centreon-x-token'];
             if (!\CentreonAdministration\Repository\UserRepository::checkApiToken($token)) {
                 /* method auth */
                 throw new UnauthorizedException('Invalid Token', 'The Token is not valid');
             }
         }
         $methodName = null;
         $currentVersion = null;
         if (isset($routeVersion[$requestVersion])) {
             $methodName = $routeVersion[$requestVersion];
         } elseif (isset($routeVersion)) {
             foreach ($routeVersion as $version => $method) {
                 if (is_null($requestVersion)) {
                     if (is_null($currentVersion)) {
                         $currentVersion = $version;
                         $methodName = $method;
                     } else {
                         if (version_compare($currentVersion, $version, '>')) {
                             $currentVersion = $version;
                             $methodName = $method;
                         }
                     }
                 } else {
                     if (version_compare($version, $requestVersion, '<')) {
                         if (is_null($currentVersion)) {
                             $currentVersion = $version;
                             $methodName = $method;
                         } else {
                             if (version_compare($currentVersion, $version, '>')) {
                                 $currentVersion = $version;
                                 $methodName = $method;
                             }
                         }
                     }
                 }
             }
         }
         if (is_null($methodName)) {
             throw new Exception\Http\NotFoundException('Action does not exist', 'The requested action does not exist');
         }
         // Exexcute Api Method
         $calledMethod = function ($className, $methodName, $request) {
             $classToCall = $className::getHttpCoreInstance($request);
             $classToCall->{$methodName}();
         };
         $className = get_called_class();
         $calledMethod($className, $methodName, $this->request);
     } catch (HttpException $ex) {
         $errorObject = array('id' => '', 'href' => '', 'status' => $ex->getCode(), 'code' => $ex->getInternalCode(), 'title' => $ex->getTitle(), 'detail' => $ex->getMessage(), 'links' => '', 'path' => '');
         $this->router->response()->code($ex->getCode())->json($errorObject);
     } catch (Exception $ex) {
         $this->router->response()->code(500);
     }
 }
示例#4
0
文件: User.php 项目: rk4an/centreon
 /**
  * email getter
  *
  * @return string
  */
 public function getEmail()
 {
     $emails = UserRepository::getEmail($this->id);
     return $emails;
 }