Esempio n. 1
0
 /**
  * "associate" mode request
  *
  * @param HttpUrl                          $server  to make association with (usually obtained from OpenIdCredentials)
  * @param OpenIdConsumerAssociationManager $manager - dao-like association manager
  *
  * @return OpenIdConsumerAssociation
  * @throws OpenIdException
  **/
 public function associate(HttpUrl $server, OpenIdConsumerAssociationManager $manager)
 {
     Assert::isTrue($server->isValid());
     if ($association = $manager->findByServer($server)) {
         return $association;
     }
     $dhParameters = new DiffieHellmanParameters($this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_G), $this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_P));
     $keyPair = DiffieHellmanKeyPair::generate($dhParameters, $this->randomSource);
     $request = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl($server)->setPostVar('openid.ns', self::NAMESPACE_2_0)->setPostVar('openid.mode', 'associate')->setPostVar('openid.assoc_type', self::ASSOCIATION_TYPE)->setPostVar('openid.session_type', 'DH-SHA1')->setPostVar('openid.dh_modulus', base64_encode($dhParameters->getModulus()->toBinary()))->setPostVar('openid.dh_gen', base64_encode($dhParameters->getGen()->toBinary()))->setPostVar('openid.dh_consumer_public', base64_encode($keyPair->getPublic()->toBinary()));
     $response = $this->httpClient->setFollowLocation(true)->send($request);
     if ($response->getStatus()->getId() != HttpStatus::CODE_200) {
         throw new OpenIdException('bad response code from server');
     }
     $result = $this->parseKeyValueFormat($response->getBody());
     if (empty($result['assoc_handle'])) {
         throw new OpenIdException('can\\t live without handle');
     }
     if (!isset($result['assoc_type']) || $result['assoc_type'] !== self::ASSOCIATION_TYPE) {
         throw new OpenIdException('bad association type');
     }
     if (!isset($result['expires_in']) || !is_numeric($result['expires_in'])) {
         throw new OpenIdException('bad expires');
     }
     if (isset($result['session_type']) && $result['session_type'] == 'DH-SHA1' && isset($result['dh_server_public'])) {
         $secret = sha1($keyPair->makeSharedKey($this->numberFactory->makeFromBinary(base64_decode($result['dh_server_public'])))->toBinary(), true) ^ base64_decode($result['enc_mac_key']);
     } elseif (empty($result['session_type']) && isset($result['mac_key'])) {
         $secret = base64_decode($result['mac_key']);
     } else {
         throw new OpenIdException('no secret in answer');
     }
     return $manager->makeAndSave($result['assoc_handle'], $result['assoc_type'], $secret, Timestamp::makeNow()->modify('+ ' . $result['expires_in'] . ' seconds'), $server);
 }
Esempio n. 2
0
 /**
  * @param Model $model
  * @return $this
  */
 public function render(Model $model = null)
 {
     $csv = $this->toString($model);
     /** @var Model $model */
     if ($this->download) {
         if (is_string($this->download)) {
             $filename = $this->download;
         } else {
             $filename = 'csv_' . Timestamp::makeNow()->toFormatString('Y.m.d_H.i.s') . '.csv';
         }
         header('Content-Type: application/octet-stream; charset=' . $this->encoding);
         header('Content-Length: ' . strlen($csv));
         header('Content-Disposition: attachment;filename="' . $filename . '"');
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
     } else {
         header('Content-Type: text/plain; charset=' . ($this->encoding ?: 'utf-8'));
     }
     echo $csv;
     return $this;
 }
Esempio n. 3
0
 public function __construct(Timestamp $timestamp = null)
 {
     $this->timestamp = $timestamp ?: Timestamp::makeNow();
 }
Esempio n. 4
0
 public function __construct()
 {
     $this->date = Timestamp::makeNow();
 }
Esempio n. 5
0
 public function __clone()
 {
     $vars = get_object_vars($this);
     foreach ($vars as $key => $val) {
         if (is_object($val)) {
             $this->{$key} = clone $val;
         }
     }
     $this->createDate = Timestamp::makeNow();
     $this->cloned = true;
     $this->clonedFrom = $this->id ? $this->id : $this->clonedFrom;
     $this->setId(null);
     $this->removed = false;
 }