1 | <?php |
||
37 | abstract class Proxy { |
||
38 | static private $accesses = array(); |
||
39 | private $ldap = null; |
||
40 | |||
41 | /** @var \OCP\ICache|null */ |
||
42 | private $cache; |
||
43 | |||
44 | /** |
||
45 | * @param ILDAPWrapper $ldap |
||
46 | */ |
||
47 | public function __construct(ILDAPWrapper $ldap) { |
||
54 | |||
55 | /** |
||
56 | * @param string $configPrefix |
||
57 | */ |
||
58 | private function addAccess($configPrefix) { |
||
59 | static $ocConfig; |
||
60 | static $fs; |
||
61 | static $log; |
||
62 | static $avatarM; |
||
63 | static $userMap; |
||
64 | static $groupMap; |
||
65 | static $db; |
||
66 | static $coreUserManager; |
||
67 | static $coreNotificationManager; |
||
68 | if($fs === null) { |
||
69 | $ocConfig = \OC::$server->getConfig(); |
||
70 | $fs = new FilesystemHelper(); |
||
71 | $log = new LogWrapper(); |
||
72 | $avatarM = \OC::$server->getAvatarManager(); |
||
73 | $db = \OC::$server->getDatabaseConnection(); |
||
74 | $userMap = new UserMapping($db); |
||
75 | $groupMap = new GroupMapping($db); |
||
76 | $coreUserManager = \OC::$server->getUserManager(); |
||
77 | $coreNotificationManager = \OC::$server->getNotificationManager(); |
||
78 | } |
||
79 | $userManager = |
||
80 | new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, |
||
81 | $coreUserManager, $coreNotificationManager); |
||
82 | $connector = new Connection($this->ldap, $configPrefix); |
||
83 | $access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig())); |
||
84 | $access->setUserMapper($userMap); |
||
85 | $access->setGroupMapper($groupMap); |
||
86 | self::$accesses[$configPrefix] = $access; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param string $configPrefix |
||
91 | * @return mixed |
||
92 | */ |
||
93 | protected function getAccess($configPrefix) { |
||
94 | if(!isset(self::$accesses[$configPrefix])) { |
||
95 | $this->addAccess($configPrefix); |
||
96 | } |
||
97 | return self::$accesses[$configPrefix]; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param string $uid |
||
102 | * @return string |
||
103 | */ |
||
104 | protected function getUserCacheKey($uid) { |
||
105 | return 'user-'.$uid.'-lastSeenOn'; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param string $gid |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function getGroupCacheKey($gid) { |
||
113 | return 'group-'.$gid.'-lastSeenOn'; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param string $id |
||
118 | * @param string $method |
||
119 | * @param array $parameters |
||
120 | * @param bool $passOnWhen |
||
121 | * @return mixed |
||
122 | */ |
||
123 | abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
||
124 | |||
125 | /** |
||
126 | * @param string $id |
||
127 | * @param string $method |
||
128 | * @param array $parameters |
||
129 | * @return mixed |
||
130 | */ |
||
131 | abstract protected function walkBackends($id, $method, $parameters); |
||
132 | |||
133 | /** |
||
134 | * @param string $id |
||
135 | * @return Access |
||
136 | */ |
||
137 | abstract public function getLDAPAccess($id); |
||
138 | |||
139 | /** |
||
140 | * Takes care of the request to the User backend |
||
141 | * @param string $id |
||
142 | * @param string $method string, the method of the user backend that shall be called |
||
143 | * @param array $parameters an array of parameters to be passed |
||
144 | * @param bool $passOnWhen |
||
145 | * @return mixed, the result of the specified method |
||
|
|||
146 | */ |
||
147 | protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
||
148 | $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
||
149 | if($result === $passOnWhen) { |
||
150 | $result = $this->walkBackends($id, $method, $parameters); |
||
151 | } |
||
152 | return $result; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param string|null $key |
||
157 | * @return string |
||
158 | */ |
||
159 | private function getCacheKey($key) { |
||
160 | $prefix = 'LDAP-Proxy-'; |
||
161 | if($key === null) { |
||
162 | return $prefix; |
||
163 | } |
||
164 | return $prefix.md5($key); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @param string $key |
||
169 | * @return mixed|null |
||
170 | */ |
||
171 | public function getFromCache($key) { |
||
172 | if($this->cache === null) { |
||
173 | return null; |
||
174 | } |
||
175 | |||
176 | $key = $this->getCacheKey($key); |
||
177 | $value = $this->cache->get($key); |
||
178 | if ($value === null) { |
||
179 | return null; |
||
180 | } |
||
181 | |||
182 | return json_decode(base64_decode($value)); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param string $key |
||
187 | * @param mixed $value |
||
188 | */ |
||
189 | public function writeToCache($key, $value) { |
||
197 | |||
198 | public function clearCache() { |
||
204 | } |
||
205 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.