Nevermind, there was a mistake in a part of the Group class I'd have never thought of XD
On Sunday, January 13, 2013 12:15:56 PM UTC+1, Stefano Campanella wrote: > > >> > >> I'm using the datasources plugin, but it is not used in this > particular controller nor in any class that is loaded there. > > > > I was referring to the location of your User model > I'm using no plug-in then > > > > > You're describing another authorization handler > > > > http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#authorization > > > Yes I know...actually what really happens is that inside beforeFilter() > $this->Auth->isAuthorized() is called, since cake doesn't have any > support for using authorization for anonymous users I call it > explicitly. So no spreading of authorization code, it's still inside the > authorize component. yes, I know it's a strange usage of cakephp > (apparently everything I write is strange for cake xD), but I want a > system where actions can be made public or restricted to one particular > user group without changing the code, but only the db content > > > Putting a model in your $uses array makes it _available_ to be used > from where it is setup on first use - it doesn't eagerly load the model. > > Right, I didn't think of it, but for this perticular case I don't think > it can be useful. > > >> And anyway putting the class in the uses array doesn't work because > controller classes are loaded after the beforeFilter() from what I read > in the dispatcher code > > That's logically impossible since the beforeFilter is IN the > controller class. > Sorry, I meant that controller's Models are loaded after the beforeFilter. > > My code quite simple: > In AppController, after components and helpers definition I only have: > > public function beforeFilter() { > parent::beforeFilter(); > /** > * This is the easiest way I found to make Authorize work for > anonymous users too > */ > if(!$this->Auth->loggedIn() and > $this->Auth->isAuthorized(array('id'=>0),$this->request)){ > $this->Auth->allow(); > } > } > > In my Authorize Component then I have: > public function authorize($user, CakeRequest $request){ > $act=$this->action($request,':action'); > if(isset($this->controller()->permissions) && > !empty($this->controller()->permissions[$act])){ > if(empty($user) or empty($user['id'])){ > $group = ClassRegistry::init('Group'); > //Make a query to Group model > } > else{ > //Make normal logged-in User permissions check > } > } > return false; > } > > That's it. I tried commenting in and out all the lines in differen > combination and I found the problem arises as soon as > ClassRegistry::init() is called. > > -Stefano > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php?hl=en.
