From f92fcb53ca78cc8822962e676b0db117e1a08aa5 Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Sun, 4 Dec 2016 13:51:58 +0100
Subject: Add CRUD for site credentials
---
.../Controller/SiteCredentialController.php | 138 +++++++++++++++
src/Wallabag/CoreBundle/Entity/SiteCredential.php | 197 +++++++++++++++++++++
.../CoreBundle/Form/Type/SiteCredentialType.php | 43 +++++
.../Repository/SiteCredentialRepository.php | 13 ++
.../Resources/translations/messages.da.yml | 25 +++
.../Resources/translations/messages.de.yml | 25 +++
.../Resources/translations/messages.en.yml | 25 +++
.../Resources/translations/messages.es.yml | 25 +++
.../Resources/translations/messages.fa.yml | 25 +++
.../Resources/translations/messages.fr.yml | 31 +++-
.../Resources/translations/messages.it.yml | 25 +++
.../Resources/translations/messages.oc.yml | 25 +++
.../Resources/translations/messages.pl.yml | 25 +++
.../Resources/translations/messages.pt.yml | 25 +++
.../Resources/translations/messages.ro.yml | 25 +++
.../Resources/translations/messages.tr.yml | 5 +
.../themes/baggy/SiteCredential/edit.html.twig | 60 +++++++
.../themes/baggy/SiteCredential/index.html.twig | 44 +++++
.../themes/baggy/SiteCredential/new.html.twig | 53 ++++++
.../views/themes/material/Config/index.html.twig | 20 +--
.../themes/material/SiteCredential/edit.html.twig | 60 +++++++
.../themes/material/SiteCredential/index.html.twig | 44 +++++
.../themes/material/SiteCredential/new.html.twig | 53 ++++++
23 files changed, 998 insertions(+), 13 deletions(-)
create mode 100644 src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
create mode 100644 src/Wallabag/CoreBundle/Entity/SiteCredential.php
create mode 100644 src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
create mode 100644 src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/edit.html.twig
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
create mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
new file mode 100644
index 00000000..e7e43800
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -0,0 +1,138 @@
+getDoctrine()->getManager();
+
+ $credentials = $em->getRepository('WallabagCoreBundle:SiteCredential')->findAll();
+
+ return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array(
+ 'credentials' => $credentials,
+ ));
+ }
+
+ /**
+ * Creates a new site credential entity.
+ *
+ * @Route("/site-credential/new", name="site_credential_new")
+ * @Method({"GET", "POST"})
+ */
+ public function newAction(Request $request)
+ {
+ $credential = new SiteCredential($this->getUser());
+
+ $form = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $credential);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($credential);
+ $em->flush($credential);
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ $this->get('translator')->trans('flashes.site_credential.notice.added', ['%host%' => $credential->getHost()])
+ );
+
+ return $this->redirectToRoute('site_credential_edit', array('id' => $credential->getId()));
+ }
+
+ return $this->render('WallabagCoreBundle:SiteCredential:new.html.twig', array(
+ 'credential' => $credential,
+ 'form' => $form->createView(),
+ ));
+ }
+
+ /**
+ * Displays a form to edit an existing site credential entity.
+ *
+ * @Route("/site-credential/{id}/edit", name="site_credential_edit")
+ * @Method({"GET", "POST"})
+ */
+ public function editAction(Request $request, SiteCredential $siteCredential)
+ {
+ $deleteForm = $this->createDeleteForm($siteCredential);
+ $editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\SiteCredentialType', $siteCredential);
+ $editForm->handleRequest($request);
+
+ if ($editForm->isSubmitted() && $editForm->isValid()) {
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($siteCredential);
+ $em->flush();
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ $this->get('translator')->trans('flashes.site_credential.notice.updated', ['%host%' => $siteCredential->getHost()])
+ );
+
+ return $this->redirectToRoute('site_credential_edit', array('id' => $siteCredential->getId()));
+ }
+
+ return $this->render('WallabagCoreBundle:SiteCredential:edit.html.twig', array(
+ 'credential' => $siteCredential,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ ));
+ }
+
+ /**
+ * Deletes a site credential entity.
+ *
+ * @Route("/site-credential/{id}", name="site_credential_delete")
+ * @Method("DELETE")
+ */
+ public function deleteAction(Request $request, SiteCredential $siteCredential)
+ {
+ $form = $this->createDeleteForm($siteCredential);
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ $this->get('translator')->trans('flashes.site_credential.notice.deleted', ['%host%' => $siteCredential->getHost()])
+ );
+
+ $em = $this->getDoctrine()->getManager();
+ $em->remove($siteCredential);
+ $em->flush();
+ }
+
+ return $this->redirectToRoute('site_credential_index');
+ }
+
+ /**
+ * Creates a form to delete a site credential entity.
+ *
+ * @param SiteCredential $siteCredential The site credential entity
+ *
+ * @return \Symfony\Component\Form\Form The form
+ */
+ private function createDeleteForm(SiteCredential $siteCredential)
+ {
+ return $this->createFormBuilder()
+ ->setAction($this->generateUrl('site_credential_delete', array('id' => $siteCredential->getId())))
+ ->setMethod('DELETE')
+ ->getForm()
+ ;
+ }
+}
diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
new file mode 100644
index 00000000..85ee07d4
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
@@ -0,0 +1,197 @@
+user = $user;
+ }
+
+ /**
+ * Get id.
+ *
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set host.
+ *
+ * @param string $host
+ *
+ * @return SiteCredential
+ */
+ public function setHost($host)
+ {
+ $this->host = $host;
+
+ return $this;
+ }
+
+ /**
+ * Get host.
+ *
+ * @return string
+ */
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ /**
+ * Set username.
+ *
+ * @param string $username
+ *
+ * @return SiteCredential
+ */
+ public function setUsername($username)
+ {
+ $this->username = $username;
+
+ return $this;
+ }
+
+ /**
+ * Get username.
+ *
+ * @return string
+ */
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ /**
+ * Set password.
+ *
+ * @param string $password
+ *
+ * @return SiteCredential
+ */
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ /**
+ * Get password.
+ *
+ * @return string
+ */
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ /**
+ * Set createdAt.
+ *
+ * @param \DateTime $createdAt
+ *
+ * @return SiteCredential
+ */
+ public function setCreatedAt($createdAt)
+ {
+ $this->createdAt = $createdAt;
+
+ return $this;
+ }
+
+ /**
+ * Get createdAt.
+ *
+ * @return \DateTime
+ */
+ public function getCreatedAt()
+ {
+ return $this->createdAt;
+ }
+
+ /**
+ * @return User
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
+ * @ORM\PrePersist
+ */
+ public function timestamps()
+ {
+ if (is_null($this->createdAt)) {
+ $this->createdAt = new \DateTime();
+ }
+ }
+}
diff --git a/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
new file mode 100644
index 00000000..9db7c155
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
@@ -0,0 +1,43 @@
+add('host', TextType::class, [
+ 'label' => 'site_credential.form.host_label',
+ ])
+ ->add('username', TextType::class, [
+ 'label' => 'site_credential.form.username_label',
+ ])
+ ->add('password', PasswordType::class, [
+ 'label' => 'site_credential.form.password_label',
+ ])
+ ->add('save', SubmitType::class, [
+ 'label' => 'config.form.save',
+ ])
+ ;
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults([
+ 'data_class' => 'Wallabag\CoreBundle\Entity\SiteCredential',
+ ]);
+ }
+
+ public function getBlockPrefix()
+ {
+ return 'site_credential';
+ }
+}
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
new file mode 100644
index 00000000..501b4439
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -0,0 +1,13 @@
+
+
+
+
+{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
new file mode 100644
index 00000000..fda60b31
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
@@ -0,0 +1,44 @@
+{% extends "WallabagCoreBundle::layout.html.twig" %}
+
+{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %}
+
+{% block content %}
+
+
+
+{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
new file mode 100644
index 00000000..bf713902
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
@@ -0,0 +1,53 @@
+{% extends "WallabagCoreBundle::layout.html.twig" %}
+
+{% block title %}{{ 'site_credential.page_title'|trans }}{% endblock %}
+
+{% block content %}
+
+
+
+{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig
index 9b0816eb..1e10bf38 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig
@@ -66,13 +66,13 @@
-
-
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig
index bf713902..3c008cde 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/new.html.twig
@@ -42,7 +42,7 @@
{{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
{{ form_rest(form) }}
-
{{ 'site_credential.form.back_to_list'|trans }}
+
{{ 'site_credential.form.back_to_list'|trans }}
--
cgit v1.2.3
From 5a9bc00726ddaf7c8798d4932d0a8b7a38422670 Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Mon, 1 May 2017 22:13:17 +0200
Subject: Retrieve username/password from database
Inject the current user & the repo to retrieve username/password from the database
---
.../GrabySiteConfigBuilder.php | 32 ++++++++++++++++------
.../Repository/SiteCredentialRepository.php | 18 ++++++++++++
.../CoreBundle/Resources/config/services.yml | 9 +++++-
3 files changed, 49 insertions(+), 10 deletions(-)
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 1c56fa9f..94615687 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -6,6 +6,8 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
use Graby\SiteConfig\ConfigBuilder;
use Psr\Log\LoggerInterface;
+use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
+use Wallabag\UserBundle\Entity\User;
class GrabySiteConfigBuilder implements SiteConfigBuilder
{
@@ -13,26 +15,36 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
* @var ConfigBuilder
*/
private $grabyConfigBuilder;
+
/**
- * @var array
+ * @var SiteCredentialRepository
*/
- private $credentials;
+ private $credentialRepository;
+
/**
* @var LoggerInterface
*/
private $logger;
+ /**
+ * @var User
+ */
+ private $currentUser;
+
+
/**
* GrabySiteConfigBuilder constructor.
*
- * @param ConfigBuilder $grabyConfigBuilder
- * @param array $credentials
+ * @param ConfigBuilder $grabyConfigBuilder
+ * @param User $currentUser
+ * @param SiteCredentialRepository $credentialRepository
* @param LoggerInterface $logger
*/
- public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger)
+ public function __construct(ConfigBuilder $grabyConfigBuilder, User $currentUser, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
{
$this->grabyConfigBuilder = $grabyConfigBuilder;
- $this->credentials = $credentials;
+ $this->credentialRepository = $credentialRepository;
+ $this->currentUser = $currentUser;
$this->logger = $logger;
}
@@ -47,7 +59,9 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$host = substr($host, 4);
}
- if (empty($this->credentials[$host])) {
+ $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
+
+ if (null === $credentials) {
$this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
return false;
@@ -62,8 +76,8 @@ 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);
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
index 88aee6d5..316ecc75 100644
--- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -7,4 +7,22 @@ namespace Wallabag\CoreBundle\Repository;
*/
class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
{
+ /**
+ * Retrieve one username/password for the given host and userId.
+ *
+ * @param string $host
+ * @param int $userId
+ *
+ * @return null|array
+ */
+ public function findOneByHostAndUser($host, $userId)
+ {
+ return $this->createQueryBuilder('s')
+ ->select('s.username', 's.password')
+ ->where('s.host = :hostname')->setParameter('hostname', $host)
+ ->andWhere('s.user = :userId')->setParameter('userId', $userId)
+ ->setMaxResults(1)
+ ->getQuery()
+ ->getOneOrNullResult();
+ }
}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 4be79547..a59152d3 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -63,7 +63,8 @@ services:
class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
arguments:
- "@wallabag_core.graby.config_builder"
- - "%sites_credentials%"
+ - "@=service('security.token_storage').getToken().getUser()"
+ - "@wallabag_core.site_credential_repository"
- '@logger'
tags:
- { name: monolog.logger, channel: graby }
@@ -120,6 +121,12 @@ services:
arguments:
- WallabagCoreBundle:Tag
+ wallabag_core.site_credential_repository:
+ class: Wallabag\CoreBundle\Repository\SiteCredentialRepository
+ factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
+ arguments:
+ - WallabagCoreBundle:SiteCredential
+
wallabag_core.helper.entries_export:
class: Wallabag\CoreBundle\Helper\EntriesExport
arguments:
--
cgit v1.2.3
From b8427f22f06cab58383ec3080f09715c712c65ef Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Mon, 1 May 2017 22:13:35 +0200
Subject: Add menu access to site credentials CRUD
---
.../DataFixtures/ORM/LoadSiteCredentialData.php | 34 ++++++++++++++++++++++
.../GrabySiteConfigBuilder.php | 18 ++++++++----
.../CoreBundle/Resources/config/services.yml | 2 +-
.../Resources/translations/messages.da.yml | 1 +
.../Resources/translations/messages.de.yml | 1 +
.../Resources/translations/messages.en.yml | 1 +
.../Resources/translations/messages.es.yml | 1 +
.../Resources/translations/messages.fa.yml | 1 +
.../Resources/translations/messages.fr.yml | 1 +
.../Resources/translations/messages.it.yml | 1 +
.../Resources/translations/messages.oc.yml | 1 +
.../Resources/translations/messages.pl.yml | 1 +
.../Resources/translations/messages.pt.yml | 1 +
.../Resources/translations/messages.ro.yml | 1 +
.../Resources/translations/messages.tr.yml | 1 +
.../themes/baggy/SiteCredential/edit.html.twig | 2 +-
.../themes/baggy/SiteCredential/index.html.twig | 4 +--
.../themes/baggy/SiteCredential/new.html.twig | 2 +-
.../Resources/views/themes/baggy/layout.html.twig | 3 ++
.../views/themes/material/layout.html.twig | 5 ++++
20 files changed, 71 insertions(+), 11 deletions(-)
create mode 100644 src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
new file mode 100644
index 00000000..866f55a4
--- /dev/null
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadSiteCredentialData.php
@@ -0,0 +1,34 @@
+getReference('admin-user'));
+ $credential->setHost('example.com');
+ $credential->setUsername('foo');
+ $credential->setPassword('bar');
+
+ $manager->persist($credential);
+
+ $manager->flush();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getOrder()
+ {
+ return 50;
+ }
+}
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 94615687..ae69492d 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -7,7 +7,7 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
use Graby\SiteConfig\ConfigBuilder;
use Psr\Log\LoggerInterface;
use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
-use Wallabag\UserBundle\Entity\User;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
class GrabySiteConfigBuilder implements SiteConfigBuilder
{
@@ -27,7 +27,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
private $logger;
/**
- * @var User
+ * @var Wallabag\UserBundle\Entity\User|null
*/
private $currentUser;
@@ -36,16 +36,19 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
* GrabySiteConfigBuilder constructor.
*
* @param ConfigBuilder $grabyConfigBuilder
- * @param User $currentUser
+ * @param TokenStorage $token
* @param SiteCredentialRepository $credentialRepository
* @param LoggerInterface $logger
*/
- public function __construct(ConfigBuilder $grabyConfigBuilder, User $currentUser, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
+ public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
{
$this->grabyConfigBuilder = $grabyConfigBuilder;
$this->credentialRepository = $credentialRepository;
- $this->currentUser = $currentUser;
$this->logger = $logger;
+
+ if ($token->getToken()) {
+ $this->currentUser = $token->getToken()->getUser();
+ }
}
/**
@@ -59,7 +62,10 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$host = substr($host, 4);
}
- $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
+ $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]);
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index a59152d3..09bc77fe 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -63,7 +63,7 @@ services:
class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
arguments:
- "@wallabag_core.graby.config_builder"
- - "@=service('security.token_storage').getToken().getUser()"
+ - "@security.token_storage"
- "@wallabag_core.site_credential_repository"
- '@logger'
tags:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index ef58a16b..3a3fb91d 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -32,6 +32,7 @@ menu:
# save_link: 'Save a link'
back_to_unread: 'Tilbage til de ulæste artikler'
# users_management: 'Users management'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Tilføj ny artikel'
search: 'Søg'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index d026a030..85f0e1a3 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Link speichern'
back_to_unread: 'Zurück zu ungelesenen Artikeln'
users_management: 'Benutzerverwaltung'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Neuen Artikel hinzufügen'
search: 'Suche'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index 12feb7dd..284fa2fb 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Save a link'
back_to_unread: 'Back to unread articles'
users_management: 'Users management'
+ site_credentials: 'Site credentials'
top:
add_new_entry: 'Add a new entry'
search: 'Search'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index 2351d467..33bb879c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Guardar un enlace'
back_to_unread: 'Volver a los artículos sin leer'
users_management: 'Configuración de usuarios'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Añadir un nuevo artículo'
search: 'Buscar'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index 32e1ff42..90eb119c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'ذخیرهٔ یک پیوند'
back_to_unread: 'بازگشت به خواندهنشدهها'
# users_management: 'Users management'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'افزودن مقالهٔ تازه'
search: 'جستجو'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 17eaf015..542ddf48 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -32,6 +32,7 @@ menu:
save_link: "Sauvegarder un nouvel article"
back_to_unread: "Retour aux articles non lus"
users_management: "Gestion des utilisateurs"
+ site_credentials: 'Accès aux sites'
top:
add_new_entry: "Sauvegarder un nouvel article"
search: "Rechercher"
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index 752085c8..5cb2a68f 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Salva collegamento'
back_to_unread: 'Torna ai contenuti non letti'
# users_management: 'Users management'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Aggiungi un nuovo contenuto'
search: 'Cerca'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index 9e941de0..bc11b2a4 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Enregistrar un novèl article'
back_to_unread: 'Tornar als articles pas legits'
users_management: 'Gestion dels utilizaires'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Enregistrar un novèl article'
search: 'Cercar'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index 38e051f5..033d6ac5 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Zapisz link'
back_to_unread: 'Powrót do nieprzeczytanych artykułów'
users_management: 'Zarządzanie użytkownikami'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Dodaj nowy wpis'
search: 'Szukaj'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
index d3b245b8..c70c2496 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
@@ -32,6 +32,7 @@ menu:
save_link: 'Salvar um link'
back_to_unread: 'Voltar para os artigos não lidos'
users_management: 'Gestão de Usuários'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Adicionar uma nova entrada'
search: 'Pesquisa'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 66c72429..a5dc44f0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -32,6 +32,7 @@ menu:
# save_link: 'Save a link'
back_to_unread: 'Înapoi la articolele necitite'
# users_management: 'Users management'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Introdu un nou articol'
search: 'Căutare'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
index 34ae5b87..4d01e7f7 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
@@ -32,6 +32,7 @@ menu:
# save_link: 'Save a link'
back_to_unread: 'Okunmayan makalelere geri dön'
# users_management: 'Users management'
+ # site_credentials: 'Site credentials'
top:
add_new_entry: 'Yeni bir makale ekle'
search: 'Ara'
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig
index 8448f17e..882be430 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/edit.html.twig
@@ -49,7 +49,7 @@
{{ form_end(delete_form) }}
- {{ 'site_credential.form.back_to_list'|trans }}
+ {{ 'site_credential.form.back_to_list'|trans }}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
index fda60b31..c128bceb 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
@@ -25,7 +25,7 @@
{{ credential.host }} |
{{ credential.username }} |
- {{ 'site_credential.list.edit_action'|trans }}
+ {{ 'site_credential.list.edit_action'|trans }}
|
{% endfor %}
@@ -33,7 +33,7 @@
- {{ 'site_credential.list.create_new_one'|trans }}
+ {{ 'site_credential.list.create_new_one'|trans }}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
index bf713902..3c008cde 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/new.html.twig
@@ -42,7 +42,7 @@
{{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
{{ form_rest(form) }}
- {{ 'site_credential.form.back_to_list'|trans }}
+ {{ 'site_credential.form.back_to_list'|trans }}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
index 42aeace9..17fa13bb 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig
@@ -38,6 +38,9 @@
{{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }}
+ {% if craue_setting('restricted_access') %}
+
+ {% endif %}
{% if is_granted('ROLE_SUPER_ADMIN') %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
index 2dab1c18..60907e11 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
@@ -66,6 +66,11 @@
{{ 'menu.left.config'|trans }}
+ {% if craue_setting('restricted_access') %}
+
+ {{ 'menu.left.site_credentials'|trans }}
+
+ {% endif %}
{% if is_granted('ROLE_SUPER_ADMIN') %}
{{ 'menu.left.users_management'|trans }}
--
cgit v1.2.3
From 9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Wed, 3 May 2017 10:23:49 +0200
Subject: Add a live test for restricted article
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
It is not aimed to test if we can get the full article (since we aren't using real login/password)
but mostly to test the full work (with authentication, etc.)
Do not clean fixtured to avoid SQLite to re-use id for entry tag relation 😓
---
src/Wallabag/CoreBundle/Controller/SiteCredentialController.php | 4 +---
.../CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 5 ++---
2 files changed, 3 insertions(+), 6 deletions(-)
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index 429f529a..dc8e723d 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -24,9 +24,7 @@ class SiteCredentialController extends Controller
*/
public function indexAction()
{
- $em = $this->getDoctrine()->getManager();
-
- $credentials = $em->getRepository('WallabagCoreBundle:SiteCredential')->findByUser($this->getUser());
+ $credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array(
'credentials' => $credentials,
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index ae69492d..62a3bc13 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -31,14 +31,13 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
*/
private $currentUser;
-
/**
* GrabySiteConfigBuilder constructor.
*
* @param ConfigBuilder $grabyConfigBuilder
- * @param TokenStorage $token
+ * @param TokenStorage $token
* @param SiteCredentialRepository $credentialRepository
- * @param LoggerInterface $logger
+ * @param LoggerInterface $logger
*/
public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
{
--
cgit v1.2.3
From 906424c1b6fd884bf2081bfe6dd0b1f9651c2801 Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Sun, 11 Jun 2017 23:05:19 +0200
Subject: Crypt site credential password
---
src/Wallabag/CoreBundle/Command/InstallCommand.php | 2 +
.../Controller/SiteCredentialController.php | 2 +
.../DependencyInjection/Configuration.php | 2 +
.../DependencyInjection/WallabagCoreExtension.php | 1 +
src/Wallabag/CoreBundle/Entity/SiteCredential.php | 3 +-
src/Wallabag/CoreBundle/Helper/CryptoProxy.php | 86 ++++++++++++++++++++++
.../Repository/SiteCredentialRepository.php | 20 ++++-
.../CoreBundle/Resources/config/services.yml | 8 ++
8 files changed, 121 insertions(+), 3 deletions(-)
create mode 100644 src/Wallabag/CoreBundle/Helper/CryptoProxy.php
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 0f119377..eb725a59 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -313,6 +313,8 @@ class InstallCommand extends ContainerAwareCommand
$this
->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]);
+
+ return $this;
}
/**
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index dc8e723d..0bacafb7 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -45,6 +45,8 @@ class SiteCredentialController extends Controller
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
+ $credential->setPassword($this->get('wallabag_core.helper.crypto_proxy')->crypt($credential->getPassword()));
+
$em = $this->getDoctrine()->getManager();
$em->persist($credential);
$em->flush($credential);
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
index 33df92d3..a9791f6b 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
@@ -63,6 +63,8 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->end()
+ ->scalarNode('encryption_key_path')
+ ->end()
->end()
;
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
index b4d8a386..532ce238 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
@@ -29,6 +29,7 @@ class WallabagCoreExtension extends Extension
$container->setParameter('wallabag_core.fetching_error_message_title', $config['fetching_error_message_title']);
$container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']);
$container->setParameter('wallabag_core.default_internal_settings', $config['default_internal_settings']);
+ $container->setParameter('wallabag_core.site_credentials.encryption_key_path', $config['encryption_key_path']);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
index 85ee07d4..732d9506 100644
--- a/src/Wallabag/CoreBundle/Entity/SiteCredential.php
+++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
@@ -46,8 +46,7 @@ class SiteCredential
* @var string
*
* @Assert\NotBlank()
- * @Assert\Length(max=255)
- * @ORM\Column(name="password", type="string", length=255)
+ * @ORM\Column(name="password", type="text")
*/
private $password;
diff --git a/src/Wallabag/CoreBundle/Helper/CryptoProxy.php b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php
new file mode 100644
index 00000000..d0a9b85c
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php
@@ -0,0 +1,86 @@
+logger = $logger;
+
+ if (!file_exists($encryptionKeyPath)) {
+ $key = Key::createNewRandomKey();
+
+ file_put_contents($encryptionKeyPath, $key->saveToAsciiSafeString());
+ chmod($encryptionKeyPath, 0600);
+ }
+
+ $this->encryptionKey = file_get_contents($encryptionKeyPath);
+ }
+
+ /**
+ * Ensure the given value will be crypted.
+ *
+ * @param string $secretValue Secret valye to crypt
+ *
+ * @return string
+ */
+ public function crypt($secretValue)
+ {
+ $this->logger->debug('Crypto: crypting value: '.$this->mask($secretValue));
+
+ return Crypto::encrypt($secretValue, $this->loadKey());
+ }
+
+ /**
+ * Ensure the given crypted value will be decrypted.
+ *
+ * @param string $cryptedValue The value to be decrypted
+ *
+ * @return string
+ */
+ public function decrypt($cryptedValue)
+ {
+ $this->logger->debug('Crypto: decrypting value: '.$this->mask($cryptedValue));
+
+ try {
+ return Crypto::decrypt($cryptedValue, $this->loadKey());
+ } catch (WrongKeyOrModifiedCiphertextException $e) {
+ throw new \RuntimeException('Decrypt fail: '.$e->getMessage());
+ }
+ }
+
+ /**
+ * Load the private key.
+ *
+ * @return string
+ */
+ private function loadKey()
+ {
+ return Key::loadFromAsciiSafeString($this->encryptionKey);
+ }
+
+ /**
+ * Keep first and last character and put some stars in between.
+ *
+ * @param string $value Value to mask
+ *
+ * @return string
+ */
+ private function mask($value)
+ {
+ return $value[0].'*****'.$value[strlen($value) - 1];
+ }
+}
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
index 316ecc75..6f904f0a 100644
--- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -2,11 +2,20 @@
namespace Wallabag\CoreBundle\Repository;
+use Wallabag\CoreBundle\Helper\CryptoProxy;
+
/**
* SiteCredentialRepository.
*/
class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
{
+ private $cryptoProxy;
+
+ public function setCrypto(CryptoProxy $cryptoProxy)
+ {
+ $this->cryptoProxy = $cryptoProxy;
+ }
+
/**
* Retrieve one username/password for the given host and userId.
*
@@ -17,12 +26,21 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
*/
public function findOneByHostAndUser($host, $userId)
{
- return $this->createQueryBuilder('s')
+ $res = $this->createQueryBuilder('s')
->select('s.username', 's.password')
->where('s.host = :hostname')->setParameter('hostname', $host)
->andWhere('s.user = :userId')->setParameter('userId', $userId)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
+
+ if (null === $res) {
+ return;
+ }
+
+ // decrypt password before returning it
+ $res['password'] = $this->cryptoProxy->decrypt($res['password']);
+
+ return $res;
}
}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 09bc77fe..e09b0f18 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -126,6 +126,8 @@ services:
factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
arguments:
- WallabagCoreBundle:SiteCredential
+ calls:
+ - [ setCrypto, [ "@wallabag_core.helper.crypto_proxy" ] ]
wallabag_core.helper.entries_export:
class: Wallabag\CoreBundle\Helper\EntriesExport
@@ -208,3 +210,9 @@ services:
wallabag_core.entry.download_images.client:
class: GuzzleHttp\Client
+
+ wallabag_core.helper.crypto_proxy:
+ class: Wallabag\CoreBundle\Helper\CryptoProxy
+ arguments:
+ - "%wallabag_core.site_credentials.encryption_key_path%"
+ - "@logger"
--
cgit v1.2.3
From bead8b42da4f17238dc0d5e0f90184b224ec5df7 Mon Sep 17 00:00:00 2001
From: Thomas Citharel
Date: Wed, 14 Jun 2017 15:02:34 +0200
Subject: Fix reviews
Encrypt username too
Redirect to list after saving credentials
Fix typos
Signed-off-by: Thomas Citharel
---
.../Controller/SiteCredentialController.php | 38 ++++++++++++++++------
src/Wallabag/CoreBundle/Entity/SiteCredential.php | 3 +-
.../CoreBundle/Form/Type/SiteCredentialType.php | 1 +
.../GrabySiteConfigBuilder.php | 3 +-
src/Wallabag/CoreBundle/Helper/CryptoProxy.php | 4 +--
.../Repository/SiteCredentialRepository.php | 3 +-
.../Resources/translations/messages.fr.yml | 4 +--
.../themes/material/SiteCredential/index.html.twig | 4 ++-
8 files changed, 41 insertions(+), 19 deletions(-)
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index 0bacafb7..98781dab 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -26,9 +26,9 @@ class SiteCredentialController extends Controller
{
$credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
- return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array(
+ return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', [
'credentials' => $credentials,
- ));
+ ]);
}
/**
@@ -36,6 +36,10 @@ class SiteCredentialController extends Controller
*
* @Route("/new", name="site_credentials_new")
* @Method({"GET", "POST"})
+ *
+ * @param Request $request
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
*/
public function newAction(Request $request)
{
@@ -45,24 +49,25 @@ class SiteCredentialController extends Controller
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
+ $credential->setUsername($this->get('wallabag_core.helper.crypto_proxy')->crypt($credential->getUsername()));
$credential->setPassword($this->get('wallabag_core.helper.crypto_proxy')->crypt($credential->getPassword()));
$em = $this->getDoctrine()->getManager();
$em->persist($credential);
- $em->flush($credential);
+ $em->flush();
$this->get('session')->getFlashBag()->add(
'notice',
$this->get('translator')->trans('flashes.site_credential.notice.added', ['%host%' => $credential->getHost()])
);
- return $this->redirectToRoute('site_credentials_edit', array('id' => $credential->getId()));
+ return $this->redirectToRoute('site_credentials_index');
}
- return $this->render('WallabagCoreBundle:SiteCredential:new.html.twig', array(
+ return $this->render('WallabagCoreBundle:SiteCredential:new.html.twig', [
'credential' => $credential,
'form' => $form->createView(),
- ));
+ ]);
}
/**
@@ -70,6 +75,11 @@ class SiteCredentialController extends Controller
*
* @Route("/{id}/edit", name="site_credentials_edit")
* @Method({"GET", "POST"})
+ *
+ * @param Request $request
+ * @param SiteCredential $siteCredential
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
*/
public function editAction(Request $request, SiteCredential $siteCredential)
{
@@ -80,6 +90,9 @@ class SiteCredentialController extends Controller
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
+ $siteCredential->setUsername($this->get('wallabag_core.helper.crypto_proxy')->crypt($siteCredential->getUsername()));
+ $siteCredential->setPassword($this->get('wallabag_core.helper.crypto_proxy')->crypt($siteCredential->getPassword()));
+
$em = $this->getDoctrine()->getManager();
$em->persist($siteCredential);
$em->flush();
@@ -89,14 +102,14 @@ class SiteCredentialController extends Controller
$this->get('translator')->trans('flashes.site_credential.notice.updated', ['%host%' => $siteCredential->getHost()])
);
- return $this->redirectToRoute('site_credentials_edit', array('id' => $siteCredential->getId()));
+ return $this->redirectToRoute('site_credentials_index');
}
- return $this->render('WallabagCoreBundle:SiteCredential:edit.html.twig', array(
+ return $this->render('WallabagCoreBundle:SiteCredential:edit.html.twig', [
'credential' => $siteCredential,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
- ));
+ ]);
}
/**
@@ -104,6 +117,11 @@ class SiteCredentialController extends Controller
*
* @Route("/{id}", name="site_credentials_delete")
* @Method("DELETE")
+ *
+ * @param Request $request
+ * @param SiteCredential $siteCredential
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function deleteAction(Request $request, SiteCredential $siteCredential)
{
@@ -136,7 +154,7 @@ class SiteCredentialController extends Controller
private function createDeleteForm(SiteCredential $siteCredential)
{
return $this->createFormBuilder()
- ->setAction($this->generateUrl('site_credentials_delete', array('id' => $siteCredential->getId())))
+ ->setAction($this->generateUrl('site_credentials_delete', ['id' => $siteCredential->getId()]))
->setMethod('DELETE')
->getForm()
;
diff --git a/src/Wallabag/CoreBundle/Entity/SiteCredential.php b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
index 732d9506..58075e92 100644
--- a/src/Wallabag/CoreBundle/Entity/SiteCredential.php
+++ b/src/Wallabag/CoreBundle/Entity/SiteCredential.php
@@ -37,8 +37,7 @@ class SiteCredential
* @var string
*
* @Assert\NotBlank()
- * @Assert\Length(max=255)
- * @ORM\Column(name="username", type="string", length=255)
+ * @ORM\Column(name="username", type="text")
*/
private $username;
diff --git a/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
index 9db7c155..fd409ad2 100644
--- a/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/SiteCredentialType.php
@@ -19,6 +19,7 @@ class SiteCredentialType extends AbstractType
])
->add('username', TextType::class, [
'label' => 'site_credential.form.username_label',
+ 'data' => '',
])
->add('password', PasswordType::class, [
'label' => 'site_credential.form.password_label',
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 62a3bc13..a79e6ebe 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -87,7 +87,8 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
$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]);
diff --git a/src/Wallabag/CoreBundle/Helper/CryptoProxy.php b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php
index d0a9b85c..e8b19cb9 100644
--- a/src/Wallabag/CoreBundle/Helper/CryptoProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/CryptoProxy.php
@@ -65,7 +65,7 @@ class CryptoProxy
/**
* Load the private key.
*
- * @return string
+ * @return Key
*/
private function loadKey()
{
@@ -81,6 +81,6 @@ class CryptoProxy
*/
private function mask($value)
{
- return $value[0].'*****'.$value[strlen($value) - 1];
+ return strlen($value) > 0 ? $value[0].'*****'.$value[strlen($value) - 1] : 'Empty value';
}
}
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
index 6f904f0a..36906761 100644
--- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -38,7 +38,8 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
return;
}
- // decrypt password before returning it
+ // decrypt user & password before returning them
+ $res['username'] = $this->cryptoProxy->decrypt($res['username']);
$res['password'] = $this->cryptoProxy->decrypt($res['password']);
return $res;
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 542ddf48..cd239b5c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -515,7 +515,7 @@ user:
twofactor_label: "Double authentification"
save: "Sauvegarder"
delete: "Supprimer"
- delete_confirm: "Êtes-vous sur ?"
+ delete_confirm: "Êtes-vous sûr ?"
back_to_list: "Revenir à la liste"
search:
placeholder: "Filtrer par nom d’utilisateur ou email"
@@ -537,7 +537,7 @@ site_credential:
password_label: 'Mot de passe'
save: "Sauvegarder"
delete: "Supprimer"
- delete_confirm: "Êtes-vous sur ?"
+ delete_confirm: "Êtes-vous sûr ?"
back_to_list: "Revenir à la liste"
error:
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
index c128bceb..4d30a692 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
@@ -16,6 +16,7 @@
{{ 'site_credential.form.host_label'|trans }} |
{{ 'site_credential.form.username_label'|trans }} |
+ {{ 'site_credential.form.password_label'|trans }} |
{{ 'site_credential.list.actions'|trans }} |
@@ -23,7 +24,8 @@
{% for credential in credentials %}
{{ credential.host }} |
- {{ credential.username }} |
+ ***** |
+ ***** |
{{ 'site_credential.list.edit_action'|trans }}
|
--
cgit v1.2.3
From f44dba22fc1a566cb156d9e6eda5afc353163eda Mon Sep 17 00:00:00 2001
From: Jeremy Benoist
Date: Sun, 18 Jun 2017 15:34:59 +0200
Subject: Get rid of masked value in listing
---
.../Resources/views/themes/baggy/SiteCredential/index.html.twig | 2 --
.../Resources/views/themes/material/SiteCredential/index.html.twig | 4 ----
2 files changed, 6 deletions(-)
(limited to 'src')
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
index c128bceb..324854ad 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/SiteCredential/index.html.twig
@@ -15,7 +15,6 @@
{{ 'site_credential.form.host_label'|trans }} |
- {{ 'site_credential.form.username_label'|trans }} |
{{ 'site_credential.list.actions'|trans }} |
@@ -23,7 +22,6 @@
{% for credential in credentials %}
{{ credential.host }} |
- {{ credential.username }} |
{{ 'site_credential.list.edit_action'|trans }}
|
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
index 4d30a692..324854ad 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/SiteCredential/index.html.twig
@@ -15,8 +15,6 @@
{{ 'site_credential.form.host_label'|trans }} |
- {{ 'site_credential.form.username_label'|trans }} |
- {{ 'site_credential.form.password_label'|trans }} |
{{ 'site_credential.list.actions'|trans }} |
@@ -24,8 +22,6 @@
{% for credential in credentials %}
{{ credential.host }} |
- ***** |
- ***** |
{{ 'site_credential.list.edit_action'|trans }}
|
--
cgit v1.2.3