/**
  * Receive SendGrid Events
  *
  * @return mixed
  */
 public function eventAction()
 {
     /**
      * If Basic Auth is configured, authenticate the request
      */
     if ($this->auth) {
         $this->auth->setRequest($this->getRequest());
         $this->auth->setResponse($this->getResponse());
         $result = $this->auth->authenticate();
         if (!$result->isValid()) {
             return $this->appError('Authentication Failed', $this->getResponse()->getStatusCode(), 'auth_error');
         }
     }
     /**
      * All SendGrid Requests are POSTed
      */
     if (!$this->getRequest()->isPost()) {
         return $this->appError('Method Not Allowed', 405, 'general_error');
     }
     /**
      * Trigger Events for Listeners
      */
     $this->emitter->receiveRequest($this->getRequest());
     /**
      * Return an Empty 200 Response
      */
     return $this->getResponse();
 }
예제 #2
0
 /**
  * Authenticate
  *
  * @throws Exception\RuntimeException
  * @return Authentication\Result
  */
 public function authenticate()
 {
     if (empty($this->request)) {
         throw new Exception\RuntimeException('Request and Response objects must be set before calling authenticate()');
     }
     if ($this->request->getUri()->getScheme() != 'https') {
         return new Result(Result::FAILURE_UNCATEGORIZED, array(), array('Http authentication must be over https'));
     }
     return parent::authenticate();
 }
예제 #3
0
 public function testUnsupportedScheme()
 {
     $response = new Response();
     $headers = new Headers();
     $request = new Request();
     $headers->addHeaderLine('Authorization', 'NotSupportedScheme <followed by a space character');
     $request->setHeaders($headers);
     $a = new Adapter\Http($this->_digestConfig);
     $a->setDigestResolver($this->_digestResolver)->setRequest($request)->setResponse($response);
     $result = $a->authenticate();
     $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_UNCATEGORIZED);
 }
예제 #4
0
파일: ProxyTest.php 프로젝트: nieldm/zf2
 /**
  * Acts like a client sending the given Authenticate header value.
  *
  * @param  string $clientHeader Authenticate header value
  * @param  string $scheme       Which authentication scheme to use
  * @return array Containing the result, the response headers, and the status
  */
 public function _doAuth($clientHeader, $scheme)
 {
     // Set up stub request and response objects
     $response = new Response();
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Proxy-Authorization', $clientHeader);
     $headers->addHeaderLine('User-Agent', 'PHPUnit');
     $request = new Request();
     $request->setUri('http://localhost/');
     $request->setMethod('GET');
     $request->setHeaders($headers);
     // Select an Authentication scheme
     switch ($scheme) {
         case 'basic':
             $use = $this->_basicConfig;
             break;
         case 'digest':
             $use = $this->_digestConfig;
             break;
         case 'both':
         default:
             $use = $this->_bothConfig;
     }
     // Create the HTTP Auth adapter
     $a = new \Zend\Authentication\Adapter\Http($use);
     $a->setBasicResolver($this->_basicResolver);
     $a->setDigestResolver($this->_digestResolver);
     // Send the authentication request
     $a->setRequest($request);
     $a->setResponse($response);
     $result = $a->authenticate();
     $return = array('result' => $result, 'status' => $response->getStatusCode(), 'headers' => $response->getHeaders());
     return $return;
 }
예제 #5
0
파일: ProxyTest.php 프로젝트: rexmac/zf2
 /**
  * Acts like a client sending the given Authenticate header value.
  *
  * @param  string $clientHeader Authenticate header value
  * @param  string $scheme       Which authentication scheme to use
  * @return array Containing the result, the response headers, and the status
  */
 public function _doAuth($clientHeader, $scheme)
 {
     // Set up stub request and response objects
     $request = $this->getMock('Zend\\Controller\\Request\\Http');
     $response = new HTTPResponse();
     $response->setHttpResponseCode(200);
     $response->headersSentThrowsException = false;
     // Set stub method return values
     $request->expects($this->any())->method('getRequestUri')->will($this->returnValue('/'));
     $request->expects($this->any())->method('getMethod')->will($this->returnValue('GET'));
     $request->expects($this->any())->method('getServer')->will($this->returnValue('PHPUnit'));
     $request->expects($this->any())->method('getHeader')->will($this->returnValue($clientHeader));
     // Select an Authentication scheme
     switch ($scheme) {
         case 'basic':
             $use = $this->_basicConfig;
             break;
         case 'digest':
             $use = $this->_digestConfig;
             break;
         case 'both':
         default:
             $use = $this->_bothConfig;
     }
     // Create the HTTP Auth adapter
     $a = new \Zend\Authentication\Adapter\Http($use);
     $a->setBasicResolver($this->_basicResolver);
     $a->setDigestResolver($this->_digestResolver);
     // Send the authentication request
     $a->setRequest($request);
     $a->setResponse($response);
     $result = $a->authenticate();
     $return = array('result' => $result, 'status' => $response->getHttpResponseCode(), 'headers' => $response->getHeaders());
     return $return;
 }
예제 #6
0
파일: ObjectTest.php 프로젝트: rexmac/zf2
 public function testUnsupportedScheme()
 {
     $response = $this->getMock('Zend\\Controller\\Response\\Http');
     $request = $this->getMock('Zend\\Controller\\Request\\Http');
     $request->expects($this->any())->method('getHeader')->will($this->returnValue('NotSupportedScheme <followed by a space caracter'));
     $a = new Adapter\Http($this->_digestConfig);
     $a->setDigestResolver($this->_digestResolver)->setRequest($request)->setResponse($response);
     $result = $a->authenticate();
     $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_UNCATEGORIZED);
 }
예제 #7
0
 protected function getAuthService()
 {
     $config = array('accept_schemes' => 'basic', 'realm' => 'ref-pays-admin');
     //        if (null == $this->authService){
     $httpAuthAdapter = new Http($config);
     $authService = new AuthenticationService();
     $basicResolver = new FileResolver();
     $basicResolver->setFile(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '\\public\\files\\basicPasswd.txt');
     $httpAuthAdapter->setBasicResolver($basicResolver);
     $httpAuthAdapter->setRequest($this->getRequest());
     $httpAuthAdapter->setResponse($this->getResponse());
     $result = $httpAuthAdapter->authenticate();
     if (!$result->isValid()) {
         die(var_dump($result->getMessages()));
     }
     die('654645');
     $authService->setAdapter($httpAuthAdapter);
     $this->authService = $authService;
     //        }
     return $this->authService;
 }