Class TAuthManager

Description

TAuthManager class

TAuthManager performs user authentication and authorization for a Prado application. TAuthManager works together with a IUserManager module that can be specified via the UserManager property. If an authorization fails, TAuthManager will try to redirect the client browser to a login page that is specified via the LoginPage. To login or logout a user, call login or logout, respectively.

The AuthExpire property can be used to define the time in seconds after which the authentication should expire. AllowAutoLogin specifies if the login information should be stored in a cookie to perform automatic login. Enabling this feature will cause that AuthExpire has no effect since the user will be logged in again on authentication expiration.

To load TAuthManager, configure it in application configuration as follows, <module id="auth" class="System.Security.TAuthManager" UserManager="users" LoginPage="login" /> <module id="users" class="System.Security.TUserManager" />

  • since: 3.0
  • version: $Id: TAuthManager.php 2526 2008-10-15 11:03:36Z mikl $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Security/TAuthManager.php (line 44)

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --TAuthManager
Class Constant Summary
 RETURN_URL_VAR = 'ReturnUrl'
Method Summary
void doAuthentication (mixed $sender, mixed $param)
void doAuthorization (mixed $sender, mixed $param)
string generateUserKey ()
boolean getAllowAutoLogin ()
integer getAuthExpire ()
string getLoginPage ()
string getReturnUrl ()
string getUserKey ()
void init (TXmlElement $config)
void leave (mixed $sender, mixed $param)
boolean login (string $username, string $password, integer $expire)
void logout ()
void onAuthenticate (mixed $param)
void onAuthExpire (mixed $param)
void onAuthorize (mixed $param)
void setAllowAutoLogin (boolean $value)
void setAuthExpire (integer $value)
void setLoginPage (string $pagePath)
void setReturnUrl (string $value)
void setReturnUrlVarName (string $value)
void setUserManager (string|IUserManager $provider)
boolean switchUser (string $username)
void updateSessionUser (IUser $user)
Methods
doAuthentication (line 157)

Performs authentication.

This is the event handler attached to application's Authentication event. Do not call this method directly.

  • access: public
void doAuthentication (mixed $sender, mixed $param)
  • mixed $sender: sender of the Authentication event
  • mixed $param: event parameter
doAuthorization (line 173)

Performs authorization.

This is the event handler attached to application's Authorization event. Do not call this method directly.

  • access: public
void doAuthorization (mixed $sender, mixed $param)
  • mixed $sender: sender of the Authorization event
  • mixed $param: event parameter
generateUserKey (line 371)
  • return: a key used to store user information in session
  • access: protected
  • since: 3.1.1
string generateUserKey ()
getAllowAutoLogin (line 241)
  • return: whether to allow remembering login so that the user logs on automatically next time. Defaults to false.
  • access: public
  • since: 3.1.1
boolean getAllowAutoLogin ()
getAuthExpire (line 259)
  • return: authentication expiration time in seconds. Defaults to zero (no expiration).
  • access: public
  • since: 3.1.3
integer getAuthExpire ()
getLoginPage (line 134)
  • return: path of login page should login is required
  • access: public
string getLoginPage ()
getReturnUrl (line 223)
  • return: URL that the browser should be redirected to when login succeeds.
  • access: public
string getReturnUrl ()
getReturnUrlVarName (line 207)
  • return: the name of the session variable storing return URL. It defaults to 'AppID:ReturnUrl'
  • access: public
string getReturnUrlVarName ()
getUserKey (line 360)
  • return: a unique variable name for storing user session/cookie data
  • access: public
  • since: 3.1.1
string getUserKey ()
getUserManager (line 113)
  • return: user manager instance
  • access: public
IUserManager getUserManager ()
init (line 89)

Initializes this module.

This method is required by the IModule interface.

  • access: public
  • throws: TConfigurationException if user manager does not exist or is not IUserManager
void init (TXmlElement $config)
  • TXmlElement $config: configuration for this module, can be null

Redefinition of:
TModule::init()
Initializes the module.
leave (line 188)

Performs login redirect if authorization fails.

This is the event handler attached to application's EndRequest event. Do not call this method directly.

  • access: public
void leave (mixed $sender, mixed $param)
  • mixed $sender: sender of the event
  • mixed $param: event parameter
login (line 416)

Logs in a user with username and password.

The username and password will be used to validate if login is successful. If yes, a user object will be created for the application.

  • return: if login is successful
  • access: public
boolean login (string $username, string $password, integer $expire)
  • string $username: username
  • string $password: password
  • integer $expire: number of seconds that automatic login will remain effective. If 0, it means user logs out when session ends. This parameter is added since 3.1.1.
logout (line 443)

Logs out a user.

User session will be destroyed after this method is called.

  • access: public
  • throws: TConfigurationException if session module is not loaded.
void logout ()
onAuthenticate (line 281)

Performs the real authentication work.

An OnAuthenticate event will be raised if there is any handler attached to it. If the application already has a non-null user, it will return without further authentication. Otherwise, user information will be restored from session data.

  • access: public
  • throws: TConfigurationException if session module does not exist.
void onAuthenticate (mixed $param)
  • mixed $param: parameter to be passed to OnAuthenticate event
onAuthExpire (line 330)

Performs user logout on authentication expiration.

An 'OnAuthExpire' event will be raised if there is any handler attached to it.

  • access: public
void onAuthExpire (mixed $param)
  • mixed $param: parameter to be passed to OnAuthExpire event.
onAuthorize (line 344)

Performs the real authorization work.

Authorization rules obtained from the application will be used to check if a user is allowed. If authorization fails, the response status code will be set as 401 and the application terminates.

  • access: public
void onAuthorize (mixed $param)
  • mixed $param: parameter to be passed to OnAuthorize event
setAllowAutoLogin (line 250)
  • access: public
  • since: 3.1.1
void setAllowAutoLogin (boolean $value)
  • boolean $value: whether to allow remembering login so that the user logs on automatically next time. Users have to enable cookie to make use of this feature.
setAuthExpire (line 268)
  • access: public
  • since: 3.1.3
void setAuthExpire (integer $value)
  • integer $value: authentication expiration time in seconds. Defaults to zero (no expiration).
setLoginPage (line 145)

Sets the login page that the client browser will be redirected to if login is needed.

Login page should be specified in the format of page path.

void setLoginPage (string $pagePath)
  • string $pagePath: path of login page should login is required
setReturnUrl (line 232)

Sets the URL that the browser should be redirected to when login succeeds.

  • access: public
void setReturnUrl (string $value)
  • string $value: the URL to be redirected to.
setReturnUrlVarName (line 215)
  • access: public
void setReturnUrlVarName (string $value)
  • string $value: the name of the session variable storing return URL.
setUserManager (line 122)
  • access: public
  • throws: TInvalidOperationException if the module has been initialized or the user manager object is not IUserManager
void setUserManager (string|IUserManager $provider)
  • string|IUserManager $provider: the user manager module ID or the user manager object
switchUser (line 398)

Switches to a new user.

This method will logout the current user first and login with a new one (without password.)

  • return: if the switch is successful
  • access: public
boolean switchUser (string $username)
  • string $username: the new username
updateSessionUser (line 381)

Updates the user data stored in session.

  • access: public
  • throws: new TConfigurationException if session module is not loaded.
void updateSessionUser (IUser $user)
  • IUser $user: user object

Inherited Methods

Inherited From TModule

TModule::getID()
TModule::init()
TModule::setID()

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()
Class Constants
RETURN_URL_VAR = 'ReturnUrl' (line 49)

GET variable name for return url

Documentation generated on Sun, 11 Jan 2009 20:17:00 -0500 by phpDocumentor 1.3.0RC4