Path: blob/master/src/applications/auth/management/PhabricatorAuthManagementLDAPWorkflow.php
12256 views
<?php12final class PhabricatorAuthManagementLDAPWorkflow3extends PhabricatorAuthManagementWorkflow {45protected function didConstruct() {6$this7->setName('ldap')8->setExamples('**ldap**')9->setSynopsis(10pht('Analyze and diagnose issues with LDAP configuration.'));11}1213public function execute(PhutilArgumentParser $args) {14$console = PhutilConsole::getConsole();15$console->getServer()->setEnableLog(true);1617PhabricatorLDAPAuthProvider::assertLDAPExtensionInstalled();1819$provider = PhabricatorLDAPAuthProvider::getLDAPProvider();20if (!$provider) {21$console->writeOut(22"%s\n",23pht('The LDAP authentication provider is not enabled.'));24exit(1);25}2627if (!function_exists('ldap_connect')) {28$console->writeOut(29"%s\n",30pht('The LDAP extension is not enabled.'));31exit(1);32}3334$adapter = $provider->getAdapter();3536$console->writeOut("%s\n", pht('Enter LDAP Credentials'));37$username = phutil_console_prompt(pht('LDAP Username: '));38if (!strlen($username)) {39throw new PhutilArgumentUsageException(40pht('You must enter an LDAP username.'));41}4243phutil_passthru('stty -echo');44$password = phutil_console_prompt(pht('LDAP Password: '));45phutil_passthru('stty echo');4647if (!strlen($password)) {48throw new PhutilArgumentUsageException(49pht('You must enter an LDAP password.'));50}5152$adapter->setLoginUsername($username);53$adapter->setLoginPassword(new PhutilOpaqueEnvelope($password));5455$console->writeOut("\n");56$console->writeOut("%s\n", pht('Connecting to LDAP...'));5758$account_ids = $adapter->getAccountIdentifiers();59if ($account_ids) {60$value_list = mpull($account_ids, 'getIdentifierRaw');61$value_list = implode(', ', $value_list);6263$console->writeOut("%s\n", pht('Found LDAP Account: %s', $value_list));64} else {65$console->writeOut("%s\n", pht('Unable to find LDAP account!'));66}6768return 0;69}7071}727374