コード例 #1
0
 public function __construct(Profile $owner, Profile $reader = null)
 {
     $this->owner = $owner;
     $this->reader = $reader;
     // TRANS: Message when a private stream attemps to be read by unauthorized third party.
     $msg = sprintf(_m('This stream is protected and only authorized subscribers may see its contents.'));
     // If $reader is a profile, authentication has been made but still not accepted (403),
     // otherwise authentication may give access to this resource (401).
     parent::__construct($msg, $reader instanceof Profile ? 403 : 401);
 }
コード例 #2
0
 /**
  * the date when this Authorization stops being effective.
  * 
  * @param object DateAndTime $effectiveDate
  * 
  * @throws object AuthorizationException An exception with
  *		   one of the following messages defined in
  *		   org.osid.authorization.AuthorizationException may be thrown:
  *		   {@link
  *		   org.osid.authorization.AuthorizationException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.authorization.AuthorizationException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.authorization.AuthorizationException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.authorization.AuthorizationException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.authorization.AuthorizationException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.authorization.AuthorizationException#EFFECTIVE_PRECEDE_EXPIRATION}
  * 
  * @access public
  */
 function updateEffectiveDate($effectiveDate)
 {
     if (!$this->isExplicit()) {
         // "Cannot modify an implicit Authorization."
         throwError(new Error(AuthorizationException::OPERATION_FAILED(), "Authorization", true));
     }
     // ** parameter validation
     ArgumentValidator::validate($effectiveDate, HasMethodsValidatorRule::getRule("asDateAndTime"), true);
     // ** end of parameter validation
     // make sure effective date is before expiration date
     if ($effectiveDate->isGreaterThan($this->_expirationDate)) {
         throwError(new Error(AuthorizationException::EFFECTIVE_PRECEDE_EXPIRATION(), "Authorization", true));
     }
     if ($this->_effectiveDate->isEqualTo($effectiveDate)) {
         return;
     }
     // nothing to update
     // update the object
     $this->_effectiveDate = $effectiveDate;
     // update the database
     $dbHandler = Services::getService("DatabaseManager");
     $query = new UpdateQuery();
     $query->setTable("az2_explicit_az");
     $query->addWhereEqual("id", $this->_id);
     $timestamp = $dbHandler->toDBDate($effectiveDate, $this->_cache->_dbIndex);
     $query->addValue("effective_date", $timestamp);
     $queryResult = $dbHandler->query($query, $this->_cache->_dbIndex);
     if ($queryResult->getNumberOfRows() == 0) {
         throwError(new Error(AuthorizationException::OPERATION_FAILED(), "Authorization", true));
     }
     if ($queryResult->getNumberOfRows() > 1) {
         throwError(new Error(AuthorizationException::OPERATION_FAILED(), "Authorization", true));
     }
 }
コード例 #3
0
 /**
  * @param Exception $parent
  */
 public function __construct(Exception $parent)
 {
     parent::__construct($parent->getMessage(), $parent->getCode(), $parent);
 }
コード例 #4
0
 public function testConstructor()
 {
     $authorizationException = new AuthorizationException(AuthorizationException::NOT_AUTHORIZED, ['consumer_id' => 1, 'resources' => 'record2']);
     $this->assertSame('Consumer is not authorized to access record2', $authorizationException->getMessage());
 }