[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Lcobucci\JWT\Validation\Constraint; 4 5 use DateInterval; 6 use DateTimeInterface; 7 use Lcobucci\Clock\Clock; 8 use Lcobucci\JWT\Token; 9 use Lcobucci\JWT\Validation\Constraint; 10 use Lcobucci\JWT\Validation\ConstraintViolation; 11 12 final class ValidAt implements Constraint 13 { 14 /** @var Clock */ 15 private $clock; 16 17 /** @var DateInterval */ 18 private $leeway; 19 20 public function __construct(Clock $clock, DateInterval $leeway = null) 21 { 22 $this->clock = $clock; 23 $this->leeway = $this->guardLeeway($leeway); 24 } 25 26 /** @return DateInterval */ 27 private function guardLeeway(DateInterval $leeway = null) 28 { 29 if ($leeway === null) { 30 return new DateInterval('PT0S'); 31 } 32 33 if ($leeway->invert === 1) { 34 throw LeewayCannotBeNegative::create(); 35 } 36 37 return $leeway; 38 } 39 40 public function assert(Token $token) 41 { 42 $now = $this->clock->now(); 43 44 $this->assertIssueTime($token, $now->add($this->leeway)); 45 $this->assertMinimumTime($token, $now->add($this->leeway)); 46 $this->assertExpiration($token, $now->sub($this->leeway)); 47 } 48 49 /** @throws ConstraintViolation */ 50 private function assertExpiration(Token $token, DateTimeInterface $now) 51 { 52 if ($token->isExpired($now)) { 53 throw new ConstraintViolation('The token is expired'); 54 } 55 } 56 57 /** @throws ConstraintViolation */ 58 private function assertMinimumTime(Token $token, DateTimeInterface $now) 59 { 60 if (! $token->isMinimumTimeBefore($now)) { 61 throw new ConstraintViolation('The token cannot be used yet'); 62 } 63 } 64 65 /** @throws ConstraintViolation */ 66 private function assertIssueTime(Token $token, DateTimeInterface $now) 67 { 68 if (! $token->hasBeenIssuedBefore($now)) { 69 throw new ConstraintViolation('The token was issued in the future'); 70 } 71 } 72 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |