예제 #1
0
 /**
  * 
  *
  * @return MHTTPRequest
  */
 public static function request()
 {
     if (!MHTTPRequest::$request) {
         if (isRunningInSimulatedRequestMode()) {
             MHTTPRequest::$request = new MHTTPRequest(simulatedRequestFileName(), simulatedRequestName());
         } else {
             MHTTPRequest::$request = new MHTTPRequest();
         }
     }
     return MHTTPRequest::$request;
 }
예제 #2
0
 /**
  * 
  *
  * @return MView
  */
 public function view()
 {
     if ($this->applicationController()) {
         if ($this->applicationController()->acceptsMethod(S(MHTTPRequest()->method()))) {
             if (MHTTPRequest()->contentType()) {
                 $contentTypes = MHTTPRequest()->contentType()->componentsSeparatedByString(S(";"));
                 foreach ($contentTypes->toArray() as $contentType) {
                     $type = $contentType->stringByTrimmingEmptySpaces();
                     if ($this->applicationController()->acceptedMethodForMethod(S(MHTTPRequest()->method()))->contentTypes()->count() > 0) {
                         if (!$this->applicationController()->acceptedMethodForMethod(S(MHTTPRequest()->method()))->contentTypes()->containsObject($type)) {
                             throw new MBadRequestException(Sf("The specified content-type (%s) is not supported", $type));
                         }
                     }
                 }
             }
             if ($this->isRestricted()) {
                 if (!$this->authenticatedUserName) {
                     $authenticateHeader = Sf('Digest realm="%s", qop="auth", nonce="%s", opaque="%s"', $this->realm(), uniqid(), md5($this->realm()));
                     if (empty(MHTTPRequest::request()->server()['PHP_AUTH_DIGEST'])) {
                         $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                         $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                         return $this->accessDeniedView();
                     } else {
                         $data = $this->_parseDigest(MHTTPRequest::request()->server()['PHP_AUTH_DIGEST']);
                         $username = $data->objectForKey(S("username"));
                         if ($username) {
                             $password = $this->passwordForUserWithName($username);
                             if ($password) {
                                 $A1 = S(md5(Sf("%s:%s:%s", $data->objectForKey(S("username")), $this->realm(), $password)));
                                 $A2 = S(md5(Sf("%s:%s", MHTTPRequest::request()->server()['REQUEST_METHOD'], $data->objectForKey(S("uri")))));
                                 $validResponse = S(md5(Sf("%s:%s:%s:%s:%s:%s", $A1, $data->objectForKey("nonce"), $data->objectForKey("nc"), $data->objectForKey("cnonce"), $data->objectForKey("qop"), $A2)));
                                 if ($data->objectForKey("response")->equals($validResponse)) {
                                     $this->authenticatedUserName = $username;
                                     return $this->_view();
                                 } else {
                                     $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                                     $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                                     return $this->invalidCredentialsView();
                                 }
                             } else {
                                 $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                                 $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                                 return $this->invalidCredentialsView();
                             }
                         } else {
                             $this->setResponseCode(MHTTPResponse::RESPONSE_UNAUTHORIZED);
                             $this->addResponseHeader(S("WWW-Authenticate"), $authenticateHeader);
                             return $this->invalidCredentialsView();
                         }
                     }
                 } else {
                     return $this->_view();
                 }
             } else {
                 return $this->_view();
             }
         } else {
             throw new MBadRequestException(Sf("The specified request method (%s) is not supported", MHTTPRequest()->method()));
         }
     } else {
         return $this->_view();
     }
 }
예제 #3
0
/**
 * Returns the MHTTPRequest which contains all information about the current HTTP request
 *
 * This function returns the current MHTTPRequest object being processed by your
 * application
 *
 * @see MHTTPRequest
 *
 * @return MHTTPRequest The current MHTTPRequest object
 */
function MHTTPRequest()
{
    return MHTTPRequest::request();
}