Loading Please wait...

zHttpAuth Class Reference
[HTTP Authentication.]

Inheritance diagram for zHttpAuth:

Inheritance graph
[legend]
Collaboration diagram for zHttpAuth:

Collaboration graph
[legend]

Public Member Functions

 zHttpAuth (&$cntrl)
 attachController (&$cntrl)
 setRawCredentials ($usr, $psw)
 setCredentialsDataCon ($conName)
 setCredentialsDataCol ($tableName, $usrCol, $pswCol)
 validate ()
 noCache ()
 setRealm ($realmText)
 sendHeaders ()
 forward401 ()
 loop ()
 ifCanceled ($cancelText="UnAuthorized Access")
 isOk ()

Data Fields

 $cntrl
 $mode
 $data = array()
 $dataCon
 $cancelText = null
 $realm = null

Detailed Description

HTTP Authentication Class.

Definition at line 10 of file zHttpAuth.php.


Member Function Documentation

zHttpAuth::zHttpAuth ( &$  cntrl  ) 

Definition at line 23 of file zHttpAuth.php.

References $cntrl, and attachController().

00023                              {
00024     $this->attachController($cntrl);
00025     if(!defined('Z_HTTP_AUTH_MODE_RAW'))define('Z_HTTP_AUTH_MODE_RAW', true);
00026     if(!defined('Z_HTTP_AUTH_MODE_DB'))define('Z_HTTP_AUTH_MODE_DB', false);
00027   }

Here is the call graph for this function:

zHttpAuth::attachController ( &$  cntrl  ) 

Definition at line 28 of file zHttpAuth.php.

References $cntrl.

Referenced by zHttpAuth().

00028                                     {
00029     $this->cntrl = &$cntrl;
00030   }

zHttpAuth::setRawCredentials ( usr,
psw 
)

Set text username and Password.

Parameters:
$usr string Username in Plain text
$psw string Password in Plain text

Definition at line 36 of file zHttpAuth.php.

00036                                         {
00037     $this->mode = Z_HTTP_AUTH_MODE_RAW;
00038     $this->data = array($usr, $psw);
00039   }

zHttpAuth::setCredentialsDataCon ( conName  ) 

Set database Connection File. Used when UserName and Password are fetched from some table of some database.

Parameters:
$conName string Connection File Name.

Definition at line 45 of file zHttpAuth.php.

00045                                           {
00046     $this->mode = Z_HTTP_AUTH_MODE_DB;
00047     $this->dataCon = $conName;
00048   }

zHttpAuth::setCredentialsDataCol ( tableName,
usrCol,
pswCol 
)

Set TableName, Username Column and Password Column. Used when UserName and Password are fetched from some table of some database.

Parameters:
$tableName string TableName in which teh username and password are stored.
$userCol string Column Name that stores UserName(s)
$pswCol string Column name that stores Password(s)

Definition at line 56 of file zHttpAuth.php.

00056                                                               {
00057     $this->mode = Z_HTTP_AUTH_MODE_DB;
00058     $this->data = array($tableName, $usrCol, $pswCol);
00059   }

zHttpAuth::validate (  ) 

Validates the HTTP request. Validates the HTTP request with the given credentials

Returns:
boolean

Definition at line 65 of file zHttpAuth.php.

References load_module(), perror(), and sendHeaders().

Referenced by isOk().

00065                      {
00066     if(count($this->data) < 2){
00067       perror("<code>zigmoyd.HttpAuth.validate</code><br />Credentials are Not set");
00068       return false;
00069     }
00070     if(!isset($_SERVER['PHP_AUTH_USER'])){
00071       $this->sendHeaders();
00072     }else{
00073       switch($this->mode){
00074         case Z_HTTP_AUTH_MODE_RAW:
00075           if(count($this->data) != 2){
00076             perror("<code>zigmoyd.HttpAuth.validate</code><br />unexpected Credentials<br />Expecting UserName and Password Pair as the validation mode is set to RAW<br />But the Credentials are TableName UserCol and PswCol (like DB)");
00077             return false;
00078           }
00079           //$this->cntrl->noAutoViewRender();
00080           //$this->cntrl->noLayout();
00081           return ($_SERVER['PHP_AUTH_USER'] == $this->data[0] && $_SERVER['PHP_AUTH_PW'] == $this->data[1]);
00082         break;
00083         case Z_HTTP_AUTH_MODE_DB:
00084           if(count($this->data) != 3){
00085             perror("<code>zigmoyd.HttpAuth.validate</code><br />unexpected Credentials<br />Expecting TableName UserCol and PasswordCol as the validation mode is set to DB<br />But the Credentials are UserName and PswName (like RAW)");
00086             return false;
00087           }
00088           load_module('dbAccess');
00089           $db = new zDbAccess($this->dataCon, $this->data[0]);
00090           $db->fetch($this->data[1]);
00091           $db->fetch($this->data[2]);
00092           $db->identifyBy($this->data[1], $_SERVER['PHP_AUTH_USER']);
00093           $db->identifyBy($this->data[2], $_SERVER['PHP_AUTH_PW']);
00094           $retSet = $db->export();
00095           return(is_array($retSet) && count($retSet) >= 1);
00096         break;
00097       }
00098     }
00099   }

Here is the call graph for this function:

zHttpAuth::noCache (  ) 

sends anti Cache HTTP Headers.

For internal use only.

Definition at line 104 of file zHttpAuth.php.

00104                     {
00105     $this->cntrl->setHeader("Pragma: no-cache");
00106     $this->cntrl->setHeader("Cache-Control: no-cache, must-revalidate");
00107     $this->cntrl->setHeader("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00108   }

zHttpAuth::setRealm ( realmText  ) 

set the Realm text which will be used on Authentication.

Parameters:
$realmText string realm Text which will be used.

Definition at line 113 of file zHttpAuth.php.

00113                                {
00114     $this->realm = $realmText;
00115   }

zHttpAuth::sendHeaders (  ) 

send HTTP headers.

For internal use only.

Definition at line 120 of file zHttpAuth.php.

References forward401(), ifCanceled(), and url_segment().

Referenced by loop(), and validate().

00120                         {
00121     if(is_null($this->realm))$this->realm = '/'.implode('/', url_segment(ZIG_URL_SEGMENT_PATH));
00122     $this->cntrl->setHeader('WWW-Authenticate: Basic realm="'.$this->realm.'"');
00123     $this->cntrl->setHeader('HTTP/1.0 401 Unauthorized');
00124     if(is_null($this->cancelText))$this->ifCanceled();
00125     $this->forward401();
00126   }

Here is the call graph for this function:

zHttpAuth::forward401 (  ) 

forward 401 HTTP Error.

For internal use only.

Definition at line 131 of file zHttpAuth.php.

References zTemplate::sysNumeric().

Referenced by sendHeaders().

00131                        {
00132     exit(zTemplate::sysNumeric('401', $this->cancelText));
00133   }

Here is the call graph for this function:

zHttpAuth::loop (  ) 

Loop sending Headers.

For internal use only.

Definition at line 138 of file zHttpAuth.php.

References sendHeaders().

00138                  {
00139     $this->sendHeaders();
00140   }

Here is the call graph for this function:

zHttpAuth::ifCanceled ( cancelText = "UnAuthorized Access"  ) 

Text to show If the user cancels HTTP Authentication.

Parameters:
$cancelText string Text to show.

Definition at line 145 of file zHttpAuth.php.

References $cancelText.

Referenced by sendHeaders().

00145                                                         {
00146     $this->cancelText = $cancelText;
00147   }

zHttpAuth::isOk (  ) 

Returns boolean value if the user has provided valid credentials.

Returns:
boolean

Definition at line 152 of file zHttpAuth.php.

References validate().

00152                  {
00153     return $this->validate();
00154   }

Here is the call graph for this function:


Field Documentation

zHttpAuth::$cntrl

Definition at line 16 of file zHttpAuth.php.

Referenced by attachController(), and zHttpAuth().

zHttpAuth::$mode

Definition at line 17 of file zHttpAuth.php.

zHttpAuth::$data = array()

Definition at line 18 of file zHttpAuth.php.

zHttpAuth::$dataCon

Definition at line 19 of file zHttpAuth.php.

zHttpAuth::$cancelText = null

Definition at line 20 of file zHttpAuth.php.

Referenced by ifCanceled().

zHttpAuth::$realm = null

Definition at line 21 of file zHttpAuth.php.


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:54 2008 for zigmoyd.kdevelop by doxygen 1.5.6