X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FGuzzleSiteAuthenticator%2FGrabySiteConfigBuilder.php;h=10689c62bbf82e631dda0da5f708b23dccc163f2;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=15aa0317cc7fe8ff93378633eeb02403f3dea72f;hpb=5fe65baee5910c887ba148b1163a1a53654dc324;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 15aa0317..10689c62 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -5,8 +5,9 @@ namespace Wallabag\CoreBundle\GuzzleSiteAuthenticator; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; use Graby\SiteConfig\ConfigBuilder; -use OutOfRangeException; use Psr\Log\LoggerInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Wallabag\CoreBundle\Repository\SiteCredentialRepository; class GrabySiteConfigBuilder implements SiteConfigBuilder { @@ -14,27 +15,39 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder * @var ConfigBuilder */ private $grabyConfigBuilder; + /** - * @var array + * @var SiteCredentialRepository */ - private $credentials; + private $credentialRepository; + /** * @var LoggerInterface */ private $logger; + /** + * @var Wallabag\UserBundle\Entity\User|null + */ + private $currentUser; + /** * GrabySiteConfigBuilder constructor. * - * @param ConfigBuilder $grabyConfigBuilder - * @param array $credentials - * @param LoggerInterface $logger + * @param ConfigBuilder $grabyConfigBuilder + * @param TokenStorage $token + * @param SiteCredentialRepository $credentialRepository + * @param LoggerInterface $logger */ - public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger) + public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger) { $this->grabyConfigBuilder = $grabyConfigBuilder; - $this->credentials = $credentials; + $this->credentialRepository = $credentialRepository; $this->logger = $logger; + + if ($token->getToken()) { + $this->currentUser = $token->getToken()->getUser(); + } } /** @@ -44,11 +57,16 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder { // required by credentials below $host = strtolower($host); - if (substr($host, 0, 4) == 'www.') { + if (substr($host, 0, 4) === 'www.') { $host = substr($host, 4); } - if (empty($this->credentials[$host])) { + $credentials = null; + if ($this->currentUser) { + $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); + } + + if (null === $credentials) { $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); return false; @@ -63,13 +81,14 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder 'passwordField' => $config->login_password_field ?: null, 'extraFields' => $this->processExtraFields($config->login_extra_fields), 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, - 'username' => $this->credentials[$host]['username'], - 'password' => $this->credentials[$host]['password'], + 'username' => $credentials['username'], + 'password' => $credentials['password'], ]; $config = new SiteConfig($parameters); - // do not leak password in log + // do not leak usernames and passwords in log + $parameters['username'] = '**masked**'; $parameters['password'] = '**masked**'; $this->logger->debug('Auth: add parameters.', ['host' => $host, 'parameters' => $parameters]);