Ejemplo n.º 1
0
 public function testIsValid()
 {
     $TestVar = new Base();
     $this->assertTrue(Base::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new RESTProcessorA_underTest_isValid();
     $this->assertTrue(RESTProcessorA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(RESTProcessorA::isValid($TestVar));
     $this->assertTrue(ProcessorA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new ProcessorA_underTest_isValid();
     $this->assertTrue(ProcessorA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(ProcessorA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new RESTController();
     $this->assertTrue(RESTController::isValid($TestVar));
     $this->assertTrue(FrontControllerA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new FrontControllerA_underTest_isValid();
     $this->assertTrue(FrontControllerA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(FrontControllerA::isValid($TestVar));
     $this->assertTrue(Object::isValid($TestVar));
     $TestVar = new ModelA_underTest_isValid();
     $this->assertTrue(ModelA_underTest_isValid::isValid($TestVar));
     $this->assertTrue(ModelA::isValid($TestVar));
 }
Ejemplo n.º 2
0
 /**
  * @param HttpRequestA $oRequest
  * @param RESTProcessorA $oProcessor
  * @returns HttpResponseA
  * @throws \vsc\presentation\responses\ExceptionResponse
  * @throws \vsc\presentation\responses\ExceptionResponseError
  * @throws \vsc\presentation\views\ExceptionView
  * @throws ExceptionResponseError
  */
 public function getResponse(HttpRequestA $oRequest, $oProcessor = null)
 {
     $oModel = null;
     try {
         if (!$oRequest->isGet()) {
             if ($oRequest->hasContentType() && !RESTRequest::validContentType($oRequest->getContentType())) {
                 throw new ExceptionResponseError('Invalid request content type', HttpResponseType::UNSUPPORTED_MEDIA_TYPE);
             }
         }
         if (!ProcessorA::isValid($oProcessor)) {
             throw new ExceptionController('Invalid request processor');
         }
         /* @var RESTProcessorA $oProcessor */
         if (RESTProcessorA::isValid($oProcessor) && !$oProcessor->validRequestMethod($oRequest->getHttpMethod())) {
             throw new ExceptionResponseError('Invalid request method', HttpResponseType::METHOD_NOT_ALLOWED);
         }
         $oMap = $oProcessor->getMap();
         if ($oMap->requiresAuthentication()) {
             try {
                 if ($oProcessor instanceof AuthenticatedProcessorI) {
                     /* @var AuthenticatedProcessorI $oProcessor */
                     if (!$oRequest->hasAuthenticationData()) {
                         throw new ExceptionAuthenticationNeeded('This resource needs authentication');
                     }
                     // here we check that the request contains the same authentication type as the map
                     if (($oRequest->getAuthentication()->getType() & $oMap->getAuthenticationType()) !== $oMap->getAuthenticationType()) {
                         throw new ExceptionAuthenticationNeeded('Invalid authorization scheme. Supported schemes: ' . implode(', ', $oMap->getValidAuthenticationSchemas()));
                     }
                     if (!$oProcessor->handleAuthentication($oRequest->getAuthentication())) {
                         throw new ExceptionAuthenticationNeeded('Invalid authentication data', 'testrealm');
                     }
                 } else {
                     throw new ExceptionAuthenticationNeeded('This resource requires authentication but doesn\'t support any authorization scheme');
                 }
             } catch (ExceptionAuthenticationNeeded $e) {
                 return $this->getErrorResponse($e, $oRequest);
             }
         }
     } catch (\Exception $e) {
         return $this->getErrorResponse($e, $oRequest);
     }
     return parent::getResponse($oRequest, $oProcessor);
 }