Audit.php 3.97 KiB
<?php
class Audit implements EndpointInterface
  private TaskGateway $gateway;
  private string $errorMessage = 'No audit requiring removal';
  public function __construct (TaskGateway $gateway)
    $this->gateway = $gateway;
  /**
   * @return array
   * Part of the interface of orchestrator plugin to treat GET method
  public function processEndPointGet (): array
    return [];
  /**
   * @param array|null $data
   * @return array
  public function processEndPointPost (array $data = NULL): array
    return [];
  /**
   * @param array|NULL $data
   * @return array
  public function processEndPointDelete (array $data = NULL): array
    return [];
  /**
   * @param array|NULL $data
   * @return array
   * @throws Exception
  public function processEndPointPatch (array $data = NULL): array
    $result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit'));
    // Recursive function to filter out empty arrays at any depth
    $filteredResults = $this->recursiveArrayFilter($result);
    if (empty($filteredResults)) {
        return [$this->errorMessage];
    return $filteredResults;
  /**
   * @param array $auditSubTasks
   * @return array
   * @throws Exception
  public function processAuditDeletion (array $auditSubTasks): array
    return array_values(array_map(
        fn($task) => $this->processScheduledTask($task),
        array_filter($auditSubTasks, fn($task) => $this->gateway->statusAndScheduleCheck($task))
    ));
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
/** * @param array $task * @return array * @throws Exception */ private function processScheduledTask (array $task): array { // Retrieve data from the main task. $auditMainTask = $this->getAuditMainTask($task['fdtasksgranularmaster'][0]); // Simply get the days to retain audit. $auditRetention = $auditMainTask[0]['fdaudittasksretention'][0]; // Verification of all audit and their potential removal based on retention days passed, also update subtasks. return $this->checkAuditPassedRetention($auditRetention, $task['dn'], $task['cn'][0]); } /** * @param string $mainTaskDn * @return array * Note : Simply return attributes from the main related audit tasks. */ public function getAuditMainTask (string $mainTaskDn): array { // Retrieve data from the main task return $this->gateway->getLdapTasks('(objectClass=fdAuditTasks)', ['fdAuditTasksRetention'], '', $mainTaskDn); } /** * @param $auditRetention * @return array * Note : This will return a validation of audit log suppression * @throws Exception */ public function checkAuditPassedRetention ($auditRetention, $subTaskDN, $subTaskCN): array { $auditLib = new FusionDirectory\Audit\AuditLib($auditRetention, $this->returnLdapAuditEntries(), $this->gateway, $subTaskDN, $subTaskCN); return $auditLib->checkAuditPassedRetentionOrchestrator(); } /** * @return array * NOTE : simply return the list of audit entries existing in LDAP */ public function returnLdapAuditEntries () : array { // Search in LDAP for audit entries (All entries ! This can be pretty heavy. $audit = $this->gateway->getLdapTasks('(objectClass=fdAuditEvent)', ['fdAuditDateTime'], '', ''); // Remove the count key from the audit array. $this->gateway->unsetCountKeys($audit); return $audit; } /** * @param array $array * @return array * Note : Recursively filters out empty values and arrays at any depth. */ private function recursiveArrayFilter (array $array): array { // First filter the array for non-empty elements $filtered = array_filter($array, function ($item) { if (is_array($item)) { // Recursively filter the sub-array $item = $this->recursiveArrayFilter($item); // Only retain non-empty arrays return !empty($item); } else { // Retain non-empty scalar values return !empty($item);
141142143144145146
} }); return $filtered; } }