Store our DN and objectclasses in Attribute::class entries, so that we can dynamically calculate is_rdn and required objects (to be implemented)
This commit is contained in:
@@ -34,10 +34,14 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
// The schema's representation of this attribute
|
||||
protected(set) ?AttributeType $schema;
|
||||
|
||||
// The DN this object is in
|
||||
protected(set) string $dn;
|
||||
// The old values for this attribute - helps with isDirty() to determine if there is an update pending
|
||||
protected(set) Collection $values_old;
|
||||
// Current Values
|
||||
public Collection $values;
|
||||
// The other object classes of the entry that include this attribute
|
||||
protected(set) Collection $oc;
|
||||
|
||||
/*
|
||||
# Has the attribute been modified
|
||||
@@ -90,12 +94,22 @@ class Attribute implements \Countable, \ArrayAccess, \Iterator
|
||||
protected $postvalue = array();
|
||||
*/
|
||||
|
||||
public function __construct(string $name,array $values)
|
||||
/**
|
||||
* Create an Attribute
|
||||
*
|
||||
* @param string $dn DN this attribute is used in
|
||||
* @param string $name Name of the attribute
|
||||
* @param array $values Current Values
|
||||
* @param array $oc ObjectClasses that the DN has, that includes this attribute
|
||||
*/
|
||||
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
||||
{
|
||||
$this->dn = $dn;
|
||||
$this->name = $name;
|
||||
$this->values_old = collect($values);
|
||||
|
||||
$this->values = collect();
|
||||
$this->oc = collect($oc);
|
||||
$this->lang_tags = collect();
|
||||
|
||||
$this->schema = (new Server)
|
||||
|
@@ -49,15 +49,17 @@ class Factory
|
||||
/**
|
||||
* Create the new Object for an attribute
|
||||
*
|
||||
* @param string $dn
|
||||
* @param string $attribute
|
||||
* @param array $values
|
||||
* @param array $oc
|
||||
* @return Attribute
|
||||
*/
|
||||
public static function create(string $attribute,array $values): Attribute
|
||||
public static function create(string $dn,string $attribute,array $values,array $oc=[]): Attribute
|
||||
{
|
||||
$class = Arr::get(self::map,strtolower($attribute),Attribute::class);
|
||||
Log::debug(sprintf('%s:Creating LDAP Attribute [%s] as [%s]',static::LOGKEY,$attribute,$class));
|
||||
|
||||
return new $class($attribute,$values);
|
||||
return new $class($dn,$attribute,$values,$oc);
|
||||
}
|
||||
}
|
@@ -15,9 +15,17 @@ final class ObjectClass extends Attribute
|
||||
// The schema ObjectClasses for this objectclass of a DN
|
||||
protected Collection $oc_schema;
|
||||
|
||||
public function __construct(string $name,array $values)
|
||||
/**
|
||||
* Create an ObjectClass Attribute
|
||||
*
|
||||
* @param string $dn DN this attribute is used in
|
||||
* @param string $name Name of the attribute
|
||||
* @param array $values Current Values
|
||||
* @param array $oc ObjectClasses that the DN has, that includes this attribute
|
||||
*/
|
||||
public function __construct(string $dn,string $name,array $values,array $oc=[])
|
||||
{
|
||||
parent::__construct($name,$values);
|
||||
parent::__construct($dn,$name,$values,$oc);
|
||||
|
||||
$this->oc_schema = config('server')
|
||||
->schema('objectclasses')
|
||||
|
@@ -3,9 +3,9 @@
|
||||
namespace App\Classes\LDAP;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use LdapRecord\LdapRecordException;
|
||||
|
||||
use App\Exceptions\Import\GeneralException;
|
||||
use App\Exceptions\Import\ObjectExistsException;
|
||||
use App\Ldap\Entry;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,6 @@ abstract class Import
|
||||
* @param int $action
|
||||
* @return Collection
|
||||
* @throws GeneralException
|
||||
* @throws ObjectExistsException
|
||||
*/
|
||||
final protected function commit(Entry $o,int $action): Collection
|
||||
{
|
||||
@@ -57,15 +56,24 @@ abstract class Import
|
||||
try {
|
||||
$o->save();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return collect([
|
||||
'dn'=>$o->getDN(),
|
||||
'result'=>sprintf('%d: %s (%s)',
|
||||
($x=$e->getDetailedError())->getErrorCode(),
|
||||
$x->getErrorMessage(),
|
||||
$x->getDiagnosticMessage(),
|
||||
)
|
||||
]);
|
||||
} catch (LdapRecordException $e) {
|
||||
if ($e->getDetailedError())
|
||||
return collect([
|
||||
'dn'=>$o->getDN(),
|
||||
'result'=>sprintf('%d: %s (%s)',
|
||||
($x=$e->getDetailedError())->getErrorCode(),
|
||||
$x->getErrorMessage(),
|
||||
$x->getDiagnosticMessage(),
|
||||
)
|
||||
]);
|
||||
else
|
||||
return collect([
|
||||
'dn'=>$o->getDN(),
|
||||
'result'=>sprintf('%d: %s',
|
||||
$e->getCode(),
|
||||
$e->getMessage(),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
return collect(['dn'=>$o->getDN(),'result'=>__('Created')]);
|
||||
|
@@ -46,7 +46,7 @@ class LDIF extends Import
|
||||
if (! $line) {
|
||||
if (! is_null($o)) {
|
||||
// Add the last attribute;
|
||||
$o->addAttribute($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
|
||||
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
||||
|
||||
@@ -125,7 +125,7 @@ class LDIF extends Import
|
||||
Log::debug(sprintf('%s: Adding Attribute [%s] value [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
|
||||
|
||||
if ($value)
|
||||
$o->addAttribute($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
else
|
||||
throw new GeneralException(sprintf('Attribute has no value [%s] (line %d)',$attribute,$c));
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class LDIF extends Import
|
||||
// We may still have a pending action
|
||||
if ($action) {
|
||||
// Add the last attribute;
|
||||
$o->addAttribute($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||
|
||||
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
||||
|
||||
|
Reference in New Issue
Block a user