Skip to content

Commit c0cc7bb

Browse files
author
epriestley
committedJun 17, 2013
Provide bin/auth ldap for LDAP diagnostics
Summary: Ref T1536. Test Plan: Ran `bin/auth ldap`. Reviewers: mbishopim3, chad Reviewed By: mbishopim3 CC: aran Maniphest Tasks: T1536 Differential Revision: https://secure.phabricator.com/D6218
1 parent fded36c commit c0cc7bb

File tree

4 files changed

+102
-23
lines changed

4 files changed

+102
-23
lines changed
 

‎scripts/setup/manage_auth.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
$args->parseStandardArguments();
1616

1717
$workflows = array(
18-
new PhabricatorAuthManagementListWorkflow(),
18+
new PhabricatorAuthManagementRecoverWorkflow(),
19+
new PhabricatorAuthManagementLDAPWorkflow(),
1920
new PhutilHelpArgumentWorkflow(),
2021
);
2122

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@
823823
'PhabricatorAuthLinkController' => 'applications/auth/controller/PhabricatorAuthLinkController.php',
824824
'PhabricatorAuthListController' => 'applications/auth/controller/config/PhabricatorAuthListController.php',
825825
'PhabricatorAuthLoginController' => 'applications/auth/controller/PhabricatorAuthLoginController.php',
826+
'PhabricatorAuthManagementLDAPWorkflow' => 'applications/auth/management/PhabricatorAuthManagementLDAPWorkflow.php',
826827
'PhabricatorAuthManagementRecoverWorkflow' => 'applications/auth/management/PhabricatorAuthManagementRecoverWorkflow.php',
827828
'PhabricatorAuthManagementWorkflow' => 'applications/auth/management/PhabricatorAuthManagementWorkflow.php',
828829
'PhabricatorAuthNewController' => 'applications/auth/controller/config/PhabricatorAuthNewController.php',
@@ -2707,6 +2708,7 @@
27072708
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
27082709
),
27092710
'PhabricatorAuthLoginController' => 'PhabricatorAuthController',
2711+
'PhabricatorAuthManagementLDAPWorkflow' => 'PhabricatorAuthManagementWorkflow',
27102712
'PhabricatorAuthManagementRecoverWorkflow' => 'PhabricatorAuthManagementWorkflow',
27112713
'PhabricatorAuthManagementWorkflow' => 'PhutilArgumentWorkflow',
27122714
'PhabricatorAuthNewController' => 'PhabricatorAuthProviderConfigController',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
final class PhabricatorAuthManagementLDAPWorkflow
4+
extends PhabricatorAuthManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$this
8+
->setName('ldap')
9+
->setExamples('**ldap**')
10+
->setSynopsis(
11+
pht('Analyze and diagnose issues with LDAP configuration.'));
12+
}
13+
14+
public function execute(PhutilArgumentParser $args) {
15+
$console = PhutilConsole::getConsole();
16+
$console->getServer()->setEnableLog(true);
17+
18+
$provider = new PhabricatorAuthProviderLDAP();
19+
if (!$provider->isEnabled()) {
20+
$console->writeOut(
21+
"%s\n",
22+
"The LDAP authentication provider is not enabled.");
23+
exit(1);
24+
}
25+
26+
if (!function_exists('ldap_connect')) {
27+
$console->writeOut(
28+
"%s\n",
29+
"The LDAP extension is not enabled.");
30+
exit(1);
31+
}
32+
33+
$adapter = $provider->getAdapter();
34+
$adapter->setConsole($console);
35+
36+
$console->writeOut("%s\n", pht('LDAP CONFIGURATION'));
37+
$adapter->printConfiguration();
38+
39+
$console->writeOut("%s\n", pht('Enter LDAP Credentials'));
40+
$username = phutil_console_prompt("LDAP Username: ");
41+
if (!strlen($username)) {
42+
throw new PhutilArgumentUsageException(
43+
pht("You must enter an LDAP username."));
44+
}
45+
46+
phutil_passthru('stty -echo');
47+
$password = phutil_console_prompt("LDAP Password: ");
48+
phutil_passthru('stty echo');
49+
50+
if (!strlen($password)) {
51+
throw new PhutilArgumentUsageException(
52+
pht("You must enter an LDAP password."));
53+
}
54+
55+
$adapter->setLoginUsername($username);
56+
$adapter->setLoginPassword(new PhutilOpaqueEnvelope($password));
57+
58+
$console->writeOut("\n");
59+
$console->writeOut("%s\n", pht('Connecting to LDAP...'));
60+
61+
$account_id = $adapter->getAccountID();
62+
if ($account_id) {
63+
$console->writeOut("%s\n", pht('Found LDAP Account: %s', $account_id));
64+
} else {
65+
$console->writeOut("%s\n", pht('Unable to find LDAP account!'));
66+
}
67+
68+
return 0;
69+
}
70+
71+
}

‎src/applications/auth/provider/PhabricatorAuthProvider.php

+27-22
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,33 @@ protected function loadOrCreateAccount($account_id) {
180180
$account->setEmail($adapter->getAccountEmail());
181181
$account->setAccountURI($adapter->getAccountURI());
182182

183-
try {
184-
$name = PhabricatorSlug::normalize($this->getProviderName());
185-
$name = $name.'-profile.jpg';
186-
187-
// TODO: If the image has not changed, we do not need to make a new
188-
// file entry for it, but there's no convenient way to do this with
189-
// PhabricatorFile right now. The storage will get shared, so the impact
190-
// here is negligible.
191-
192-
$image_uri = $adapter->getAccountImageURI();
193-
194-
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
195-
$image_file = PhabricatorFile::newFromFileDownload(
196-
$image_uri,
197-
array(
198-
'name' => $name,
199-
));
200-
unset($unguarded);
201-
202-
$account->setProfileImagePHID($image_file->getPHID());
203-
} catch (Exception $ex) {
204-
$account->setProfileImagePHID(null);
183+
$account->setProfileImagePHID(null);
184+
$image_uri = $adapter->getAccountImageURI();
185+
if ($image_uri) {
186+
try {
187+
$name = PhabricatorSlug::normalize($this->getProviderName());
188+
$name = $name.'-profile.jpg';
189+
190+
// TODO: If the image has not changed, we do not need to make a new
191+
// file entry for it, but there's no convenient way to do this with
192+
// PhabricatorFile right now. The storage will get shared, so the impact
193+
// here is negligible.
194+
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
195+
$image_file = PhabricatorFile::newFromFileDownload(
196+
$image_uri,
197+
array(
198+
'name' => $name,
199+
));
200+
unset($unguarded);
201+
202+
if ($image_file) {
203+
$account->setProfileImagePHID($image_file->getPHID());
204+
}
205+
} catch (Exception $ex) {
206+
// Log this but proceed, it's not especially important that we
207+
// be able to pull profile images.
208+
phlog($ex);
209+
}
205210
}
206211

207212
$this->willSaveAccount($account);

0 commit comments

Comments
 (0)
Failed to load comments.