From 6d900d096418b97b32d0c6d911b14a815776fb16 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 2 Sep 2023 20:28:04 +1000 Subject: [PATCH] Work out which attributes are available to a DN --- app/Classes/LDAP/Attribute.php | 7 +++ app/Classes/LDAP/Schema/Base.php | 10 ++++ app/Classes/LDAP/Schema/ObjectClass.php | 76 +++++++++++++++---------- app/Ldap/Entry.php | 25 ++++++++ 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index be5f300..f3f6b73 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -120,6 +120,8 @@ class Attribute public function __get(string $key): mixed { return match ($key) { + // List all the attributes + 'attributes' => $this->attributes(), // Can this attribute have more values 'can_addvalues' => $this->schema && (! $this->schema->is_single_value) && ((! $this->max_values_count) || ($this->values->count() < $this->max_values_count)), // Schema attribute description @@ -143,6 +145,11 @@ class Attribute }; } + public function __toString(): string + { + return $this->__get('name'); + } + /** * Return the hints about this attribute, ie: RDN, Required, etc * diff --git a/app/Classes/LDAP/Schema/Base.php b/app/Classes/LDAP/Schema/Base.php index d97ef6c..bf9aee3 100644 --- a/app/Classes/LDAP/Schema/Base.php +++ b/app/Classes/LDAP/Schema/Base.php @@ -46,6 +46,16 @@ abstract class Base { } } + public function __isset(string $key): bool + { + return isset($this->{$key}); + } + + public function __toString(): string + { + return $this->name; + } + /** * @return string * @deprecated replace with $class->description diff --git a/app/Classes/LDAP/Schema/ObjectClass.php b/app/Classes/LDAP/Schema/ObjectClass.php index 285eb14..ebde877 100644 --- a/app/Classes/LDAP/Schema/ObjectClass.php +++ b/app/Classes/LDAP/Schema/ObjectClass.php @@ -200,6 +200,9 @@ final class ObjectClass extends Base { public function __get(string $key): mixed { switch ($key) { + case 'attributes': + return $this->getAllAttrs(); + case 'sup': return $this->sup_classes; @@ -216,6 +219,16 @@ final class ObjectClass extends Base { } } + /** + * Return a list of attributes that this objectClass provides + * + * @return Collection + */ + public function getAllAttrs(): Collection + { + return $this->getMustAttrs()->merge($this->getMayAttrs()); + } + /** * Adds an objectClass to the list of objectClasses that inherit * from this objectClass. @@ -229,6 +242,17 @@ final class ObjectClass extends Base { } } + /** + * Returns the array of objectClass names which inherit from this objectClass. + * + * @return Collection Names of objectClasses which inherit from this objectClass. + * @deprecated use $this->child_objectclasses + */ + public function getChildObjectClasses(): Collection + { + return $this->child_objectclasses; + } + /** * Behaves identically to addMustAttrs, but it operates on the MAY * attributes of this objectClass. @@ -397,6 +421,27 @@ final class ObjectClass extends Base { return $result; } + /** + * Gets the objectClass names from which this objectClass inherits. + * + * @return Collection An array of objectClass names (strings) + * @deprecated use $this->sup_classes; + */ + public function getSupClasses(): Collection + { + return $this->sup_classes; + } + + /** + * Gets the type of this objectClass: STRUCTURAL, ABSTRACT, or AUXILIARY. + * + * @deprecated use $this->type_name + */ + public function getType() + { + return $this->type; + } + /** * Determine if an array is listed in the may_force attrs */ @@ -492,35 +537,4 @@ final class ObjectClass extends Base { return $i; } - - /** - * Returns the array of objectClass names which inherit from this objectClass. - * - * @return Collection Names of objectClasses which inherit from this objectClass. - * @deprecated use $this->child_objectclasses - */ - public function getChildObjectClasses(): Collection - { - return $this->child_objectclasses; - } - - /** - * Gets the objectClass names from which this objectClass inherits. - * - * @return array An array of objectClass names (strings) - * @deprecated use $this->sup_classes; - */ - public function getSupClasses() { - return $this->sup_classes; - } - - /** - * Gets the type of this objectClass: STRUCTURAL, ABSTRACT, or AUXILIARY. - * - * @deprecated use $this->type_name - */ - public function getType() - { - return $this->type; - } } \ No newline at end of file diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index 18288c2..5f55bb3 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -103,6 +103,21 @@ class Entry extends Model return Crypt::encryptString($this->getDn()); } + /** + * Return a list of available attributes - as per the objectClass entry of the record + * + * @return Collection + */ + public function getAvailableAttributes(): Collection + { + $result = collect(); + + foreach ($this->objectclass as $oc) + $result = $result->merge(config('server')->schema('objectclasses',$oc)->attributes); + + return $result; + } + /** * Return a list of LDAP internal attributes * @@ -115,6 +130,16 @@ class Entry extends Model }); } + /** + * Return a list of attributes without any values + * + * @return Collection + */ + public function getMissingAttributes(): Collection + { + return $this->getAvailableAttributes()->diff($this->getVisibleAttributes()); + } + /** * Return this list of user attributes *