-
-
Notifications
You must be signed in to change notification settings - Fork 15
[WIP]Implement authenticateToken #10
base: master
Are you sure you want to change the base?
Changes from 7 commits
4516d05
e25b25c
db705a9
6861767
0ab002a
6a7c993
c370a79
764f2c0
d0f3960
5c763e2
abe0ec8
c62e3f6
56e918b
4b92f38
40383cc
29ac95b
79cb8f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,18 @@ | |
namespace phpBB\SessionsAuthBundle\Authentication; | ||
|
||
|
||
use Doctrine\ORM\EntityManager; | ||
use phpBB\SessionsAuthBundle\Authentication\Provider\phpBBUserProvider; | ||
use phpBB\SessionsAuthBundle\Tokens\phpBBToken; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; | ||
|
||
|
@@ -31,27 +35,61 @@ class phpBBSessionAuthenticator implements SimplePreAuthenticatorInterface, Auth | |
/** @var string */ | ||
private $loginpage; | ||
|
||
/** @var RequestStack */ | ||
private $requestStack; | ||
|
||
/** @var ContainerInterface */ | ||
private $container; | ||
|
||
/** @var string */ | ||
private $dbconnection; | ||
|
||
/** | ||
* @param $cookiename string | ||
* @param $boardurl string | ||
* @param $loginpage string | ||
* @param $requestStack RequestStack | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct($cookiename, $boardurl, $loginpage) | ||
public function __construct($cookiename, $boardurl, $loginpage, $dbconnection, RequestStack $requestStack, ContainerInterface $container) | ||
{ | ||
$this->cookiename = $cookiename; | ||
$this->boardurl = $boardurl; | ||
$this->loginpage = $loginpage; | ||
|
||
$this->cookiename = $cookiename; | ||
$this->boardurl = $boardurl; | ||
$this->loginpage = $loginpage; | ||
$this->dbconnection = $dbconnection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only just noticed this. All lowercase property names? |
||
$this->requestStack = $requestStack; | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param TokenInterface $token | ||
* @param UserProviderInterface $userProvider | ||
* @param $providerKey | ||
* @return AnonymousToken | ||
*/ | ||
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey) | ||
{ | ||
// TODO: Implement authenticateToken() method. | ||
if (!$userProvider instanceof phpBBUserProvider) | ||
{ | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'The user provider must be an instance of phpBBUserProvider (%s was given).', | ||
get_class($userProvider) | ||
) | ||
); | ||
} | ||
|
||
$session_id = $this->requestStack->getCurrentRequest()->cookies->get($this->cookiename . '_sid'); | ||
|
||
if (empty($session_id)) | ||
{ | ||
return null; // We can't authenticate if no SID is available. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't support SID in url? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Nicofuma We might support it, however is there a chance that there is actually a SID in the URL in a symfony page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's right, so forgot what I said ^ |
||
} | ||
|
||
/** @var EntityManager $em */ | ||
$em = $this->container->get('doctrine')->getManager($this->dbconnection); | ||
|
||
$session = $em->getRepository('phpbbSessionsAuthBundle:Session')->findById($session_id); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* | ||
* @package phpBBSessionsAuthBundle | ||
* @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
* @license MIT | ||
* | ||
*/ | ||
namespace phpBB\SessionsAuthBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Security\Core\Role\Role; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* Class Session | ||
* @package phpbb\SessionsAuthBundle\Entity | ||
* @ORM\Entity(readOnly=true) | ||
*/ | ||
class Session | ||
{ | ||
/** | ||
* @var string | ||
* @ORM\Column(type="string", name="session_id") | ||
* @ORM\Id | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var User | ||
* @ORM\ManyToOne(targetEntity="User", inversedBy="sessions") | ||
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id") | ||
*/ | ||
private $user; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return User | ||
*/ | ||
public function getUser() | ||
{ | ||
return $this->user; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
*/ | ||
public function setUser($user) | ||
{ | ||
$this->user = $user; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of random empty lines? |
||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's be picky and have these alphabetical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure: