mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-29 12:38:12 +01:00
Summary: Depends on D21012. Ref T13493. Currently, auth adapters return a single identifier for each external account. Allow them to return more than one identifier, to better handle cases where an API changes from providing a lower-quality identifier to a higher-quality identifier. On its own, this change doesn't change any user-facing behavior. Test Plan: Linked and unlinked external accounts. Maniphest Tasks: T13493 Differential Revision: https://secure.phabricator.com/D21013
72 lines
2 KiB
PHP
72 lines
2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorAuthManagementLDAPWorkflow
|
|
extends PhabricatorAuthManagementWorkflow {
|
|
|
|
protected function didConstruct() {
|
|
$this
|
|
->setName('ldap')
|
|
->setExamples('**ldap**')
|
|
->setSynopsis(
|
|
pht('Analyze and diagnose issues with LDAP configuration.'));
|
|
}
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
$console = PhutilConsole::getConsole();
|
|
$console->getServer()->setEnableLog(true);
|
|
|
|
PhabricatorLDAPAuthProvider::assertLDAPExtensionInstalled();
|
|
|
|
$provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
|
|
if (!$provider) {
|
|
$console->writeOut(
|
|
"%s\n",
|
|
pht('The LDAP authentication provider is not enabled.'));
|
|
exit(1);
|
|
}
|
|
|
|
if (!function_exists('ldap_connect')) {
|
|
$console->writeOut(
|
|
"%s\n",
|
|
pht('The LDAP extension is not enabled.'));
|
|
exit(1);
|
|
}
|
|
|
|
$adapter = $provider->getAdapter();
|
|
|
|
$console->writeOut("%s\n", pht('Enter LDAP Credentials'));
|
|
$username = phutil_console_prompt(pht('LDAP Username: '));
|
|
if (!strlen($username)) {
|
|
throw new PhutilArgumentUsageException(
|
|
pht('You must enter an LDAP username.'));
|
|
}
|
|
|
|
phutil_passthru('stty -echo');
|
|
$password = phutil_console_prompt(pht('LDAP Password: '));
|
|
phutil_passthru('stty echo');
|
|
|
|
if (!strlen($password)) {
|
|
throw new PhutilArgumentUsageException(
|
|
pht('You must enter an LDAP password.'));
|
|
}
|
|
|
|
$adapter->setLoginUsername($username);
|
|
$adapter->setLoginPassword(new PhutilOpaqueEnvelope($password));
|
|
|
|
$console->writeOut("\n");
|
|
$console->writeOut("%s\n", pht('Connecting to LDAP...'));
|
|
|
|
$account_ids = $adapter->getAccountIdentifiers();
|
|
if ($account_ids) {
|
|
$value_list = mpull($account_ids, 'getIdentifierRaw');
|
|
$value_list = implode(', ', $value_list);
|
|
|
|
$console->writeOut("%s\n", pht('Found LDAP Account: %s', $value_list));
|
|
} else {
|
|
$console->writeOut("%s\n", pht('Unable to find LDAP account!'));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|