-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from SaschaDens/dev
- Loading branch information
Showing
14 changed files
with
346 additions
and
253 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
namespace Dsdevbe\LdapConnector\Adapter; | ||
|
||
use adLDAP\adLDAP as adLDAPService; | ||
use Dsdevbe\LdapConnector\Model\User as UserModel; | ||
|
||
class Adldap implements LdapInterface | ||
{ | ||
protected $_ldap; | ||
|
||
protected $_username; | ||
|
||
protected $_password; | ||
|
||
protected function _mapDataToUserModel($username, array $groups) | ||
{ | ||
$model = new UserModel([ | ||
'username' => $username, | ||
'password' => $this->_password, | ||
]); | ||
$model->setGroups($groups); | ||
return $model; | ||
} | ||
|
||
public function __construct($config) | ||
{ | ||
$this->_ldap = new adLDAPService($config); | ||
} | ||
|
||
/** | ||
* @param String $username | ||
* @param String $password | ||
* @return bool | ||
*/ | ||
public function connect($username, $password) | ||
{ | ||
$this->_username = $username; | ||
$this->_password = $password; | ||
|
||
return $this->_ldap->authenticate($username, $password); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isConnected() | ||
{ | ||
return !!$this->_ldap->getLdapBind(); | ||
} | ||
|
||
/** | ||
* @param String $username | ||
* @return UserModel | ||
*/ | ||
public function getUserInfo($username) | ||
{ | ||
$user = $this->_ldap->user()->info($username); | ||
|
||
if (!$user) { | ||
return null; | ||
} | ||
|
||
$groups = $this->_ldap->user()->groups($username); | ||
return $this->_mapDataToUserModel($username, $groups); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace Dsdevbe\LdapConnector\Adapter; | ||
|
||
use Dsdevbe\LdapConnector\Model\User as UserModel; | ||
|
||
interface LdapInterface | ||
{ | ||
/** | ||
* @param String $username | ||
* @param String $password | ||
* @return bool | ||
*/ | ||
public function connect($username, $password); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isConnected(); | ||
|
||
/** | ||
* @param $username | ||
* @return UserModel | ||
*/ | ||
public function getUserInfo($username); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
return array( | ||
'plugins' => array( | ||
'adldap' => array( | ||
'account_suffix'=> '@domain.local', | ||
'domain_controllers'=> array( | ||
'192.168.0.1', | ||
'dc02.domain.local' | ||
), // Load balancing domain controllers | ||
'base_dn' => 'DC=domain,DC=local', | ||
'admin_username' => 'admin', // This is required for session persistance in the application | ||
'admin_password' => 'yourPassword', | ||
), | ||
), | ||
); |
138 changes: 80 additions & 58 deletions
138
src/Dsdevbe/LdapConnector/LdapConnectorServiceProvider.php
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,84 @@ | ||
<?php namespace Dsdevbe\LdapConnector; | ||
<?php | ||
namespace Dsdevbe\LdapConnector; | ||
|
||
use Auth; | ||
use Dsdevbe\LdapConnector\Adapter\Adldap; | ||
use Illuminate\Auth\Guard; | ||
use Illuminate\Support\ServiceProvider; | ||
use Auth; | ||
use Exception; | ||
|
||
class LdapConnectorServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
Auth::extend('ldap', function($app) { | ||
$provider = new LdapUserProvider($this->getConfig()); | ||
return new Guard($provider, $app['session.store']); | ||
}); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array('auth'); | ||
} | ||
|
||
/** | ||
* Get ldap configuration | ||
* | ||
* @return array | ||
*/ | ||
public function getConfig() | ||
{ | ||
if(!$this->app['config']['ldap']) { | ||
throw new Exception('LDAP config not found. Check if app/config/ldap.php exists.'); | ||
} | ||
|
||
return $this->app['config']['ldap']; | ||
} | ||
|
||
class LdapConnectorServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
Auth::extend('ldap', function ($app) { | ||
$ldap = new Adldap( | ||
$this->getLdapAdapterConfig('adldap') | ||
); | ||
$provider = new LdapUserProvider($ldap); | ||
|
||
return new Guard($provider, $app['session.store']); | ||
}); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$ldapConfig = __DIR__ . '/Config/ldap.php'; | ||
$this->publishConfig($ldapConfig); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array('auth'); | ||
} | ||
|
||
protected function publishConfig($configPath) | ||
{ | ||
$this->publishes(array( | ||
$configPath => config_path('ldap.php') | ||
)); | ||
} | ||
|
||
/** | ||
* Get ldap configuration | ||
* | ||
* @return array | ||
*/ | ||
public function getLdapConfig() | ||
{ | ||
return $this->app['config']->get('ldap'); | ||
} | ||
|
||
/** | ||
* @param $pluginName | ||
* @return array | ||
*/ | ||
public function getLdapAdapterConfig($pluginName) | ||
{ | ||
$pluginsConfig = $this->app['config']->get('ldap.plugins'); | ||
|
||
return $pluginsConfig[$pluginName]; | ||
} | ||
} |
Oops, something went wrong.