From 87eb9193e567d86d907f758f4bf6775a1f1c55f5 Mon Sep 17 00:00:00 2001
From: Martin Haase <martin.haase@daasi.de>
Date: Thu, 24 Sep 2009 07:53:31 +0000
Subject: [PATCH] * Updates the timestamp evereytime the checkAccess method is
 called.

git-svn-id: https://textgridlab.org/svn/textgrid/trunk/middleware/tgauth@4272 7c539038-3410-0410-b1ec-0f2a7bf1c452
---
 .../tgExtensions/UpdateTimestamp.class.php    | 113 ++++++++++++++++++
 1 file changed, 113 insertions(+)
 create mode 100755 info.textgrid.middleware.tgauth.rbac/tgExtensions/UpdateTimestamp.class.php

diff --git a/info.textgrid.middleware.tgauth.rbac/tgExtensions/UpdateTimestamp.class.php b/info.textgrid.middleware.tgauth.rbac/tgExtensions/UpdateTimestamp.class.php
new file mode 100755
index 0000000..af73ab6
--- /dev/null
+++ b/info.textgrid.middleware.tgauth.rbac/tgExtensions/UpdateTimestamp.class.php
@@ -0,0 +1,113 @@
+<?php
+// ####################################################################
+// Version: 0.1.0
+// Autor: Markus Widmer
+// Erstellungsdatum: 16.01.2009
+// Letzte Aenderung: 16.01.2009
+
+
+
+class UpdateTimestamp extends RBACExtension {
+
+  // ## Klassenvariablen ##############################################
+
+
+
+
+  // ## Konstruktor ###################################################
+  public function __construct( $inRBAC ) {
+
+    // Let the extension do all the things
+    // we dont't want to do
+    parent::__construct( $inRBAC );
+
+  }
+
+
+
+  // ## registerEvents ################################################
+  public function registerEvents( RBAC $inRegistrar ) {
+
+    $inRegistrar->registerEventListener( "checkAccess", "finish", $this, "timestampCheckAccess" );
+
+  }
+
+
+
+
+  // ## timestampCheckAccess ##########################################
+  public function timestampCheckAccess( Context $inContext ) {
+
+    $arrParameter = $inContext->getParameters();     // The parameters of the checkAccess-function
+    $arrEntry = $inContext->getValue( "resource" );  // The resource-entry
+    $operation = $arrParameter[1];                   // Die der Funktion checkAccess uebergebene Operatio
+    $filter = "";
+
+
+    // Filter to search for the resource
+    $filter  = "(&" . $this->conf->getValue( "session", "filter" );
+    $filter .= "(" . $this->conf->getValue( "session", "namingattribute" ) . "=" . $arrParameter[0] . "))";
+
+
+    $file = fopen( "/tmp/debug.log", "a+" );
+    fwrite( $file, "Searching..." . $filter . "\n\n" );
+    fclose( $file );
+
+
+    // Search for the session
+    $arrSession = $this->conn['session']->search( $this->conf->getValue( "session", "base" ), $filter, "sub", Array( "rbacsessionchecktimestamp" ) );
+
+
+    // If the session was found send an update of the
+    // timestamp.
+    if( sizeof( $arrSession ) === 1 ) {
+
+      $arrModify['rbacsessionchecktimestamp'][] = date( "YmdHis", time() ) . "Z";
+
+      $this->conn['session']->modify( $arrSession[0]['dn'], $arrModify );
+
+    }
+
+
+    return $inContext;
+
+  }
+
+
+
+
+  // ## publicUserOperationsOnObject ##################################
+  public function publicUserOperationsOnObject( Context $inContext ) {
+
+    $arrParameter = $inContext->getParameters();             // The parameters of the userOperationsOnObject-function
+    $arrOperation = $inContext->getValue( "arrOperation" );  // The operations already allowed
+
+
+    if( !in_array( "read", $arrOperation ) ) {
+
+      $filter = "(&" . $this->conf->getValue( "resource", "filter" );
+      $filter .= "(|(" . $this->conf->getValue( "resource", "namingattribute" ) . "=" . $arrParameter[1] . ")";
+      $filter .= "  (" . $this->conf->getValue( "resource", "aliasattribute" ) . "=" . $arrParameter[1] . "))";
+      $filter .= "(tgispublic=TRUE))";
+
+
+      // Search for the resource
+      $arrResource = $this->conn['resource']->search( $this->conf->getValue( "resource", "base" ), $filter, "sub", Array( "tgispublic" ) );
+
+
+      if( sizeof( $arrResource ) > 0 ) {
+
+        $arrOperation[] = "read";
+        $inContext->setValue( "arrOperation", $arrOperation );
+
+      }
+
+    }
+
+
+    return $inContext;
+
+  }
+
+}
+?>
-- 
GitLab