Implemented more attribute classes
This commit is contained in:
@@ -14,7 +14,7 @@ class Attribute
|
||||
// Attribute Name
|
||||
protected string $name;
|
||||
|
||||
protected ?AttributeType $schema;
|
||||
protected ?AttributeType $schema = NULL;
|
||||
|
||||
/*
|
||||
# Source of this attribute definition
|
||||
@@ -28,7 +28,7 @@ class Attribute
|
||||
protected bool $is_deletable = FALSE;
|
||||
|
||||
// Is this attribute an internal attribute
|
||||
protected bool $is_internal;
|
||||
protected bool $is_internal = FALSE;
|
||||
|
||||
// Is this attribute the RDN?
|
||||
protected bool $is_rdn = FALSE;
|
||||
@@ -95,7 +95,9 @@ class Attribute
|
||||
$this->name = $name;
|
||||
$this->values = collect($values);
|
||||
|
||||
$this->schema = config('server')->schema('attributetypes',$name);
|
||||
// No need to load our schema for internal attributes
|
||||
if (! $this->is_internal)
|
||||
$this->schema = config('server')->schema('attributetypes',$name);
|
||||
|
||||
/*
|
||||
# Should this attribute be hidden
|
||||
|
@@ -7,6 +7,6 @@ use App\Classes\LDAP\Attribute;
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
*/
|
||||
abstract class Binary extends Attribute
|
||||
class Binary extends Attribute
|
||||
{
|
||||
}
|
@@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute\Binary;
|
||||
use App\Classes\LDAP\Attribute\Binary;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are jpeg pictures
|
||||
* Represents an JpegPhoto Attribute
|
||||
*/
|
||||
final class JpegPhoto extends Binary
|
||||
{
|
||||
|
@@ -20,13 +20,24 @@ class Factory
|
||||
* Map of attributes to appropriate class
|
||||
*/
|
||||
public const map = [
|
||||
'createtimestamp' => Internal\Timestamp::class,
|
||||
'creatorsname' => Internal\EntryDN::class,
|
||||
'entrycsn' => Internal\EntryCSN::class,
|
||||
'entrydn' => Internal\EntryDN::class,
|
||||
'entryuuid' => Internal\EntryUUID::class,
|
||||
'gidnumber' => GidNumber::class,
|
||||
'hassubordinates' => Internal\HasSubordinates::class,
|
||||
'jpegphoto' => Binary\JpegPhoto::class,
|
||||
'modifytimestamp' => Internal\Timestamp::class,
|
||||
'modifiersname' => Internal\EntryDN::class,
|
||||
'objectclass' => ObjectClass::class,
|
||||
'structuralobjectclass' => Internal\StructuralObjectClass::class,
|
||||
'subschemasubentry' => Internal\SubschemaSubentry::class,
|
||||
'supportedcontrol' => Schema\OID::class,
|
||||
'supportedextension' => Schema\OID::class,
|
||||
'supportedfeatures' => Schema\OID::class,
|
||||
'supportedsaslmechanisms' => Schema\Mechanisms::class,
|
||||
'userpassword' => Password::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
12
app/Classes/LDAP/Attribute/GidNumber.php
Normal file
12
app/Classes/LDAP/Attribute/GidNumber.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an GidNumber Attribute
|
||||
*/
|
||||
final class GidNumber extends Attribute
|
||||
{
|
||||
}
|
12
app/Classes/LDAP/Attribute/Internal/EntryCSN.php
Normal file
12
app/Classes/LDAP/Attribute/Internal/EntryCSN.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an EntryCSN Attribute
|
||||
*/
|
||||
final class EntryCSN extends Internal
|
||||
{
|
||||
}
|
12
app/Classes/LDAP/Attribute/Internal/EntryDN.php
Normal file
12
app/Classes/LDAP/Attribute/Internal/EntryDN.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an EntryDN Attribute
|
||||
*/
|
||||
final class EntryDN extends Internal
|
||||
{
|
||||
}
|
@@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute\Internal;
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
* Represents an EntryUUID Attribute
|
||||
*/
|
||||
final class EntryUUID extends Internal
|
||||
{
|
||||
|
12
app/Classes/LDAP/Attribute/Internal/HasSubordinates.php
Normal file
12
app/Classes/LDAP/Attribute/Internal/HasSubordinates.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an HasSubordinates Attribute
|
||||
*/
|
||||
final class HasSubordinates extends Internal
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an StructuralObjectClass Attribute
|
||||
*/
|
||||
final class StructuralObjectClass extends Internal
|
||||
{
|
||||
}
|
12
app/Classes/LDAP/Attribute/Internal/SubschemaSubentry.php
Normal file
12
app/Classes/LDAP/Attribute/Internal/SubschemaSubentry.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an SubschemaSubentry Attribute
|
||||
*/
|
||||
final class SubschemaSubentry extends Internal
|
||||
{
|
||||
}
|
18
app/Classes/LDAP/Attribute/Internal/Timestamp.php
Normal file
18
app/Classes/LDAP/Attribute/Internal/Timestamp.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Classes\LDAP\Attribute\Internal;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are timestamps
|
||||
*/
|
||||
final class Timestamp extends Internal
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return Carbon::createFromTimestamp(strtotime($this->values[0]))->format(config('ldap.datetime_format','Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute;
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are jpeg pictures
|
||||
* Represents an ObjectClass Attribute
|
||||
*/
|
||||
final class ObjectClass extends Attribute
|
||||
{
|
||||
|
17
app/Classes/LDAP/Attribute/Password.php
Normal file
17
app/Classes/LDAP/Attribute/Password.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\LDAP\Attribute;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are passwords
|
||||
*/
|
||||
class Password extends Attribute
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return str_repeat('*',10)
|
||||
.sprintf('<br><span class="btn btn-sm btn-outline-dark"><i class="fas fa-user-check"></i> %s</span>',__('Check Password'));
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute\Schema;
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
* Represents a Mechanisms Attribute
|
||||
*/
|
||||
final class Mechanisms extends Schema
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@ namespace App\Classes\LDAP\Attribute\Schema;
|
||||
use App\Classes\LDAP\Attribute\Schema;
|
||||
|
||||
/**
|
||||
* Represents an attribute whose values are binary
|
||||
* Represents an OID Attribute
|
||||
*/
|
||||
final class OID extends Schema
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use LdapRecord\Models\Model;
|
||||
|
||||
use App\Classes\LDAP\Attribute;
|
||||
use App\Classes\LDAP\Attribute\Factory;
|
||||
|
||||
class Entry extends Model
|
||||
@@ -14,48 +15,54 @@ class Entry extends Model
|
||||
|
||||
public function getAttributes(): array
|
||||
{
|
||||
$result = collect();
|
||||
static $result = NULL;
|
||||
|
||||
foreach (parent::getAttributes() as $attribute => $value) {
|
||||
$o = Factory::create($attribute,$value);
|
||||
if (is_null($result)) {
|
||||
$result = collect();
|
||||
|
||||
// Set the rdn flag
|
||||
if (preg_match('/^'.$attribute.'=/i',$this->dn))
|
||||
$o->setRDN();
|
||||
foreach (parent::getAttributes() as $attribute => $value) {
|
||||
$o = Factory::create($attribute,$value);
|
||||
|
||||
// Set required flag
|
||||
$o->required_by(collect($this->getAttribute('objectclass')));
|
||||
// Set the rdn flag
|
||||
if (preg_match('/^'.$attribute.'=/i',$this->dn))
|
||||
$o->setRDN();
|
||||
|
||||
$result->put($attribute,$o);
|
||||
// Set required flag
|
||||
$o->required_by(collect($this->getAttribute('objectclass')));
|
||||
|
||||
$result->put($attribute,$o);
|
||||
}
|
||||
|
||||
$sort = collect(config('ldap.attr_display_order',[]))->transform(function($item) { return strtolower($item); });
|
||||
|
||||
// Order the attributes
|
||||
$result = $result->sortBy([function(Attribute $a,Attribute $b) use ($sort): int {
|
||||
if ($a === $b)
|
||||
return 0;
|
||||
|
||||
// Check if $a/$b are in the configuration to be sorted first, if so get it's key
|
||||
$a_key = $sort->search($a->name_lc);
|
||||
$b_key = $sort->search($b->name_lc);
|
||||
|
||||
// If the keys were not in the sort list, set the key to be the count of elements (ie: so it is last to be sorted)
|
||||
if ($a_key === FALSE)
|
||||
$a_key = $sort->count()+1;
|
||||
|
||||
if ($b_key === FALSE)
|
||||
$b_key = $sort->count()+1;
|
||||
|
||||
// Case where neither $a, nor $b are in ldap.attr_display_order, $a_key = $b_key = one greater than num elements.
|
||||
// So we sort them alphabetically
|
||||
if ($a_key === $b_key)
|
||||
return strcasecmp($a->name,$b->name);
|
||||
|
||||
// Case where at least one attribute or its friendly name is in $attrs_display_order
|
||||
// return -1 if $a before $b in $attrs_display_order
|
||||
return ($a_key < $b_key) ? -1 : 1;
|
||||
} ])->toArray();
|
||||
}
|
||||
|
||||
$sort = collect(config('ldap.attr_display_order',[]))->transform(function($item) { return strtolower($item); });
|
||||
|
||||
// Order the attributes
|
||||
return $result->sortBy([function($a,$b) use ($sort) {
|
||||
if (! $sort->count() || $a === $b)
|
||||
return 0;
|
||||
|
||||
// Check if $a/$b are in the configuration to be sorted first, if so get it's key
|
||||
$a_key = $sort->search($a->name_lc);
|
||||
$b_key = $sort->search($b->name_lc);
|
||||
|
||||
// If the keys were not in the sort list, set the key to be the count of elements (ie: so it is last to be sorted)
|
||||
if ($a_key === FALSE)
|
||||
$a_key = $sort->count()+1;
|
||||
|
||||
if ($b_key === FALSE)
|
||||
$b_key = $sort->count()+1;
|
||||
|
||||
// Case where neither $a, nor $b are in ldap.attr_display_order, $a_key = $b_key = one greater than num elements.
|
||||
// So we sort them alphabetically
|
||||
if ($a_key === $b_key)
|
||||
return strcasecmp($a->name,$b->name);
|
||||
|
||||
// Case where at least one attribute or its friendly name is in $attrs_display_order
|
||||
// return -1 if $a before $b in $attrs_display_order
|
||||
return ($a_key < $b_key) ? -1 : 1;
|
||||
} ])->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
@@ -73,6 +80,23 @@ class Entry extends Model
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Return a list of LDAP internal attributes
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getInternalAttributes(): Collection
|
||||
{
|
||||
return collect($this->getAttributes())->filter(function($item) {
|
||||
return $item->is_internal;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this list of user attributes
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getVisibleAttributes(): Collection
|
||||
{
|
||||
return collect($this->getAttributes())->filter(function($item) {
|
||||
|
Reference in New Issue
Block a user