diff options
Diffstat (limited to 'src/Wallabag/UserBundle/OAuthStorageLdapWrapper.php')
-rw-r--r-- | src/Wallabag/UserBundle/OAuthStorageLdapWrapper.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/OAuthStorageLdapWrapper.php b/src/Wallabag/UserBundle/OAuthStorageLdapWrapper.php new file mode 100644 index 00000000..8a851f12 --- /dev/null +++ b/src/Wallabag/UserBundle/OAuthStorageLdapWrapper.php | |||
@@ -0,0 +1,43 @@ | |||
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 | } | ||