diff options
-rw-r--r-- | src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index b0be2176..6ee2986a 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |||
@@ -8,7 +8,6 @@ use Graby\SiteConfig\ConfigBuilder; | |||
8 | use Psr\Log\LoggerInterface; | 8 | use Psr\Log\LoggerInterface; |
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | 9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
10 | use Wallabag\CoreBundle\Repository\SiteCredentialRepository; | 10 | use Wallabag\CoreBundle\Repository\SiteCredentialRepository; |
11 | use Wallabag\UserBundle\Entity\User; | ||
12 | 11 | ||
13 | class GrabySiteConfigBuilder implements SiteConfigBuilder | 12 | class GrabySiteConfigBuilder implements SiteConfigBuilder |
14 | { | 13 | { |
@@ -28,9 +27,9 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
28 | private $logger; | 27 | private $logger; |
29 | 28 | ||
30 | /** | 29 | /** |
31 | * @var User|null | 30 | * @var TokenStorage |
32 | */ | 31 | */ |
33 | private $currentUser; | 32 | private $token; |
34 | 33 | ||
35 | /** | 34 | /** |
36 | * GrabySiteConfigBuilder constructor. | 35 | * GrabySiteConfigBuilder constructor. |
@@ -40,10 +39,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
40 | $this->grabyConfigBuilder = $grabyConfigBuilder; | 39 | $this->grabyConfigBuilder = $grabyConfigBuilder; |
41 | $this->credentialRepository = $credentialRepository; | 40 | $this->credentialRepository = $credentialRepository; |
42 | $this->logger = $logger; | 41 | $this->logger = $logger; |
43 | 42 | $this->token = $token; | |
44 | if ($token->getToken()) { | ||
45 | $this->currentUser = $token->getToken()->getUser(); | ||
46 | } | ||
47 | } | 43 | } |
48 | 44 | ||
49 | /** | 45 | /** |
@@ -51,13 +47,15 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
51 | */ | 47 | */ |
52 | public function buildForHost($host) | 48 | public function buildForHost($host) |
53 | { | 49 | { |
50 | $user = $this->getUser(); | ||
51 | |||
54 | // required by credentials below | 52 | // required by credentials below |
55 | $host = strtolower($host); | 53 | $host = strtolower($host); |
56 | if ('www.' === substr($host, 0, 4)) { | 54 | if ('www.' === substr($host, 0, 4)) { |
57 | $host = substr($host, 4); | 55 | $host = substr($host, 4); |
58 | } | 56 | } |
59 | 57 | ||
60 | if (!$this->currentUser) { | 58 | if (!$user) { |
61 | $this->logger->debug('Auth: no current user defined.'); | 59 | $this->logger->debug('Auth: no current user defined.'); |
62 | 60 | ||
63 | return false; | 61 | return false; |
@@ -73,7 +71,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
73 | $hosts[] = '.' . implode('.', $split); | 71 | $hosts[] = '.' . implode('.', $split); |
74 | } | 72 | } |
75 | 73 | ||
76 | $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); | 74 | $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $user->getId()); |
77 | 75 | ||
78 | if (null === $credentials) { | 76 | if (null === $credentials) { |
79 | $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); | 77 | $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); |
@@ -131,4 +129,13 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
131 | 129 | ||
132 | return $extraFields; | 130 | return $extraFields; |
133 | } | 131 | } |
132 | |||
133 | private function getUser() | ||
134 | { | ||
135 | if ($this->token->getToken() && null !== $this->token->getToken()->getUser()) { | ||
136 | return $this->token->getToken()->getUser(); | ||
137 | } | ||
138 | |||
139 | return null; | ||
140 | } | ||
134 | } | 141 | } |