diff --git a/Entity/Tenant.php b/Entity/Tenant.php index 9ab89e6..59ad3e7 100644 --- a/Entity/Tenant.php +++ b/Entity/Tenant.php @@ -111,6 +111,16 @@ class Tenant implements UserInterface */ private $updatedAt; + /** + * @ORM\Column(name="is_white_listed", type="boolean", options={"default":0}) + */ + private $isWhiteListed = false; + + /** + * @ORM\Column(name="white_listed_until", type="datetime", nullable=true) + */ + private $whiteListedUntil; + /** * @ORM\PrePersist */ @@ -419,4 +429,47 @@ public function setUsername($name) public function eraseCredentials() { } + + /** + * @return boolean + */ + public function getIsWhiteListed() + { + return $this->isWhiteListed; + } + + /** + * @param boolean $isWhiteListed + */ + public function setIsWhiteListed($isWhiteListed) + { + $this->isWhiteListed = $isWhiteListed; + return $this; + } + + /** + * @return null|\DateTime + */ + public function getWhiteListedUntil() + { + return $this->whiteListedUntil; + } + + /** + * @param \DateTime $whiteListedUntil + */ + public function setWhiteListedUntil($whiteListedUntil) + { + $this->whiteListedUntil = $whiteListedUntil; + return $this; + } + + /** + * @return boolean + */ + public function isWhiteListed() + { + $now = new \DateTime(); + return $this->getIsWhiteListed() && (is_null($this->getWhiteListedUntil()) || ($now < $this->getWhiteListedUntil())); + } } diff --git a/Listener/LicenseListener.php b/Listener/LicenseListener.php index 70d9fd7..e2c3345 100644 --- a/Listener/LicenseListener.php +++ b/Listener/LicenseListener.php @@ -2,6 +2,7 @@ namespace AtlassianConnectBundle\Listener; +use AtlassianConnectBundle\Entity\Tenant; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelInterface; @@ -57,8 +58,12 @@ public function onKernelRequest(GetResponseEvent $event) // Checking for whitelisted users try { $user = $this->tokenStorage->getToken()->getUser(); - $today = date('Y-m-d'); - if ($user instanceof UserInterface) { + if ($user instanceof Tenant) { + if($user->isWhiteListed()){ + return; + } + + $today = date('Y-m-d'); $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist'); foreach ($whitelist as $allowed) { if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) { @@ -66,7 +71,6 @@ public function onKernelRequest(GetResponseEvent $event) return; } } - } } catch (\Exception $e) { // Do nothing @@ -77,4 +81,4 @@ public function onKernelRequest(GetResponseEvent $event) $event->setResponse($response); } } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 857021f..1580008 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,8 @@ In your **protected** controller action you can make a signed request to JIRA in $request = new JWTRequest($this->getUser()); $json = $request->get('/rest/api/2/issue/KEY-XXX'); + +### White listening licences + +You could white-list any lisence by editing related row in table tenant and setting field is_white_listed to 1. +If you will also set white_listed_until - you will be able to set white-list expiration