1 | <?php |
||
54 | class GuzzleJsonAuth extends \AuthPlugin |
||
55 | { |
||
56 | /** |
||
57 | * Contains the data of the authenticated user |
||
58 | * |
||
59 | * @var null|array |
||
60 | */ |
||
61 | protected $_user = null; |
||
62 | |||
63 | /** |
||
64 | * Simply state the user in question exists without checking |
||
65 | * |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | public function userExists($username) |
||
72 | |||
73 | /** |
||
74 | * Authenticate with a JSON endpoint using a configurable Guzzle client |
||
75 | * |
||
76 | * {@inheritDoc} |
||
77 | * @SuppressWarnings(PHPMD.Superglobals) |
||
78 | */ |
||
79 | public function authenticate($username, $password) |
||
107 | |||
108 | /** |
||
109 | * Initialize the authenticated user with the data from the external DB |
||
110 | * |
||
111 | * {@inheritDoc} |
||
112 | */ |
||
113 | public function initUser(&$user, $autocreate = false) |
||
119 | |||
120 | /** |
||
121 | * Update the authenticated user with the data from the external DB |
||
122 | * |
||
123 | * {@inheritDoc} |
||
124 | */ |
||
125 | public function updateUser(&$user) |
||
133 | |||
134 | /** |
||
135 | * Auto create a new local account automatically |
||
136 | * when asked to login a user who doesn't exist |
||
137 | * locally but does in the external auth database |
||
138 | * |
||
139 | * {@inheritDoc} |
||
140 | */ |
||
141 | public function autoCreate() |
||
145 | |||
146 | /** |
||
147 | * Do not allow any property changes |
||
148 | * |
||
149 | * {@inheritDoc} |
||
150 | */ |
||
151 | public function allowPropChange($prop = '') |
||
155 | |||
156 | /** |
||
157 | * Do not allow to change the password |
||
158 | * |
||
159 | * {@inheritDoc} |
||
160 | */ |
||
161 | public function allowPasswordChange() |
||
165 | |||
166 | /** |
||
167 | * Do not store the password in the local DB |
||
168 | * |
||
169 | * {@inheritDoc} |
||
170 | */ |
||
171 | public function allowSetLocalPassword() |
||
175 | |||
176 | /** |
||
177 | * Disable setting the password |
||
178 | * |
||
179 | * {@inheritDoc} |
||
180 | */ |
||
181 | public function setPassword($user, $password) |
||
185 | |||
186 | /** |
||
187 | * Disable updating the external DB |
||
188 | * |
||
189 | * {@inheritDoc} |
||
190 | */ |
||
191 | public function updateExternalDB($user) |
||
195 | |||
196 | /** |
||
197 | * Disable updating the groups in the external DB |
||
198 | * |
||
199 | * {@inheritDoc} |
||
200 | */ |
||
201 | public function updateExternalDBGroups($user, $addgroups, $delgroups = array()) |
||
205 | |||
206 | /** |
||
207 | * Disable creating accounts in the external DB |
||
208 | * |
||
209 | * {@inheritDoc} |
||
210 | */ |
||
211 | public function canCreateAccounts() |
||
215 | |||
216 | /** |
||
217 | * Disable adding user to the external DB |
||
218 | * |
||
219 | * {@inheritDoc} |
||
220 | */ |
||
221 | public function addUser($user, $password, $email = '', $realname = '') |
||
225 | |||
226 | /** |
||
227 | * Allow certain local user accounts, such as the Wiki Admin, to login |
||
228 | * |
||
229 | * {@inheritDoc} |
||
230 | */ |
||
231 | public function strict() |
||
235 | |||
236 | /** |
||
237 | * Disable strict user auth for all users |
||
238 | * |
||
239 | * {@inheritDoc} |
||
240 | * |
||
241 | * @todo Consider adding a configurable array of users who are allowed to be authenticated locally, set strict() to true then |
||
242 | */ |
||
243 | public function strictUserAuth($username) |
||
247 | |||
248 | /** |
||
249 | * Set the authentication data for the request. |
||
250 | * |
||
251 | * @param string $username The username to authenticate. |
||
252 | * @param string $password The password to authenticate. |
||
253 | * @return array The set authentication data. |
||
254 | * @SuppressWarnings(PHPMD.Superglobals) |
||
255 | */ |
||
256 | protected function _setAuthData($username, $password) |
||
271 | |||
272 | /** |
||
273 | * Get a Guzzle Client |
||
274 | * |
||
275 | * @return Client The Guzzle client. |
||
276 | */ |
||
277 | protected function _getGuzzleClient() |
||
281 | |||
282 | /** |
||
283 | * Extract the user data from the response |
||
284 | * |
||
285 | * @param ResponseInterface $response The Guzzle response object. |
||
286 | * @return array The extracted user data with 'username', 'realName' & 'email'. |
||
287 | * @SuppressWarnings(PHPMD.Superglobals) |
||
288 | */ |
||
289 | protected function _extractUserData(ResponseInterface $response) |
||
312 | |||
313 | /** |
||
314 | * Populate the user array |
||
315 | * |
||
316 | * @param string $username The username of the user. |
||
317 | * @param string $realName The real name of the user. |
||
318 | * @param string $email The email of the user. |
||
319 | * @return array The populated user array with 'username', 'realName' & 'email'. |
||
320 | */ |
||
321 | protected function _populateUserArray($username = '', $realName = '', $email = '') |
||
331 | |||
332 | /** |
||
333 | * Get a given user field |
||
334 | * |
||
335 | * @param string $fieldName The name of the field. |
||
336 | * @return string The requested field. |
||
337 | * @throws \BadMethodCallException If an invalid field is requested. |
||
338 | */ |
||
339 | protected function _getUserField($fieldName) |
||
346 | } |
||
347 |