Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User white lists #4

Merged
merged 4 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I like the idea of being able to manipulate this from the DB!

Could you please cleanup the old logic of checking the params, as well as remove the relevant entries from parameters.yml.dist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, current implementation allow to use "both ways" - database and parameters.yml
Leaving code for processing parameters.yml will give full backward compatibility.
So, basically, you could simply update lib and not required to change parameters.yml
Maybe lets leave that code for BC?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

Thanks! 👍

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