]>
Commit | Line | Data |
---|---|---|
3b68f6ca IB |
1 | <?php |
2 | ||
3 | namespace Wallabag\UserBundle; | |
4 | ||
5 | use FOS\OAuthServerBundle\Storage\OAuthStorage; | |
6 | use OAuth2\Model\IOAuth2Client; | |
7 | use Symfony\Component\Security\Core\Exception\AuthenticationException; | |
8 | ||
9 | class OAuthStorageLdapWrapper extends OAuthStorage | |
10 | { | |
11 | private $ldapManager; | |
12 | ||
13 | public function setLdapManager($ldap_manager) | |
14 | { | |
15 | $this->ldapManager = $ldap_manager; | |
16 | } | |
17 | ||
18 | public function checkUserCredentials(IOAuth2Client $client, $username, $password) | |
19 | { | |
20 | try { | |
21 | $user = $this->userProvider->loadUserByUsername($username); | |
22 | } catch (AuthenticationException $e) { | |
23 | return false; | |
24 | } | |
25 | ||
26 | if ($user->isLdapUser()) { | |
27 | return $this->checkLdapUserCredentials($user, $password); | |
28 | } else { | |
29 | return parent::checkUserCredentials($client, $username, $password); | |
30 | } | |
31 | } | |
32 | ||
33 | private function checkLdapUserCredentials($user, $password) | |
34 | { | |
35 | if ($this->ldapManager->bind($user, $password)) { | |
36 | return array( | |
37 | 'data' => $user, | |
38 | ); | |
39 | } else { | |
40 | return false; | |
41 | } | |
42 | } | |
43 | } |