|
Tuesday 18 May 2010 9:10:08 am
Comment59146
No probs! The phpBIZ class is a simple container for the phpBIZ library. It provides BIZ authentication for web applications written in PHP. Here's what's inside phpBIZ::getUser();
function getUser()
{
global $PHPBIZ_CLIENT, $PHPBIZ_AUTH_CHECK_CALL;
if ( !is_object($PHPBIZ_CLIENT) ) {
phpBIZ::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
}
if ( !$PHPBIZ_AUTH_CHECK_CALL['done'] ) {
phpBIZ::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
}
if ( !$PHPBIZ_AUTH_CHECK_CALL['result'] ) {
phpBIZ::error('authentication was checked (by '.$PHPBIZ_AUTH_CHECK_CALL['method'].'() at '.$PHPBIZ_AUTH_CHECK_CALL['file'].':'.$PHPBIZ_AUTH_CHECK_CALL['line'].') but the method returned FALSE');
}
return $PHPBIZ_CLIENT->getUser();
}where $PHPBIZ_CLIENT is a global object of the 'BIZClient' class which authenticates a user in the system. It basically returns the user which is set via a call to the setUser method... which is called by isAuthenticated or wasPreviouslyAuthenticated.
/**
* This method is called to check if the user is authenticated (previously or by
* tickets given in the URL
*
* @return TRUE when the user is authenticated; otherwise halt.
*
* @public
*/
function isAuthenticated()
{
phpBIZ::traceBegin();
$res = FALSE;
$validate_url = '';
if ( $this->wasPreviouslyAuthenticated() ) {
phpBIZ::trace('The user is already authenticated.');
$res = TRUE;
}
else
{
// calls the WS with the sessID got from the url.
phpBIZ::trace('not previously authenticated');
if (isset($_GET['sessID']))
{
phpBIZ::trace('there\'s a sessID : verifying it! ');
$res = $this->checkSessionId( $_GET['sessID'] );
}
}
phpBIZ::traceEnd($res);
return $res;
}
/**
* This method tells if the user has already been (previously) authenticated
* by looking into the session variables.
*
* @return TRUE when the user has already been authenticated; FALSE otherwise.
*
* @private
*/
function wasPreviouslyAuthenticated()
{
phpBIZ::traceBegin();
$auth = FALSE;
// `simple' BIZ client (not a proxy): username must be present
if ($_SESSION['force_logout']==1)
{
phpBIZ::trace('force_logout detected: force user disconnection.');
unset($_SESSION['phpBIZ']['user']);
$auth = FALSE;
}
if ( !empty($_SESSION['phpBIZ']['user']) ) {
// authentication already done
$this->setUser($_SESSION['phpBIZ']['user']);
phpBIZ::trace('user = `'.$_SESSION['phpBIZ']['user'].'\'');
$auth = TRUE;
}
else
{
phpBIZ::trace('no user found');
}
phpBIZ::traceEnd($auth);
return $auth;
}Enjoy... ^^ Having said that, I still don't know whether it's possible to share data between extensions or not... Does someone have any clue about that?
|