Skip to content

Commit

Permalink
Merge pull request #4 from zhil/user_white_lists
Browse files Browse the repository at this point in the history
User white lists
  • Loading branch information
thecatontheflat committed Apr 18, 2016
2 parents 658dcb7 + 96756fa commit 625d80d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
53 changes: 53 additions & 0 deletions Entity/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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()));
}
}
12 changes: 8 additions & 4 deletions Listener/LicenseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,16 +58,19 @@ 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']) {

return;
}
}

}
} catch (\Exception $e) {
// Do nothing
Expand All @@ -77,4 +81,4 @@ public function onKernelRequest(GetResponseEvent $event)
$event->setResponse($response);
}
}
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 625d80d

Please sign in to comment.