From 696d87d19038e20ff67904283acd5cd46a32ba9f Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 19 Mar 2025 08:34:56 +1100 Subject: [PATCH] Improve entry validation to only require the first item of multi value attributes --- app/Classes/LDAP/Schema/AttributeType.php | 7 +++++-- config/ldap.php | 7 ------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/Classes/LDAP/Schema/AttributeType.php b/app/Classes/LDAP/Schema/AttributeType.php index 681fd73b..33af446d 100644 --- a/app/Classes/LDAP/Schema/AttributeType.php +++ b/app/Classes/LDAP/Schema/AttributeType.php @@ -557,10 +557,13 @@ final class AttributeType extends Base { ->unique(); $validation = collect(Arr::get(config('ldap.validation'),$this->name_lc,[])); + + // Add in schema required by conditions if (($heirachy->intersect($this->required_by_object_classes->keys())->count() > 0) && (! collect($validation->get($this->name_lc))->contains('required'))) { - $validation->put($this->name_lc,array_merge(['required','min:1'],$validation->get($this->name_lc,[]))) - ->put($this->name_lc.'.*',array_merge(['required','min:1'],$validation->get($this->name_lc.'.*',[]))); + $validation + ->prepend(array_merge(['required','min:1'],$validation->get($this->name_lc.'.0',[])),$this->name_lc.'.0') + ->prepend(array_merge(['required','array','min:1'],$validation->get($this->name_lc,[])),$this->name_lc); } return $validation->toArray(); diff --git a/config/ldap.php b/config/ldap.php index c41ed84e..21c2448b 100644 --- a/config/ldap.php +++ b/config/ldap.php @@ -123,16 +123,12 @@ return [ 'validation' => [ 'objectclass' => [ 'objectclass'=>[ - 'required', - 'array', - 'min:1', new HasStructuralObjectClass, ] ], 'gidnumber' => [ 'gidnumber'=> [ 'sometimes', - 'array', 'max:1' ], 'gidnumber.*' => [ @@ -144,7 +140,6 @@ return [ 'mail' => [ 'mail'=>[ 'sometimes', - 'array', 'min:1' ], 'mail.*' => [ @@ -155,7 +150,6 @@ return [ 'userpassword' => [ 'userpassword' => [ 'sometimes', - 'array', 'min:1' ], 'userpassword.*' => [ @@ -166,7 +160,6 @@ return [ 'uidnumber' => [ 'uidnumber' => [ 'sometimes', - 'array', 'max:1' ], 'uidnumber.*' => [