dmBridge PHP API
DMCdmAuthenticationService.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00016 class DMCdmAuthenticationService extends DMAbstractAuthenticationService
00017 implements DMAuthenticationService {
00018 
00019    private $cookie_value;
00020 
00026    function authenticate(DMUser $user, $password) {
00027       // issue an HTTP request for start.exe on the cdm server using curl
00028       $uri = rtrim(DMHTTPRequest::getCurrent()->getURI()->getAbsoluteHostURI(), "/")
00029             . "/" . trim(DMConfigIni::getInstance()->getString(
00030                   "contentdm.start_exe.path"), "/");
00031       $uri = new DMURI($uri);
00032       $req = new DMHTTPRequest($uri);
00033       $req->setUsername($user->getUsername());
00034       $req->setPassword($password);
00035       $client = new DMHTTPClient($req);
00036       $response = $client->send();
00037 
00038       // authentication successful; set the cdm cookie
00039       $cookie = $response->getCookie("DMID");
00040       if ($cookie) {
00041          $this->cookie_value = $cookie;
00042          return true;
00043       }
00044       // authentication failed
00045       return false;
00046    }
00047 
00053    public function logout(DMUser $user) {
00054       parent::logout($user);
00055       // explicit domain is required when setting cookies on localhost
00056       $domain = ($_SERVER['HTTP_HOST'] != 'localhost')
00057          ? $_SERVER['HTTP_HOST'] : false;
00058       setrawcookie("DMID", false, time() - 100000, "/", $domain);
00059    }
00060 
00061    public function sendCookies() {
00062       // explicit domain is required when setting cookies on localhost
00063       $domain = ($_SERVER['HTTP_HOST'] != 'localhost')
00064          ? $_SERVER['HTTP_HOST'] : false;
00065       setrawcookie("DMID", $this->cookie_value, 0, "/", $domain);
00066    }
00067 
00068 }
 All Data Structures Functions Variables