aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-09 22:25:18 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-05-09 22:53:42 +0200
commit94b232bbb8de4699911a6446a1a96f75370cab50 (patch)
tree9f6b43ca6613e800e1cf1262bb1a79139cda8d67 /src/Wallabag
parent0eb8220204953b874ebd2dbd0362973f3f45074c (diff)
downloadwallabag-94b232bbb8de4699911a6446a1a96f75370cab50.tar.gz
wallabag-94b232bbb8de4699911a6446a1a96f75370cab50.tar.zst
wallabag-94b232bbb8de4699911a6446a1a96f75370cab50.zip
Skip auth when no credentials are found
If we can’t find a credential for the current host, even if it required login, we won’t add them and website will be fetched without any login.
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php36
-rw-r--r--src/Wallabag/CoreBundle/Helper/HttpClientFactory.php1
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml3
3 files changed, 31 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 1c866f17..a16ed49d 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -6,28 +6,35 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; 6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
7use Graby\SiteConfig\ConfigBuilder; 7use Graby\SiteConfig\ConfigBuilder;
8use OutOfRangeException; 8use OutOfRangeException;
9use Psr\Log\LoggerInterface;
9 10
10class GrabySiteConfigBuilder implements SiteConfigBuilder 11class GrabySiteConfigBuilder implements SiteConfigBuilder
11{ 12{
12 /** 13 /**
13 * @var \Graby\SiteConfig\ConfigBuilder 14 * @var ConfigBuilder
14 */ 15 */
15 private $grabyConfigBuilder; 16 private $grabyConfigBuilder;
16 /** 17 /**
17 * @var array 18 * @var array
18 */ 19 */
19 private $credentials; 20 private $credentials;
21 /**
22 * @var LoggerInterface
23 */
24 private $logger;
20 25
21 /** 26 /**
22 * GrabySiteConfigBuilder constructor. 27 * GrabySiteConfigBuilder constructor.
23 * 28 *
24 * @param \Graby\SiteConfig\ConfigBuilder $grabyConfigBuilder 29 * @param ConfigBuilder $grabyConfigBuilder
25 * @param array $credentials 30 * @param array $credentials
31 * @param LoggerInterface $logger
26 */ 32 */
27 public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials = []) 33 public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger)
28 { 34 {
29 $this->grabyConfigBuilder = $grabyConfigBuilder; 35 $this->grabyConfigBuilder = $grabyConfigBuilder;
30 $this->credentials = $credentials; 36 $this->credentials = $credentials;
37 $this->logger = $logger;
31 } 38 }
32 39
33 /** 40 /**
@@ -47,6 +54,12 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
47 $host = substr($host, 4); 54 $host = substr($host, 4);
48 } 55 }
49 56
57 if (!isset($this->credentials[$host])) {
58 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
59
60 return false;
61 }
62
50 $config = $this->grabyConfigBuilder->buildForHost($host); 63 $config = $this->grabyConfigBuilder->buildForHost($host);
51 $parameters = [ 64 $parameters = [
52 'host' => $host, 65 'host' => $host,
@@ -56,14 +69,18 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
56 'passwordField' => $config->login_password_field ?: null, 69 'passwordField' => $config->login_password_field ?: null,
57 'extraFields' => $this->processExtraFields($config->login_extra_fields), 70 'extraFields' => $this->processExtraFields($config->login_extra_fields),
58 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, 71 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
72 'username' => $this->credentials[$host]['username'],
73 'password' => $this->credentials[$host]['password'],
59 ]; 74 ];
60 75
61 if (isset($this->credentials[$host])) { 76 $config = new SiteConfig($parameters);
62 $parameters['username'] = $this->credentials[$host]['username']; 77
63 $parameters['password'] = $this->credentials[$host]['password']; 78 // do not leak password in log
64 } 79 $parameters['password'] = '**masked**';
65 80
66 return new SiteConfig($parameters); 81 $this->logger->debug('Auth: add parameters.', ['host' => $host, 'parameters' => $parameters]);
82
83 return $config;
67 } 84 }
68 85
69 /** 86 /**
@@ -85,6 +102,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
85 if (strpos($extraField, '=') === false) { 102 if (strpos($extraField, '=') === false) {
86 continue; 103 continue;
87 } 104 }
105
88 list($fieldName, $fieldValue) = explode('=', $extraField, 2); 106 list($fieldName, $fieldValue) = explode('=', $extraField, 2);
89 $extraFields[$fieldName] = $fieldValue; 107 $extraFields[$fieldName] = $fieldValue;
90 } 108 }
diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
index 11ef26d8..43f5b119 100644
--- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
+++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
@@ -51,6 +51,7 @@ class HttpClientFactory
51 $this->cookieJar->clear(); 51 $this->cookieJar->clear();
52 // need to set the (shared) cookie jar 52 // need to set the (shared) cookie jar
53 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]); 53 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]);
54
54 foreach ($this->subscribers as $subscriber) { 55 foreach ($this->subscribers as $subscriber) {
55 $client->getEmitter()->attach($subscriber); 56 $client->getEmitter()->attach($subscriber);
56 } 57 }
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 68f900a1..6c9195ce 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -63,6 +63,9 @@ services:
63 arguments: 63 arguments:
64 - "@wallabag_core.graby.config_builder" 64 - "@wallabag_core.graby.config_builder"
65 - "%sites_credentials%" 65 - "%sites_credentials%"
66 - '@logger'
67 tags:
68 - { name: monolog.logger, channel: graby }
66 69
67 # service alias override 70 # service alias override
68 bd_guzzle_site_authenticator.site_config_builder: 71 bd_guzzle_site_authenticator.site_config_builder: