[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/auth/management/ -> PhabricatorAuthManagementLDAPWorkflow.php (source)

   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      PhabricatorLDAPAuthProvider::assertLDAPExtensionInstalled();
  19  
  20      $provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
  21      if (!$provider) {
  22        $console->writeOut(
  23          "%s\n",
  24          'The LDAP authentication provider is not enabled.');
  25        exit(1);
  26      }
  27  
  28      if (!function_exists('ldap_connect')) {
  29        $console->writeOut(
  30          "%s\n",
  31          'The LDAP extension is not enabled.');
  32        exit(1);
  33      }
  34  
  35      $adapter = $provider->getAdapter();
  36  
  37      $console->writeOut("%s\n", pht('Enter LDAP Credentials'));
  38      $username = phutil_console_prompt('LDAP Username: ');
  39      if (!strlen($username)) {
  40        throw new PhutilArgumentUsageException(
  41          pht('You must enter an LDAP username.'));
  42      }
  43  
  44      phutil_passthru('stty -echo');
  45      $password = phutil_console_prompt('LDAP Password: ');
  46      phutil_passthru('stty echo');
  47  
  48      if (!strlen($password)) {
  49        throw new PhutilArgumentUsageException(
  50          pht('You must enter an LDAP password.'));
  51      }
  52  
  53      $adapter->setLoginUsername($username);
  54      $adapter->setLoginPassword(new PhutilOpaqueEnvelope($password));
  55  
  56      $console->writeOut("\n");
  57      $console->writeOut("%s\n", pht('Connecting to LDAP...'));
  58  
  59      $account_id = $adapter->getAccountID();
  60      if ($account_id) {
  61        $console->writeOut("%s\n", pht('Found LDAP Account: %s', $account_id));
  62      } else {
  63        $console->writeOut("%s\n", pht('Unable to find LDAP account!'));
  64      }
  65  
  66      return 0;
  67    }
  68  
  69  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1