aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-04-27 10:58:26 +0200
committerGitHub <noreply@github.com>2019-04-27 10:58:26 +0200
commitea54c2adb126a77c244c30059c40149754d4dbb7 (patch)
tree7f9fee18f321bef35ed845ce0f921dab2bddc72b /src
parentbfd69c74e5b4f2ebfcb304b1983bf771c2bb11f7 (diff)
parent35359bd3c67e5b6c6371e2e547a3411ca0a8027b (diff)
downloadwallabag-ea54c2adb126a77c244c30059c40149754d4dbb7.tar.gz
wallabag-ea54c2adb126a77c244c30059c40149754d4dbb7.tar.zst
wallabag-ea54c2adb126a77c244c30059c40149754d4dbb7.zip
Merge pull request #3937 from wallabag/fix/credential-subdomain
Add ability to match many domains for credentials
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php27
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php19
-rw-r--r--src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php8
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.th.yml2
15 files changed, 55 insertions, 23 deletions
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
index 866f55a4..faf29da6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
@@ -5,19 +5,38 @@ namespace Wallabag\CoreBundle\DataFixtures\ORM;
5use Doctrine\Common\DataFixtures\AbstractFixture; 5use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface; 6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager; 7use Doctrine\Common\Persistence\ObjectManager;
8use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9use Symfony\Component\DependencyInjection\ContainerInterface;
8use Wallabag\CoreBundle\Entity\SiteCredential; 10use Wallabag\CoreBundle\Entity\SiteCredential;
9 11
10class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface 12class LoadSiteCredentialData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
11{ 13{
12 /** 14 /**
15 * @var ContainerInterface
16 */
17 private $container;
18
19 public function setContainer(ContainerInterface $container = null)
20 {
21 $this->container = $container;
22 }
23
24 /**
13 * {@inheritdoc} 25 * {@inheritdoc}
14 */ 26 */
15 public function load(ObjectManager $manager) 27 public function load(ObjectManager $manager)
16 { 28 {
17 $credential = new SiteCredential($this->getReference('admin-user')); 29 $credential = new SiteCredential($this->getReference('admin-user'));
18 $credential->setHost('example.com'); 30 $credential->setHost('.super.com');
19 $credential->setUsername('foo'); 31 $credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('.super'));
20 $credential->setPassword('bar'); 32 $credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
33
34 $manager->persist($credential);
35
36 $credential = new SiteCredential($this->getReference('admin-user'));
37 $credential->setHost('paywall.example.com');
38 $credential->setUsername($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('paywall.example'));
39 $credential->setPassword($this->container->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
21 40
22 $manager->persist($credential); 41 $manager->persist($credential);
23 42
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 90e00c62..c7502bac 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -62,11 +62,24 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
62 $host = substr($host, 4); 62 $host = substr($host, 4);
63 } 63 }
64 64
65 $credentials = null; 65 if (!$this->currentUser) {
66 if ($this->currentUser) { 66 $this->logger->debug('Auth: no current user defined.');
67 $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); 67
68 return false;
69 }
70
71 $hosts = [$host];
72 // will try to see for a host without the first subdomain (fr.example.org & .example.org)
73 $split = explode('.', $host);
74
75 if (\count($split) > 1) {
76 // remove first subdomain
77 array_shift($split);
78 $hosts[] = '.' . implode('.', $split);
68 } 79 }
69 80
81 $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId());
82
70 if (null === $credentials) { 83 if (null === $credentials) {
71 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); 84 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
72 85
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
index b2e212a4..aeadd770 100644
--- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -19,16 +19,16 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
19 /** 19 /**
20 * Retrieve one username/password for the given host and userId. 20 * Retrieve one username/password for the given host and userId.
21 * 21 *
22 * @param string $host 22 * @param array $hosts An array of host to look for
23 * @param int $userId 23 * @param int $userId
24 * 24 *
25 * @return array|null 25 * @return array|null
26 */ 26 */
27 public function findOneByHostAndUser($host, $userId) 27 public function findOneByHostsAndUser($hosts, $userId)
28 { 28 {
29 $res = $this->createQueryBuilder('s') 29 $res = $this->createQueryBuilder('s')
30 ->select('s.username', 's.password') 30 ->select('s.username', 's.password')
31 ->where('s.host = :hostname')->setParameter('hostname', $host) 31 ->where('s.host IN (:hosts)')->setParameter('hosts', $hosts)
32 ->andWhere('s.user = :userId')->setParameter('userId', $userId) 32 ->andWhere('s.user = :userId')->setParameter('userId', $userId)
33 ->setMaxResults(1) 33 ->setMaxResults(1)
34 ->getQuery() 34 ->getQuery()
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index 97eb874d..6f842534 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 # form: 551 # form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 # save: Save 555 # save: Save
556 # delete: Delete 556 # delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index 0cf3b138..874908b9 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -550,7 +550,7 @@ site_credential:
550 create_new_one: 'Einen neuen Seitenzugang anlegen' 550 create_new_one: 'Einen neuen Seitenzugang anlegen'
551 form: 551 form:
552 username_label: 'Benutzername' 552 username_label: 'Benutzername'
553 host_label: 'Host' 553 host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 password_label: 'Passwort' 554 password_label: 'Passwort'
555 save: 'Speichern' 555 save: 'Speichern'
556 delete: 'Löschen' 556 delete: 'Löschen'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index 6085be14..598ad58d 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -550,7 +550,7 @@ site_credential:
550 create_new_one: Create a new credential 550 create_new_one: Create a new credential
551 form: 551 form:
552 username_label: 'Username' 552 username_label: 'Username'
553 host_label: 'Host' 553 host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 password_label: 'Password' 554 password_label: 'Password'
555 save: Save 555 save: Save
556 delete: Delete 556 delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index f2a8fb89..f8aa4109 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 # form: 551 # form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 # save: Save 555 # save: Save
556 # delete: Delete 556 # delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index a5cbd7ec..785e39ee 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 # form: 551 # form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 # save: Save 555 # save: Save
556 # delete: Delete 556 # delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index a36d84ae..b2fa1c50 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -550,7 +550,7 @@ site_credential:
550 create_new_one: Créer un nouvel accès à un site 550 create_new_one: Créer un nouvel accès à un site
551 form: 551 form:
552 username_label: 'Identifiant' 552 username_label: 'Identifiant'
553 host_label: 'Domaine' 553 host_label: 'Domaine (subdomain.example.org, .example.org, etc.)'
554 password_label: 'Mot de passe' 554 password_label: 'Mot de passe'
555 save: "Sauvegarder" 555 save: "Sauvegarder"
556 delete: "Supprimer" 556 delete: "Supprimer"
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index 1649c0e4..ecaa3b60 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 # form: 551 # form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 # save: Save 555 # save: Save
556 # delete: Delete 556 # delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index e2298f1f..848c88d2 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -550,7 +550,7 @@ site_credential:
550 create_new_one: Crear un novèl identificant 550 create_new_one: Crear un novèl identificant
551 form: 551 form:
552 username_label: "Nom d'utilizaire" 552 username_label: "Nom d'utilizaire"
553 host_label: 'Òste' 553 host_label: 'Òste (subdomain.example.org, .example.org, etc.)'
554 password_label: 'Senhal' 554 password_label: 'Senhal'
555 save: 'Enregistrar' 555 save: 'Enregistrar'
556 delete: 'Suprimir' 556 delete: 'Suprimir'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index a5712733..a0032fe8 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -550,7 +550,7 @@ site_credential:
550 create_new_one: Stwórz nowe poświadczenie 550 create_new_one: Stwórz nowe poświadczenie
551 form: 551 form:
552 username_label: 'Nazwa użytkownika' 552 username_label: 'Nazwa użytkownika'
553 host_label: 'Host' 553 host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 password_label: 'Hasło' 554 password_label: 'Hasło'
555 save: Zapisz 555 save: Zapisz
556 delete: Usuń 556 delete: Usuń
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
index 1ccf49e1..292fad61 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 form: 551 form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 save: 'Salvar' 555 save: 'Salvar'
556 delete: 'Apagar' 556 delete: 'Apagar'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 6c0e18e1..9e8d68b3 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -550,7 +550,7 @@ site_credential:
550 # create_new_one: Create a new credential 550 # create_new_one: Create a new credential
551 # form: 551 # form:
552 # username_label: 'Username' 552 # username_label: 'Username'
553 # host_label: 'Host' 553 # host_label: 'Host (subdomain.example.org, .example.org, etc.)'
554 # password_label: 'Password' 554 # password_label: 'Password'
555 # save: Save 555 # save: Save
556 # delete: Delete 556 # delete: Delete
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml
index 5524b1f1..cb3b0f23 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml
@@ -548,7 +548,7 @@ site_credential:
548 create_new_one: สร้างข้อมูลส่วนตัวใหม่ 548 create_new_one: สร้างข้อมูลส่วนตัวใหม่
549 form: 549 form:
550 username_label: 'ชื่อผู้ใช้' 550 username_label: 'ชื่อผู้ใช้'
551 host_label: 'โฮส' 551 host_label: 'โฮส (subdomain.example.org, .example.org, etc.)'
552 password_label: 'รหัสผ่าน' 552 password_label: 'รหัสผ่าน'
553 save: บันทึก 553 save: บันทึก
554 delete: ลบ 554 delete: ลบ