method beforeAction in CController, returning true to allow, false to deny, use in a base Controller (like Controller) and extend all your controllers from this base controller
beforeAction is an event triggered before any action, and you get the $action parameter to know details of the action to be executed, like its id (name)
therefore, you can use for your purposes the way you want (it will be executed before any action)