views:

449

answers:

3

I have a website with a large number of admin generators to take care of an assortment of tables. Within the realm of authenticated users, I want to be able to deny access, not just to individual actions or fields, but an entire admin module.

There doesn't appear to be a global credentials parameter for generator.yml, and putting stuff in security.yml at the module level doesn't appear to have any effect.

I've browsed the generated code and looked at cache/front/dev/modules/autoFoo/actions/actions.class.php, and at preExecute() in particular, but I don't know what to do.

I suppose I have to overwrite preExecute() in my own actions.class.php file, but I'm a bit unsure about what needs to be one, e.g., when to call parent::preExecute() (if in fact I need to or not).

+1  A: 

Answering my own question, with the results of some preliminary investigations, it would appear that:

class fooActions extends autoFooActions
{
  public function preExecute() {
    if (!sfContext::getInstance()->getUser()->hasCredential('can_do_foo')) {
        $this->redirect('@homepage');
    }
    parent::preExecute();
  }
}

...will at least prevent people for hacking URLs to get at the admin function. But I am led to believe that sfContext::getInstance() is evil. Hence I'm still looking for the Right Way To Do It.

dland
it's not that evil in action/controllers :] indeed access to context or/and session is necessary there. wherever you can (and in action, you can) use $this->getContext() anyway.
gpilotino
+2  A: 

I believe you can set the credentials inside of the module level security.yml by setting the "all" value. That is, inside of <module>/config/security.yml, put:

all:
  credentials: ModuleAccess
jeremy
that's what I thought, too, except I tried 'default' as the top-level key. Neither works in any event.
dland
I just double checked, this works for me in sf 1.2.
jeremy
+1  A: 

your security.yml file in your model/config folder should look like this:

default:
  is_secure: on
  credentials: [ moduel_access ]
samsam