Swap out adldap2/adldap2 for directorytree/ldaprecord-laravel
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace App\Classes\LDAP;
|
||||
|
||||
use Adldap\Adldap;
|
||||
use Adldap\Models\Entry;
|
||||
use App\Ldap\Entry;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Server
|
||||
@@ -42,11 +41,10 @@ class Server
|
||||
protected function getDNAttrValues(string $dn,array $attrs=['*','+'],int $deref=LDAP_DEREF_NEVER): ?Entry
|
||||
{
|
||||
try {
|
||||
return ($x=(new Adldap)
|
||||
->addProvider(config('ldap.connections.default.settings'))
|
||||
->search()
|
||||
return ($x=(new Entry)
|
||||
->query()
|
||||
->select($attrs)
|
||||
->findByDn($dn)) ? $x : NULL;
|
||||
->find($dn)) ? $x : NULL;
|
||||
|
||||
// @todo Tidy up this exception
|
||||
} catch (\Exception $e) {
|
||||
@@ -60,14 +58,13 @@ class Server
|
||||
* @param $dn
|
||||
* @return |null
|
||||
*/
|
||||
public function fetch(string $dn,array $attributes=['*'])
|
||||
public function fetch(string $dn,array $attrs=['*','+'])
|
||||
{
|
||||
try {
|
||||
return ($x=(new Adldap)
|
||||
->addProvider(config('ldap.connections.default.settings'))
|
||||
->search()
|
||||
->select($attributes)
|
||||
->findByDn($dn)) ? $x : NULL;
|
||||
return ($x=(new Entry)
|
||||
->query()
|
||||
->select($attrs)
|
||||
->find($dn)) ? $x : NULL;
|
||||
|
||||
// @todo Tidy up this exception
|
||||
} catch (\Exception $e) {
|
||||
@@ -84,11 +81,9 @@ class Server
|
||||
public function query(string $dn)
|
||||
{
|
||||
try {
|
||||
return ($x=(new Adldap)
|
||||
->addProvider(config('ldap.connections.default.settings'))
|
||||
->search()
|
||||
->setBaseDn($dn)
|
||||
//->select($attrs)
|
||||
return ($x=(new Entry)
|
||||
->query()
|
||||
->setDn($dn)
|
||||
->listing()
|
||||
->get()) ? $x : NULL;
|
||||
|
||||
|
@@ -3,9 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LdapRecord\Query\Collection;
|
||||
|
||||
use App\Classes\LDAP\Server;
|
||||
|
||||
@@ -31,6 +31,10 @@ class APIController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Collection
|
||||
*/
|
||||
public function query(Request $request): Collection
|
||||
{
|
||||
$levels = $request->query('depth',1);
|
||||
@@ -41,14 +45,12 @@ class APIController extends Controller
|
||||
->query($dn)
|
||||
->transform(function($item) {
|
||||
return [
|
||||
'title'=>$item->getDistinguishedName(),
|
||||
'item'=>Crypt::encryptString($item->getDistinguishedName()),
|
||||
'title'=>$item->getDn(),
|
||||
'item'=>Crypt::encryptString($item->getDn()),
|
||||
'icon'=>'fa-fw fas fa-sitemap',
|
||||
'lazy'=>TRUE,
|
||||
'tooltip'=>$item->getDistinguishedName(),
|
||||
'tooltip'=>$item->getDn(),
|
||||
];
|
||||
});
|
||||
|
||||
Log::debug(sprintf('%s: Query [%s] - Levels [%d]: %s',__METHOD__,$dn,$levels,serialize($x)));
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
@@ -38,6 +39,14 @@ class LoginController extends Controller
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
protected function credentials(Request $request): array
|
||||
{
|
||||
return [
|
||||
'mail' => $request->get('email'),
|
||||
'password' => $request->get('password'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Show our themed login page
|
||||
*/
|
||||
@@ -50,14 +59,4 @@ class LoginController extends Controller
|
||||
|
||||
return view('architect::auth.login')->with('login_note',$login_note);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the login username to be used by the controller.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function username()
|
||||
{
|
||||
return config('ldap_auth.identifiers.ldap.locate_users_by');
|
||||
}
|
||||
}
|
||||
|
15
app/Ldap/Entry.php
Normal file
15
app/Ldap/Entry.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ldap;
|
||||
|
||||
use LdapRecord\Models\Model;
|
||||
|
||||
class Entry extends Model
|
||||
{
|
||||
/**
|
||||
* The object classes of the LDAP model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $objectClasses = [];
|
||||
}
|
20
app/Ldap/User.php
Normal file
20
app/Ldap/User.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ldap;
|
||||
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use LdapRecord\Models\OpenLDAP\User as Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
use HasApiTokens;
|
||||
|
||||
/**
|
||||
* The object classes of the LDAP model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $objectClasses = [
|
||||
'posixAccount',
|
||||
];
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Adldap\Models\User as BaseModel;
|
||||
|
||||
class LdapUser extends BaseModel
|
||||
{
|
||||
use HasApiTokens;
|
||||
|
||||
/**
|
||||
* Get all of the user's registered OAuth clients.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function clients()
|
||||
{
|
||||
// return $this->hasMany(Passport::clientModel(), 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the access tokens for the user.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function tokens()
|
||||
{
|
||||
// return $this->hasMany(Passport::tokenModel(), 'user_id')->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current access token being used by the user.
|
||||
*
|
||||
* @return \Laravel\Passport\Token|null
|
||||
*/
|
||||
public function token()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current API token has a given scope.
|
||||
*
|
||||
* @param string $scope
|
||||
* @return bool
|
||||
*/
|
||||
public function tokenCan($scope)
|
||||
{
|
||||
return $this->accessToken ? $this->accessToken->can($scope) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new personal access token for the user.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $scopes
|
||||
*
|
||||
* @return \Laravel\Passport\PersonalAccessTokenResult
|
||||
*/
|
||||
public function createToken($name, array $scopes = [])
|
||||
{
|
||||
return Container::getInstance()->make(PersonalAccessTokenFactory::class)->make(
|
||||
$this->getKey(), $name, $scopes
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current access token for the user.
|
||||
*
|
||||
* @param \Laravel\Passport\Token $accessToken
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withAccessToken($accessToken)
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user