public static function createConnection(array $config) { $ad = new Adldap(); $ad->addProvider('default', new Provider($config)); $ad->connect('default'); return $ad; }
/** * Constructor. * * @param Adldap $adldap */ public function __construct(Adldap $adldap) { $this->adldap = $adldap; $connection = $adldap->getConnection(); if ($connection) { $this->connection = $connection; } }
/** * Execute the console command. * * @return mixed */ public function handle() { $ad = new Adldap(); $provider = new Provider(config('adldap.proto')); $ad->addProvider('proto', $provider); $ad->connect('proto'); $this->info("Connected to LDAP server."); $this->info("Synchronizing users to LDAP."); $this->syncUsers($provider); $this->info("Synchronizing committees to LDAP."); $this->syncCommittees($provider); $this->info("Synchronizing committees members to LDAP."); $this->syncCommitteeMembers($provider); $this->info("Done!"); }
/** * Adds providers to the specified Adldap instance. * * @param Adldap $adldap * @param array $connections * * @throws \Adldap\Auth\BindException * * @return Adldap */ protected function addProviders(Adldap $adldap, array $connections = []) { // Go through each connection and construct a Provider. collect($connections)->each(function ($settings, $name) use($adldap) { // Create a new provider. $provider = $this->newProvider($settings['connection_settings'], new $settings['connection'](), new $settings['schema']()); // Try connecting to the provider if `auto_connect` is true. if (isset($settings['auto_connect']) && $settings['auto_connect'] === true) { $provider->connect(); } // Add the provider to the Adldap container. $adldap->addProvider($provider, $name); }); return $adldap; }
public function setPassword($password) { // Update Laravel Password $this->password = Hash::make($password); $this->save(); // Update Active Directory Password $ad = new Adldap(); $provider = new Provider(config('adldap.proto')); $ad->addProvider('proto', $provider); $ad->connect('proto'); $ldapuser = $provider->search()->where('objectClass', 'user')->where('description', $this->id)->first(); if ($ldapuser !== null) { $ldapuser->setPassword($password); if ($this->member) { $ldapuser->setUserAccountControl(AccountControl::NORMAL_ACCOUNT); } $ldapuser->save(); } }
/** * @param string $username * @param string $password * @param null|User $user * * @return boolean */ public function authenticate($username, $password, &$user) { if ($this->ad === null) { $this->ad = new Adldap($this->adConfig); } $authSuccess = false; if ($this->ad->authenticate($username, $password, true)) { $adUser = $this->ad->users()->find($username); $sid = \Adldap\Classes\Utilities::binarySidToText($adUser->getObjectSID()); if ($user === null and $this->hasAutoAddUser($adUser)) { $user = $this->createUserFromAd($adUser); } if ($user !== null) { if ($this->autoUpdateRole) { $this->updateRole($user, $adUser); } $user->addAuthDriver($this->getName(), $sid); $authSuccess = true; } } return $authSuccess; }
/** * Register the service provider. */ public function register() { // Bind the Adldap instance to the IoC $this->app->bind('adldap', function () { $config = $this->app['config']; $settings = $config->get('adldap'); // Verify configuration. if (is_null($settings)) { $message = 'Adldap configuration could not be found. Try re-publishing using `php artisan vendor:publish --tag="adldap"`.'; throw new ConfigurationMissingException($message); } // Create a new Adldap instance. $ad = new Adldap($settings['connection_settings'], new $settings['connection'](), $settings['auto_connect']); if ($config->get('app.debug')) { // If the application is set to debug mode, we'll display LDAP error messages. $ad->getConnection()->showErrors(); } return $ad; }); // Bind the Adldap contract to the Adldap object // in the IoC for dependency injection. $this->app->bind('Adldap\\Contracts\\Adldap', 'adldap'); }
<?php session_start(); if (!empty($_POST['username'])) { $_SESSION['username'] = strtolower($_POST['username']); } if (!empty($_POST['password'])) { $_SESSION['password'] = $_POST['password']; } require "vendor/autoload.php"; use Adldap\Adldap; $configuration = array('account_suffix' => '@winthrop.edu', 'domain_controllers' => array("rahway.winthrop.edu"), 'base_dn' => 'DC=win, DC=winthrop, DC=edu', 'real_primarygroup' => true, 'use_ssl' => false, 'recursive_groups' => true, 'ad_port' => '636', 'sso' => false); try { $ad = new Adldap($configuration); } catch (AdldapException $e) { echo "Uh oh, looks like we had an issue trying to connect: {$e}"; } $authUser = false; if (!empty($_POST['username']) && !empty($_POST['password']) && $_SESSION['username'] == "visitor") { $authUser = $ad->authenticate($_SESSION['username'], $_SESSION['password']); } if ($authUser == true) { error_reporting(0); if (!$file) { //input for the file name echo 'Please enter a valid file name: '; } //Requests a file name to send to readcsv.php echo "<form action=\"readcsv.php\" method=\"post\">\nFile Name: <input type=\"text\" name=\"file\"><br>\n<input type=\"submit\" value=\"Accept\">"; //if a file is post then open the file if (isset($_POST['file'])) {
/** * This tests that the public georgia tech LDAP server * is up and running. This is useful for making sure a notice * is placed on the readme if it's no longer active. */ public function testGeorgiaTechConnection() { $config = ['account_suffix' => "@gatech.edu", 'domain_controllers' => ["whitepages.gatech.edu"], 'base_dn' => 'dc=whitepages,dc=gatech,dc=edu', 'admin_username' => null, 'admin_password' => null]; $ad = new Adldap($config); $this->assertTrue($ad->getLdapConnection()->isBound()); }
/** * @return bool */ public function isConnectedToLdap() { return $this->_ldap->getConnection()->isBound(); }
/** * This tests that when auto-connect is false, * the connect method is not called on the current * connection until manually called. */ public function testAdldapConstructNoAutoConnect() { $connection = $this->newConnectionMock(); $differentConnection = $this->newConnectionMock(); $ad = new Adldap([], $connection, false); $differentConnection->shouldReceive('close')->once()->andReturn(true); $ad->setLdapConnection($differentConnection); }
/** * Logs the last LDAP error if it is not "Success". * * @param array $adldap The instance of the adLDAP object to check for * error. */ private function handleLDAPError(\Adldap\Adldap $adldap) { if (false != $adldap) { // May be helpful for finding out what and why went wrong. $adLDAPError = $adldap->getConnection()->getLastError(); if ("Success" != $adLDAPError) { Log::error('Problem with LDAP:' . $adLDAPError); } } }
/** * Validate a user against the given credentials. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(Authenticatable $user, array $credentials) { $username = $credentials[$this->usernameField]; return $this->adldap->authenticate($username, $credentials['password']); }
/** * Проверяем * * @param $username * @param $password * @return mixed * @throws Exception */ public static function find($username, $password) { $ad = new Adldap(self::getParams()); return $ad->authenticate($username, $password, true); }
public function postRegister(Request $request) { if (Auth::check()) { $request->session()->flash('flash_message', 'You already have an account. To register an account, please log off.'); return Redirect::route('user::dashboard'); } $request->session()->flash('register_persist', $request->all()); $this->validate($request, ['email' => 'required|email|unique:users', 'name' => 'required|string', 'calling_name' => 'required|string', 'birthdate' => 'required|date_format:Y-m-d', 'gender' => 'required|in:1,2,9', 'nationality' => 'required|string', 'phone' => 'required|regex:(\\+[0-9]{8,16})', 'g-recaptcha-response' => 'required|recaptcha']); $user = User::create($request->except('g-recaptcha-response')); if (Session::get('wizard')) { $user->wizard = true; } $user->save(); /** Add user to LDAP */ $ad = new Adldap(); $provider = new Provider(config('adldap.proto')); $ad->addProvider('proto', $provider); $ad->connect('proto'); $ldapuser = $provider->make()->user(); $ldapuser->cn = "user-" . $user->id; $ldapuser->description = $user->id; $ldapuser->save(); /** End add user to LDAP */ $email = $user->email; $name = $user->mail; Mail::queue('emails.registration', ['user' => $user], function ($m) use($email, $name) { $m->replyTo('*****@*****.**', 'Study Association Proto'); $m->to($email, $name); $m->subject('Account registration at Study Association Proto'); }); AuthController::dispatchPasswordEmailFor($user); if (!Auth::check()) { $request->session()->flash('flash_message', 'Your account has been created. You will receive an e-mail with instructions on how to set your password shortly.'); return Redirect::route('homepage'); } }