diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2018-12-02 12:43:05 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-01-23 13:28:02 +0100 |
commit | a6b242a1fd6f8900d80354361449f1bf62506ef9 (patch) | |
tree | f69d87208d0ebbdb8517529582280b174af74a16 /src/Wallabag/UserBundle/Entity | |
parent | acd4412080dfb73ecaa7f9983728d1d55bc27ea4 (diff) | |
download | wallabag-a6b242a1fd6f8900d80354361449f1bf62506ef9.tar.gz wallabag-a6b242a1fd6f8900d80354361449f1bf62506ef9.tar.zst wallabag-a6b242a1fd6f8900d80354361449f1bf62506ef9.zip |
Enable OTP 2FA
- Update SchebTwoFactorBundle to version 3
- Enable Google 2fa on the bundle
- Disallow ability to use both email and google as 2fa
- Update Ocramius Proxy Manager to handle typed function & attributes (from PHP 7)
- use `$this->addFlash` shortcut instead of `$this->get('session')->getFlashBag()->add`
- update admin to be able to create/reset the 2fa
Diffstat (limited to 'src/Wallabag/UserBundle/Entity')
-rw-r--r-- | src/Wallabag/UserBundle/Entity/User.php | 94 |
1 files changed, 67 insertions, 27 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 48446e3c..6e305719 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php | |||
@@ -8,8 +8,8 @@ use FOS\UserBundle\Model\User as BaseUser; | |||
8 | use JMS\Serializer\Annotation\Accessor; | 8 | use JMS\Serializer\Annotation\Accessor; |
9 | use JMS\Serializer\Annotation\Groups; | 9 | use JMS\Serializer\Annotation\Groups; |
10 | use JMS\Serializer\Annotation\XmlRoot; | 10 | use JMS\Serializer\Annotation\XmlRoot; |
11 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; | 11 | use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface; |
12 | use Scheb\TwoFactorBundle\Model\TrustedComputerInterface; | 12 | use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface; |
13 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | 13 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
14 | use Symfony\Component\Security\Core\User\UserInterface; | 14 | use Symfony\Component\Security\Core\User\UserInterface; |
15 | use Wallabag\ApiBundle\Entity\Client; | 15 | use Wallabag\ApiBundle\Entity\Client; |
@@ -28,7 +28,7 @@ use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; | |||
28 | * @UniqueEntity("email") | 28 | * @UniqueEntity("email") |
29 | * @UniqueEntity("username") | 29 | * @UniqueEntity("username") |
30 | */ | 30 | */ |
31 | class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterface | 31 | class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface |
32 | { | 32 | { |
33 | use EntityTimestampsTrait; | 33 | use EntityTimestampsTrait; |
34 | 34 | ||
@@ -123,16 +123,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
123 | private $authCode; | 123 | private $authCode; |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * @var bool | 126 | * @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true) |
127 | * | ||
128 | * @ORM\Column(type="boolean") | ||
129 | */ | 127 | */ |
130 | private $twoFactorAuthentication = false; | 128 | private $googleAuthenticatorSecret; |
131 | 129 | ||
132 | /** | 130 | /** |
133 | * @ORM\Column(type="json_array", nullable=true) | 131 | * @var bool |
132 | * | ||
133 | * @ORM\Column(type="boolean") | ||
134 | */ | 134 | */ |
135 | private $trusted; | 135 | private $emailTwoFactor = false; |
136 | 136 | ||
137 | public function __construct() | 137 | public function __construct() |
138 | { | 138 | { |
@@ -233,49 +233,89 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
233 | /** | 233 | /** |
234 | * @return bool | 234 | * @return bool |
235 | */ | 235 | */ |
236 | public function isTwoFactorAuthentication() | 236 | public function isEmailTwoFactor() |
237 | { | ||
238 | return $this->emailTwoFactor; | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * @param bool $emailTwoFactor | ||
243 | */ | ||
244 | public function setEmailTwoFactor($emailTwoFactor) | ||
237 | { | 245 | { |
238 | return $this->twoFactorAuthentication; | 246 | $this->emailTwoFactor = $emailTwoFactor; |
239 | } | 247 | } |
240 | 248 | ||
241 | /** | 249 | /** |
242 | * @param bool $twoFactorAuthentication | 250 | * Used in the user config form to be "like" the email option. |
243 | */ | 251 | */ |
244 | public function setTwoFactorAuthentication($twoFactorAuthentication) | 252 | public function isGoogleTwoFactor() |
245 | { | 253 | { |
246 | $this->twoFactorAuthentication = $twoFactorAuthentication; | 254 | return $this->isGoogleAuthenticatorEnabled(); |
247 | } | 255 | } |
248 | 256 | ||
249 | public function isEmailAuthEnabled() | 257 | /** |
258 | * {@inheritdoc} | ||
259 | */ | ||
260 | public function isEmailAuthEnabled(): bool | ||
250 | { | 261 | { |
251 | return $this->twoFactorAuthentication; | 262 | return $this->emailTwoFactor; |
252 | } | 263 | } |
253 | 264 | ||
254 | public function getEmailAuthCode() | 265 | /** |
266 | * {@inheritdoc} | ||
267 | */ | ||
268 | public function getEmailAuthCode(): string | ||
255 | { | 269 | { |
256 | return $this->authCode; | 270 | return $this->authCode; |
257 | } | 271 | } |
258 | 272 | ||
259 | public function setEmailAuthCode($authCode) | 273 | /** |
274 | * {@inheritdoc} | ||
275 | */ | ||
276 | public function setEmailAuthCode(string $authCode): void | ||
260 | { | 277 | { |
261 | $this->authCode = $authCode; | 278 | $this->authCode = $authCode; |
262 | } | 279 | } |
263 | 280 | ||
264 | public function addTrustedComputer($token, \DateTime $validUntil) | 281 | /** |
282 | * {@inheritdoc} | ||
283 | */ | ||
284 | public function getEmailAuthRecipient(): string | ||
265 | { | 285 | { |
266 | $this->trusted[$token] = $validUntil->format('r'); | 286 | return $this->email; |
267 | } | 287 | } |
268 | 288 | ||
269 | public function isTrustedComputer($token) | 289 | /** |
290 | * {@inheritdoc} | ||
291 | */ | ||
292 | public function isGoogleAuthenticatorEnabled(): bool | ||
270 | { | 293 | { |
271 | if (isset($this->trusted[$token])) { | 294 | return $this->googleAuthenticatorSecret ? true : false; |
272 | $now = new \DateTime(); | 295 | } |
273 | $validUntil = new \DateTime($this->trusted[$token]); | ||
274 | 296 | ||
275 | return $now < $validUntil; | 297 | /** |
276 | } | 298 | * {@inheritdoc} |
299 | */ | ||
300 | public function getGoogleAuthenticatorUsername(): string | ||
301 | { | ||
302 | return $this->username; | ||
303 | } | ||
277 | 304 | ||
278 | return false; | 305 | /** |
306 | * {@inheritdoc} | ||
307 | */ | ||
308 | public function getGoogleAuthenticatorSecret(): string | ||
309 | { | ||
310 | return $this->googleAuthenticatorSecret; | ||
311 | } | ||
312 | |||
313 | /** | ||
314 | * {@inheritdoc} | ||
315 | */ | ||
316 | public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void | ||
317 | { | ||
318 | $this->googleAuthenticatorSecret = $googleAuthenticatorSecret; | ||
279 | } | 319 | } |
280 | 320 | ||
281 | /** | 321 | /** |