Commit 11ea5411 authored by stanislav.goldmann's avatar stanislav.goldmann

Adjustments for Laravel 5.2

parent b66944a6
......@@ -2,7 +2,7 @@
"name": "krenor/ldap-auth",
"description": "Basic readonly authentication via LDAP for Laravel 5.1",
"keywords": [
"laravel 5.1.11", "laravel", "laravel auth", "laravel authentication",
"laravel 5.2", "laravel", "laravel auth", "laravel authentication",
"ldap", "ldap authentication", "active directory",
"krenor"
],
......@@ -16,7 +16,7 @@
}
],
"require": {
"laravel/framework": "~5.1.11",
"laravel/framework": "~5.2",
"php": ">=5.5.9"
},
"require-dev": {
......
......@@ -23,12 +23,12 @@ class LdapAuthServiceProvider extends ServiceProvider
public function boot()
{
// Register 'ldap' as authentication method
Auth::extend('ldap', function($app){
Auth::provider('ldap', function($app){
// Create new LDAP connection based on configuration files
$ldap = new Ldap( $this->getLdapConfig() );
return new LdapAuthUserProvider(
$ldap, $app['config']['auth']['model']
$ldap, $app['config']['auth']['providers']['ldap-users']['model']
);
});
}
......
......@@ -9,6 +9,7 @@ use Illuminate\Foundation\Auth\Access\Authorizable;
class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
{
use Authorizable;
/**
......@@ -18,17 +19,31 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
*/
protected $attributes;
/**
* Build an LdapUser object from the LDAP entry
*
* @param array $entry
*
* @return void
*/
public function build(array $entry)
{
$this->buildAttributesFromLdap( $entry );
$this->buildAttributesFromLdap($entry);
}
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return 'samaccountname';
}
/**
* Get the unique identifier for the user.
*
......@@ -36,9 +51,10 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
*/
public function getAuthIdentifier()
{
return $this->attributes['samaccountname'];
return $this->attributes[$this->getAuthIdentifierName()];
}
/**
* Get the password for the user.
*
......@@ -49,41 +65,47 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
// this shouldn't be needed as you cannot directly access the password
}
/**
* Get the token value for the "remember me" session.
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberToken()
public function getRememberTokenName()
{
// this shouldn't be needed as user / password is in ldap
}
/**
* Set the token value for the "remember me" session.
* Get the token value for the "remember me" session.
*
* @param string $value
* @return void
* @return string
*/
public function setRememberToken($value)
public function getRememberToken()
{
// this shouldn't be needed as user / password is in ldap
}
/**
* Get the column name for the "remember me" token.
* Set the token value for the "remember me" session.
*
* @return string
* @param string $value
*
* @return void
*/
public function getRememberTokenName()
public function setRememberToken($value)
{
// this shouldn't be needed as user / password is in ldap
}
/**
* Dynamically access the user's attributes.
*
* @param string $key
* @param string $key
*
* @return mixed
*/
public function __get($key)
......@@ -91,11 +113,13 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
return $this->attributes[$key];
}
/**
* Dynamically set an attribute on the user.
*
* @param string $key
* @param string $key
* @param mixed $value
*
* @return void
*/
public function __set($key, $value)
......@@ -103,10 +127,12 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
$this->attributes[$key] = $value;
}
/**
* Dynamically check if a value is set on the user.
*
* @param string $key
* @param string $key
*
* @return bool
*/
public function __isset($key)
......@@ -114,6 +140,7 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
return isset( $this->attributes[$key] );
}
/**
* Setting of the LdapUser attributes
*
......@@ -121,25 +148,27 @@ class LdapUser implements UserContract, AuthorizableContract, LdapUserContract
*/
private function buildAttributesFromLdap($entry)
{
$this->attributes['display_name'] = $entry['displayname'][0];
$this->attributes['display_name'] = $entry['displayname'][0];
$this->attributes['samaccountname'] = $entry['samaccountname'][0];
$this->attributes['dn'] = $entry['dn'];
$this->attributes['member_of'] = $entry['memberof'];
$this->attributes['dn'] = $entry['dn'];
$this->attributes['member_of'] = $entry['memberof'];
// Just for readability, unsetting count as we only fetch one user
unset( $this->attributes['member_of']['count'] );
}
/**
* Check if the LdapUser is a member of requested group
*
* @param string $group
*
* @return bool
*/
public function isMemberOf($group)
{
foreach($this->attributes['member_of'] as $groups) {
if( preg_match('/^CN=' . $group . '/', $groups) ) {
foreach ($this->attributes['member_of'] as $groups) {
if (preg_match('/^CN=' . $group . '/', $groups)) {
return true;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment