[2.5] Using JAccess ?

161 views
Skip to first unread message

Naouak

unread,
Feb 8, 2012, 11:44:52 AM2/8/12
to joomla-de...@googlegroups.com
Hello,

I'm trying to use ACL to check wether an user have access to a page by checking a rights that is set through access.xml in administrator.

Reading the platform code, it seems that I have to use JAccess to check if an user have access to something (as the old way is depreciated).
How do I use it ? I've tried to do :
JAccess::check(JFactory::getUser()->id,"core.access")

but it always return false.

When I checked in the JAccess code, it seems that the values for ACL are never loaded. 've tried to search usage for JAccess in my Joomla installation but I cannot find usage of that class.

How am I supposed to check these access in site part (not administrator) without using deprecated functions ? (I don't want to break my code when I will switch to 3.0)

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net

Mark Dexter

unread,
Feb 8, 2012, 11:50:40 AM2/8/12
to joomla-de...@googlegroups.com
Normally we use JUser->authorise() to check a user's permission to do a task. As far as I know, this is not deprecated. Mark

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Naouak

unread,
Feb 8, 2012, 12:17:20 PM2/8/12
to joomla-de...@googlegroups.com
JUser->authorise, seems to call JAccess::check and I run into the same problem than before :
JFactory::getUser()->authorise("core.access")

always returns false.

I have " <action name="core.access" title="JACTION_ACCESS" description="JACTION_ACCESS_COMPONENT_DESC" />" in my access.xml.

And I have added var_dump(self::$assetRules); to JAccess::check function. It always return an empty array.

Am I doing anything wrong ?

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net


Mark Dexter

unread,
Feb 8, 2012, 12:23:13 PM2/8/12
to joomla-de...@googlegroups.com
Do you need to specify a second argument (@param   string  $assetname  The name of the asset on which to perform the action.)? For example, something like:

JFactory::getUser()->authorise('core.admin', 'com_config')
or
$user->authorise('core.create', 'com_banners.category.' . $categoryId)

Mark

Naouak

unread,
Feb 8, 2012, 12:27:56 PM2/8/12
to joomla-de...@googlegroups.com
Okay, I didn't understood asset as "component name" or anything like that but as "if you need to check for a specific item, it will go there".

Maybe something needs to be done there in the documentation to make it clear for developpers ? Or maybe the default value for assets need to be the component and not "1" ?

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net


mirjam k

unread,
Feb 9, 2012, 6:37:47 AM2/9/12
to joomla-de...@googlegroups.com
Is this helpfull?
http://docs.joomla.org/How_to_implement_actions_in_your_code

I posted it on the wiki after I had been struggling with how to implement permissions and tried to tie all the bits and pieces together.

With kind regards,
Mirjam


From: tar...@gmail.com
Date: Wed, 8 Feb 2012 18:27:56 +0100
Subject: Re: [jgen] [2.5] Using JAccess ?
To: joomla-de...@googlegroups.com

Mark Dexter

unread,
Feb 9, 2012, 10:45:20 AM2/9/12
to joomla-de...@googlegroups.com
Hi Mirjam. That looks really good. This is exactly how the documentation gets better -- by people seeing a need and creating a document. Thanks! Mark
Reply all
Reply to author
Forward
0 new messages