Start of tree being rendered by API/AJAX calls

This commit is contained in:
Deon George
2020-08-27 22:46:07 +10:00
parent 1e3e4b2196
commit de4fa04d3b
21 changed files with 2150 additions and 862 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Classes\LDAP;
use Adldap\Adldap;
use Adldap\Models\Entry;
use Illuminate\Support\Collection;
class Server
{
@@ -15,7 +16,7 @@ class Server
* @return array array|NULL The root DN(s) of the server on success (string) or NULL if it cannot be determine.
* @todo Sort the entries, so that they are in the correct DN order.
*/
public function getBaseDN(): ?array
public function getBaseDN(): ?Collection
{
// If the base is set in the configuration file, then just return that after validating it exists.
// @todo
@@ -25,7 +26,7 @@ class Server
} else {
$result = $this->getDNAttrValues('',['namingcontexts']);
return $result ? $result->namingcontexts : NULL;
return $result ? collect($result->namingcontexts) : NULL;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use App\Classes\LDAP\Server;
class APIController extends Controller
{
/**
* Get the LDAP server BASE DNs
*
* @return array|null
*/
public function bases()
{
return (new Server())->getBaseDN()->transform(function($item) {
return [
'title'=>$item,
'item'=>base64_encode(Crypt::encryptString($item)),
//'folder'=>TRUE,
'lazy'=>TRUE,
//'key'=>0,
//'autoexpand'=>TRUE,
];
});
}
}

View File

@@ -50,4 +50,14 @@ class LoginController extends Controller
return view('adminlte::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');
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Laravel\Passport\Http\Middleware\CreateFreshApiToken;
class Kernel extends HttpKernel
{
@@ -37,6 +38,7 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],
'api' => [

81
app/LdapUser.php Normal file
View File

@@ -0,0 +1,81 @@
<?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;
}
}

14
app/Schema/Adldap.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace App\Schema;
use Adldap\Schemas\OpenLDAP;
use App\LdapUser;
class Adldap extends OpenLDAP
{
public function userModel()
{
return LdapUser::class;
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}