summaryrefslogtreecommitdiffstats
path: root/lib/kolab_api_controller.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-11-04 08:47:08 -0500
committerAleksander Machniak <machniak@kolabsys.com>2014-11-04 08:47:08 -0500
commite561788b5c9bc243e332c09d86506489deeee796 (patch)
tree434c29987ad5515e6c967de4303c3f56c4d310ca /lib/kolab_api_controller.php
parentbe7ef6f18d07aa3f71be0184c8845c646fa09a18 (diff)
downloadwebadmin-e561788b5c9bc243e332c09d86506489deeee796.tar.gz
Return user info in system.authenticate result for better performance (#3858)
Diffstat (limited to 'lib/kolab_api_controller.php')
-rw-r--r--lib/kolab_api_controller.php38
1 files changed, 24 insertions, 14 deletions
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index db7a842..ed716cf 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -293,8 +293,6 @@ class kolab_api_controller
{
Log::trace("Authenticating user: " . $postdata['username']);
- $valid = false;
-
// destroy old session
if ($this->session_validate($postdata)) {
session_destroy();
@@ -303,38 +301,50 @@ class kolab_api_controller
session_start();
$_SESSION['user'] = new User();
+ $attributes = null;
+ $password = $postdata['password'];
+ $username = $postdata['username'];
+ $domain = $postdata['domain'];
- if (empty($postdata['domain'])) {
+ // find user domain
+ if (empty($domain)) {
Log::debug("No login domain specified. Attempting to derive from username.");
- if (count(explode('@', $postdata['username'])) > 1) {
- $login = explode('@', $postdata['username']);
+ if (count(explode('@', $username)) == 2) {
+ $login = explode('@', $username);
$username = array_shift($login);
- $domain = array_shift($login);
+ $domain = array_shift($login);
}
else {
Log::debug("No domain name space in the username, using the primary domain");
$domain = $this->config->get('kolab', 'primary_domain');
}
}
- else {
- $domain = $postdata['domain'];
- }
- if (empty($username)) {
- $username = $postdata['username'];
+ // user info requested (it's not possible to get manager info)
+ if ($postdata['info'] && ($username != 'cn=Directory Manager')) {
+ $service = $this->get_service('user');
+ $attributes = $service->object_attributes('user');
}
- $valid = $_SESSION['user']->authenticate($username, $postdata['password'], $domain);
+ // authenticate
+ $user_dn = $_SESSION['user']->authenticate($username, $password, $domain, $attributes);
// start new (PHP) session
- if ($valid) {
+ if ($user_dn) {
$_SESSION['time'] = time();
- return array(
+ $result = array(
'user' => $_SESSION['user']->get_username(),
'userid' => $_SESSION['user']->get_userid(),
'domain' => $_SESSION['user']->get_domain(),
'session_token' => session_id(),
);
+
+ if (!empty($attributes)) {
+ $attributes = array($user_dn => $attributes);
+ $result['info'] = $service->parse_result_attributes('user', $attributes);
+ }
+
+ return $result;
}
return false;