diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php')
-rw-r--r-- | src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 36 |
1 files changed, 27 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; | |||
6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; | 6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; |
7 | use Graby\SiteConfig\ConfigBuilder; | 7 | use Graby\SiteConfig\ConfigBuilder; |
8 | use OutOfRangeException; | 8 | use OutOfRangeException; |
9 | use Psr\Log\LoggerInterface; | ||
9 | 10 | ||
10 | class GrabySiteConfigBuilder implements SiteConfigBuilder | 11 | class 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 | } |