aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php')
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 1c56fa9f..a79e6ebe 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -6,6 +6,8 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; 6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
7use Graby\SiteConfig\ConfigBuilder; 7use Graby\SiteConfig\ConfigBuilder;
8use Psr\Log\LoggerInterface; 8use Psr\Log\LoggerInterface;
9use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
10use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9 11
10class GrabySiteConfigBuilder implements SiteConfigBuilder 12class GrabySiteConfigBuilder implements SiteConfigBuilder
11{ 13{
@@ -13,27 +15,39 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
13 * @var ConfigBuilder 15 * @var ConfigBuilder
14 */ 16 */
15 private $grabyConfigBuilder; 17 private $grabyConfigBuilder;
18
16 /** 19 /**
17 * @var array 20 * @var SiteCredentialRepository
18 */ 21 */
19 private $credentials; 22 private $credentialRepository;
23
20 /** 24 /**
21 * @var LoggerInterface 25 * @var LoggerInterface
22 */ 26 */
23 private $logger; 27 private $logger;
24 28
25 /** 29 /**
30 * @var Wallabag\UserBundle\Entity\User|null
31 */
32 private $currentUser;
33
34 /**
26 * GrabySiteConfigBuilder constructor. 35 * GrabySiteConfigBuilder constructor.
27 * 36 *
28 * @param ConfigBuilder $grabyConfigBuilder 37 * @param ConfigBuilder $grabyConfigBuilder
29 * @param array $credentials 38 * @param TokenStorage $token
30 * @param LoggerInterface $logger 39 * @param SiteCredentialRepository $credentialRepository
40 * @param LoggerInterface $logger
31 */ 41 */
32 public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger) 42 public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
33 { 43 {
34 $this->grabyConfigBuilder = $grabyConfigBuilder; 44 $this->grabyConfigBuilder = $grabyConfigBuilder;
35 $this->credentials = $credentials; 45 $this->credentialRepository = $credentialRepository;
36 $this->logger = $logger; 46 $this->logger = $logger;
47
48 if ($token->getToken()) {
49 $this->currentUser = $token->getToken()->getUser();
50 }
37 } 51 }
38 52
39 /** 53 /**
@@ -47,7 +61,12 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
47 $host = substr($host, 4); 61 $host = substr($host, 4);
48 } 62 }
49 63
50 if (empty($this->credentials[$host])) { 64 $credentials = null;
65 if ($this->currentUser) {
66 $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
67 }
68
69 if (null === $credentials) {
51 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); 70 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
52 71
53 return false; 72 return false;
@@ -62,13 +81,14 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
62 'passwordField' => $config->login_password_field ?: null, 81 'passwordField' => $config->login_password_field ?: null,
63 'extraFields' => $this->processExtraFields($config->login_extra_fields), 82 'extraFields' => $this->processExtraFields($config->login_extra_fields),
64 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, 83 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
65 'username' => $this->credentials[$host]['username'], 84 'username' => $credentials['username'],
66 'password' => $this->credentials[$host]['password'], 85 'password' => $credentials['password'],
67 ]; 86 ];
68 87
69 $config = new SiteConfig($parameters); 88 $config = new SiteConfig($parameters);
70 89
71 // do not leak password in log 90 // do not leak usernames and passwords in log
91 $parameters['username'] = '**masked**';
72 $parameters['password'] = '**masked**'; 92 $parameters['password'] = '**masked**';
73 93
74 $this->logger->debug('Auth: add parameters.', ['host' => $host, 'parameters' => $parameters]); 94 $this->logger->debug('Auth: add parameters.', ['host' => $host, 'parameters' => $parameters]);