aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-07 10:29:47 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-07 17:12:19 +0200
commitde9b5b5f4c8100615f2a4a35c4d4e62b0ca89c27 (patch)
tree2252f6b0356fcf9b703333fa8e07bf01206990d2
parentb283ee0d6d98b28623805ae00c669c1cdf638b91 (diff)
downloadwallabag-de9b5b5f4c8100615f2a4a35c4d4e62b0ca89c27.tar.gz
wallabag-de9b5b5f4c8100615f2a4a35c4d4e62b0ca89c27.tar.zst
wallabag-de9b5b5f4c8100615f2a4a35c4d4e62b0ca89c27.zip
Changed authentication order in GrabySiteConfigBuilder
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php25
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;
8use Psr\Log\LoggerInterface; 8use Psr\Log\LoggerInterface;
9use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; 9use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
10use Wallabag\CoreBundle\Repository\SiteCredentialRepository; 10use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
11use Wallabag\UserBundle\Entity\User;
12 11
13class GrabySiteConfigBuilder implements SiteConfigBuilder 12class 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}