mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-22 19:49:02 +01:00
Fix some more ldap issues
Summary: - LDAP import needs to use envelopes. - Use ldap_sprintf(). Test Plan: Configured an LDAP server. Added an account. Imported it; logged in with it. Tried to login with accounts like ",", etc., got good errors. Reviewers: vrana, btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D2995
This commit is contained in:
parent
a620a172a0
commit
30deacdbaf
3 changed files with 48 additions and 37 deletions
|
@ -35,10 +35,12 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||||
$current_user = $this->getRequest()->getUser();
|
$current_user = $this->getRequest()->getUser();
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
$ldap_username = $request->getCookie('phusr');
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
|
$ldap_username = $request->getStr('username');
|
||||||
try {
|
try {
|
||||||
$envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
|
$envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
|
||||||
$this->provider->auth($request->getStr('username'), $envelope);
|
$this->provider->auth($ldap_username, $envelope);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$errors[] = $e->getMessage();
|
$errors[] = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +126,6 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ldap_username = $request->getCookie('phusr');
|
|
||||||
$ldap_form = new AphrontFormView();
|
$ldap_form = new AphrontFormView();
|
||||||
$ldap_form
|
$ldap_form
|
||||||
->setUser($request->getUser())
|
->setUser($request->getUser())
|
||||||
|
|
|
@ -117,8 +117,11 @@ final class PhabricatorLDAPProvider {
|
||||||
if ($activeDirectoryDomain) {
|
if ($activeDirectoryDomain) {
|
||||||
$dn = $username . '@' . $activeDirectoryDomain;
|
$dn = $username . '@' . $activeDirectoryDomain;
|
||||||
} else {
|
} else {
|
||||||
$dn = $this->getSearchAttribute() . '=' . $username . ',' .
|
$dn = ldap_sprintf(
|
||||||
$this->getBaseDN();
|
'%Q=%s,%Q',
|
||||||
|
$this->getSearchAttribute(),
|
||||||
|
$username,
|
||||||
|
$this->getBaseDN());
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = $this->getConnection();
|
$conn = $this->getConnection();
|
||||||
|
@ -139,15 +142,21 @@ final class PhabricatorLDAPProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUser($username) {
|
private function getUser($username) {
|
||||||
$result = ldap_search($this->getConnection(), $this->getBaseDN(),
|
$conn = $this->getConnection();
|
||||||
$this->getSearchAttribute() . '=' . $username);
|
|
||||||
|
$query = ldap_sprintf(
|
||||||
|
'%Q=%S',
|
||||||
|
$this->getSearchAttribute(),
|
||||||
|
$username);
|
||||||
|
|
||||||
|
$result = ldap_search($conn, $this->getBaseDN(), $query);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
throw new Exception('Search failed. Please check your LDAP and HTTP '.
|
throw new Exception('Search failed. Please check your LDAP and HTTP '.
|
||||||
'logs for more information.');
|
'logs for more information.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = ldap_get_entries($this->getConnection(), $result);
|
$entries = ldap_get_entries($conn, $result);
|
||||||
|
|
||||||
if ($entries === false) {
|
if ($entries === false) {
|
||||||
throw new Exception('Could not get entries');
|
throw new Exception('Could not get entries');
|
||||||
|
|
|
@ -54,7 +54,7 @@ final class PhabricatorPeopleLdapController
|
||||||
->setValue('Search'));
|
->setValue('Search'));
|
||||||
|
|
||||||
$panel = new AphrontPanelView();
|
$panel = new AphrontPanelView();
|
||||||
$panel->setHeader('Import Ldap Users');
|
$panel->setHeader('Import LDAP Users');
|
||||||
$panel->appendChild($form);
|
$panel->appendChild($form);
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,8 @@ final class PhabricatorPeopleLdapController
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$ldap_provider = new PhabricatorLDAPProvider();
|
$ldap_provider = new PhabricatorLDAPProvider();
|
||||||
$ldap_provider->auth($username, $password);
|
$envelope = new PhutilOpaqueEnvelope($password);
|
||||||
|
$ldap_provider->auth($username, $envelope);
|
||||||
$results = $ldap_provider->search($search);
|
$results = $ldap_provider->search($search);
|
||||||
foreach ($results as $key => $result) {
|
foreach ($results as $key => $result) {
|
||||||
$results[$key][] = $this->renderUserInputs($result);
|
$results[$key][] = $this->renderUserInputs($result);
|
||||||
|
@ -141,7 +142,7 @@ final class PhabricatorPeopleLdapController
|
||||||
'Username',
|
'Username',
|
||||||
'Email',
|
'Email',
|
||||||
'RealName',
|
'RealName',
|
||||||
'',
|
'Import?',
|
||||||
));
|
));
|
||||||
$form->appendChild($table);
|
$form->appendChild($table);
|
||||||
$form->setAction($request->getRequestURI()
|
$form->setAction($request->getRequestURI()
|
||||||
|
@ -163,35 +164,35 @@ final class PhabricatorPeopleLdapController
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderUserInputs($user) {
|
private function renderUserInputs($user) {
|
||||||
$username = $user[0];
|
$username = $user[0];
|
||||||
$inputs = phutil_render_tag(
|
$inputs = phutil_render_tag(
|
||||||
'input',
|
'input',
|
||||||
array(
|
array(
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'name' => 'usernames[]',
|
'name' => 'usernames[]',
|
||||||
'value' =>$username,
|
'value' =>$username,
|
||||||
),
|
),
|
||||||
'');
|
'');
|
||||||
|
|
||||||
$inputs .= phutil_render_tag(
|
$inputs .= phutil_render_tag(
|
||||||
'input',
|
'input',
|
||||||
array(
|
array(
|
||||||
'type' => 'hidden',
|
'type' => 'hidden',
|
||||||
'name' => "email[$username]",
|
'name' => "email[$username]",
|
||||||
'value' =>$user[1],
|
'value' =>$user[1],
|
||||||
),
|
),
|
||||||
'');
|
'');
|
||||||
|
|
||||||
$inputs .= phutil_render_tag(
|
$inputs .= phutil_render_tag(
|
||||||
'input',
|
'input',
|
||||||
array(
|
array(
|
||||||
'type' => 'hidden',
|
'type' => 'hidden',
|
||||||
'name' => "name[$username]",
|
'name' => "name[$username]",
|
||||||
'value' =>$user[2],
|
'value' =>$user[2],
|
||||||
),
|
),
|
||||||
'');
|
'');
|
||||||
|
|
||||||
return $inputs;
|
|
||||||
|
|
||||||
|
return $inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue