Joomla! Discussion Forums



It is currently Fri Nov 27, 2009 3:55 pm (All times are UTC )

 




Post new topic Reply to topic  [ 7 posts ] 
Author Message
Posted: Fri Nov 06, 2009 5:00 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Apr 30, 2009 6:21 pm
Posts: 78
I must be missing something here. I know 1.6 will solve this but I need to implement this little security check now.

Below code works as expected, any authors can perform edit task in com_mycomponent.
Code:
// Setup permissions
$acl   = & JFactory::getACL();
$acl->addACL( 'com_mycomponent', 'edit', 'users', 'author');

// Authorize user
$user =& JFactory::getUser();
$access = new stdClass();
$access->canEditOwn = $user->authorize('com_mycomponent', 'edit');


The below code does not work as expected. All authors are still allowed to perform edit task in com_mycomponent instead of the specific user.
Code:
// Setup permissions
$acl   = & JFactory::getACL();
$acl->addACL( 'com_mycomponent', 'edit', 'users', 'author','mycomponent','own' );

// Authorize user
$user =& JFactory::getUser();
$access = new stdClass();
$access->canEditOwn = $user->authorize('com_mycomponent', 'edit', 'mycomponent', 'own');


I have scoured a good deal of core files but still cannot see how this works for com_content but not mycomponent. I know the created_by field exists for com_content but I don't see where this check is performed when authorizing a user. My component currently does not have a way of identifying who created it so how is this implemented?

Thanks.

_________________
Site: http://billengle.info


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 7:15 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Apr 30, 2009 6:21 pm
Posts: 78
If it helps mycomponent follows the same security model as com_content. Basically if someone authors an article (com_content) then they have edit access to the related mycomponent piece.

I have tried
Code:
$acl->addACL( 'com_mycomponent', 'edit', 'users', 'author','content','own' );


thinking it would use the same logic but no.

Anyone?

_________________
Site: http://billengle.info


Top
  E-mail  
 
Posted: Tue Nov 10, 2009 1:13 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7695
Location: Europe
Would you not use something like this, if it is about the articles:

Code:
$access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');


Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Tue Nov 10, 2009 4:31 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Apr 30, 2009 6:21 pm
Posts: 78
ooffick wrote:
Would you not use something like this, if it is about the articles:

Code:
$access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');


Olaf


Thanks for the response.

I tried that but the problem is the component I am accessing is not com_content it is com_mycomponent. This custom component is linked back to an article and has the same security structure; however, the data presented by com_mycomponent must be separate from com_content.

Any thoughts as to where the last two parameters are checked? I dug all the way down to acl_check() function in JAuthorization class but I do not see how it is checking "own".

Thanks for your help.

_________________
Site: http://billengle.info


Top
  E-mail  
 
Posted: Wed Nov 11, 2009 2:15 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Apr 30, 2009 6:21 pm
Posts: 78
Still not sure what com_content is doing to enforce this.

Instead I came up with a workaround which will do for now.

Code:
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$sql = ' SELECT * '.
   ' FROM #__content'.
   ' WHERE id = ' . JRequest::getVar('id') .
   ' AND created_by = ' . $user->id;
$db->setQuery($sql);
$is_author = $db->loadObject();
      
if (isset($is_author)) {
   return true;
} else {
   return false;
}

_________________
Site: http://billengle.info


Top
  E-mail  
 
Posted: Wed Nov 11, 2009 2:20 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Wed Apr 15, 2009 5:33 pm
Posts: 282
Location: Fortaleza, CE
Just fix that sql to prevent damage to your tables.
You're not even filtering the article id. Replace JRequest::getVar('id') with JRequest::getInt( 'id' )

_________________
-------------------------------------------------------------------
Nailson Oliveira - http://imagineseusite.com.br/
-------------------------------------------------------------------


Top
  E-mail  
 
Posted: Wed Nov 11, 2009 3:42 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Apr 30, 2009 6:21 pm
Posts: 78
Doh. Nice catch.
nailson_imgn wrote:
Just fix that sql to prevent damage to your tables.
You're not even filtering the article id. Replace JRequest::getVar('id') with JRequest::getInt( 'id' )

_________________
Site: http://billengle.info


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

Quick reply

 



Who is online

Users browsing this forum: becyn, lpccoder, uglykidjoe and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group