|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the tiqr project. |
|
4
|
|
|
* |
|
5
|
|
|
* The tiqr project aims to provide an open implementation for |
|
6
|
|
|
* authentication using mobile devices. It was initiated by |
|
7
|
|
|
* SURFnet and developed by Egeniq. |
|
8
|
|
|
* |
|
9
|
|
|
* More information: http://www.tiqr.org |
|
10
|
|
|
* |
|
11
|
|
|
* @author Ivo Jansch <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @package tiqr |
|
14
|
|
|
* |
|
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
require_once 'Zend/Ldap.php'; |
|
21
|
|
|
require_once 'Zend/Ldap/Attribute.php'; |
|
22
|
|
|
require_once 'Zend/Ldap/Dn.php'; |
|
23
|
|
|
|
|
24
|
|
|
require_once 'Tiqr/UserStorage/Ldap.php'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* LDAP Tiqr storage driver. |
|
28
|
|
|
*/ |
|
29
|
|
|
class Tiqr_UserSecretStorage_Ldap extends Tiqr_UserStorage_Ldap implements Tiqr_UserSecretStorage_Interface |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Construct a user class |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $config The configuration that a specific user class may use. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct($config) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->_userClass = isset($config['userClass']) ? $config['userClass'] : "tiqrPerson"; |
|
39
|
|
|
$this->_dnPattern = isset($config['dnPattern']) ? $config['dnPattern'] : "%s"; |
|
40
|
|
|
$this->_idAttr = isset($config['idAttr']) ? $config['idAttr'] : 'dn'; |
|
41
|
|
|
$this->_secretAttr = isset($config['secretAttr']) ? $config['secretAttr'] : 'tiqrSecret'; |
|
42
|
|
|
|
|
43
|
|
|
$ldapOptions = array( |
|
44
|
|
|
"host" => $config['host'], |
|
45
|
|
|
"username" => $config['username'], |
|
46
|
|
|
"password" => $config['password'], |
|
47
|
|
|
"bindRequiresDn" => $config['bindRequiresDn'], |
|
48
|
|
|
"accountDomainName" => $config['accountDomainName'], |
|
49
|
|
|
"baseDn" => $config['baseDn'], |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$this->_ldap = new Zend_Ldap($ldapOptions); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the user's secret |
|
57
|
|
|
* |
|
58
|
|
|
* @param String $userId |
|
59
|
|
|
* |
|
60
|
|
|
* @return String The user's secret |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getUserSecret($userId) |
|
63
|
|
|
{ |
|
64
|
|
|
if ($user = $this->_loadUser($userId)) { |
|
65
|
|
|
return $this->_getLDAPAttribute($user, $this->_secretAttr); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
return NULL; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Store a secret for a user |
|
72
|
|
|
* |
|
73
|
|
|
* @param String $userId |
|
74
|
|
|
* @param String $secret |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setUserSecret($userId, $secret) |
|
77
|
|
|
{ |
|
78
|
|
|
$user = $this->_loadUser($userId); |
|
79
|
|
|
$this->_setLDAPAttribute($user, $this->_secretAttr, $secret); |
|
|
|
|
|
|
80
|
|
|
$this->_saveUser($userId, $user); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|