How to protect all admin actions in all cakePHP controllers

I am developing an application using cakePHP v 1.3 for Windows (XAMPP).

Most controllers are baked with admin routing enabled. I want to protect the admin actions of each controller with a login page. How can I do this without repeating a lot? One solution to the problem is "I check the login information for the admin_index action of each controller" and then display the login screen accordingly.
Is there a better way to do this?

Rollback of the admin url ( http: // localhost / app / admin ) points to the user_admin action of the user controller (for this, a new route.php file is created in the route)

+2


a source to share


1 answer


Use an authentication component . You can configure it for admin routes only with something like this:

// AppController::beforeFilter
function beforeFilter() {
    if (isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
        $this->Auth->deny('*');
        ...
    }
}

      



Checking only in actions is index

meaningless, it's just obscurity, not security. AuthComponent will check permissions for every single page load.

+6


a source







All Articles