enrich your extensions with joomla! acl support

65
@sanderpotjer J and Beyond May 20, 2012 Enrich your extensions with Joomla! ACL support Sander Potjer

Upload: sander-potjer

Post on 10-May-2015

6.252 views

Category:

Technology


0 download

DESCRIPTION

Enrich your extensions with Joomla! ACL support during J and Beyond 2012

TRANSCRIPT

Page 1: Enrich your extensions with Joomla! ACL support

@sanderpotjer

J  and  Beyond  -­‐  May  20,  2012

Enrich your extensions with Joomla! ACL support

Sander Potjer

Page 2: Enrich your extensions with Joomla! ACL support

Sander Potjer?Twitter:@sanderpotjer

E-mail: [email protected]

Slides: http://www.slideshare.net/sanderpotjer/

Page 3: Enrich your extensions with Joomla! ACL support

Joomla! ACL

Page 4: Enrich your extensions with Joomla! ACL support

• http://www.slideshare.net/JohanJanssens/drupalcon-2005-joomla-drupal-and-you-presentation

DrupalCon, October 2005Johan Janssens

It took a while...

Page 5: Enrich your extensions with Joomla! ACL support

ACL = Access Control List

ACL?!?!

Page 6: Enrich your extensions with Joomla! ACL support

ACL = Access Control List

Access to parts of the website–e.g. menu / module visibility–“view” action

ACL?!?!

Page 7: Enrich your extensions with Joomla! ACL support

ACL = Access Control List

Access to parts of the website–e.g. menu / module visibility–“view” action

User actions on objectsexample: create / edit / edit state / delete article

ACL?!?!

Page 8: Enrich your extensions with Joomla! ACL support

ACL = Access Control List

Access to parts of the website–e.g. menu / module visibility–“view” action

User actions on objectsexample: create / edit / edit state / delete article

ACL?!?!

Page 9: Enrich your extensions with Joomla! ACL support

Joomla! 2.5 ACL Overview

Page 12: Enrich your extensions with Joomla! ACL support

•Guest is also a ‘user’

•Users can be assigned to one or multiple groups

User

Page 14: Enrich your extensions with Joomla! ACL support

Assigned to group (not to a user!)

10 Actions–Site Login–Admin Login–Offline Access (since 1.7)–Super Admin / Configure–Access Administration

Interface–Create–Delete–Edit–Edit State–Edit Own

Permissions

Page 16: Enrich your extensions with Joomla! ACL support

•Users with same permissions

• Inherited permissions from parent groups

•Unlimited nested groups

•Keep it simple! Only use nested groups if needed

Group

Page 18: Enrich your extensions with Joomla! ACL support

•What is visible for the group(article, menu, module, etc.)

•Permissions are inheritbetween Access Levels

•Even Super Users can not view content on frontend ifnot assigned

Access Level

Page 20: Enrich your extensions with Joomla! ACL support

4 possible permission settings

–Not Set

–Inherited

–Allowed

–Denied

Permissions Settings

Page 21: Enrich your extensions with Joomla! ACL support

Level 1: Global configuration –default permissions settings for actions for a group

Permission Hierarchy (levels)

Page 22: Enrich your extensions with Joomla! ACL support

Level 1: Global configuration –default permissions settings for actions for a group

Level 2: Component Options –can override the permissions of Level 1

Permission Hierarchy (levels)

Page 23: Enrich your extensions with Joomla! ACL support

Level 1: Global configuration –default permissions settings for actions for a group

Level 2: Component Options –can override the permissions of Level 1

Level 3: Category –can override the permissions of Level 1 & Level 2–available for components with categories (Articles, Banners, etc...)

Permission Hierarchy (levels)

Page 24: Enrich your extensions with Joomla! ACL support

Level 1: Global configuration –default permissions settings for actions for a group

Level 2: Component Options –can override the permissions of Level 1

Level 3: Category –can override the permissions of Level 1 & Level 2–available for components with categories (Articles, Banners, etc...)

Level 4: Item –can override the permissions of Level 1 & Level 2 & Level 3–only available for article manager in Joomla core

Permission Hierarchy (levels)

Page 25: Enrich your extensions with Joomla! ACL support

Level 1: Global configuration –default permissions settings for actions for a group

Level 2: Component Options –can override the permissions of Level 1

Level 3: Category –can override the permissions of Level 1 & Level 2–available for components with categories (Articles, Banners, etc...)

Level 4: Item –can override the permissions of Level 1 & Level 2 & Level 3–only available for article manager in Joomla core

Override permissions of higher levels only works if permission setting is not ‘Denied’!

Permission Hierarchy (levels)

Page 26: Enrich your extensions with Joomla! ACL support

• http://www.theartofjoomla.com/home/5-commentary/84-introducing-the-new-permissions-in-joomla-16.html

Level 1

Level 2

Level 3

Level 4

Inheriting example for ‘Create’ Action

Page 27: Enrich your extensions with Joomla! ACL support

Database: #__assets

Page 28: Enrich your extensions with Joomla! ACL support

Database: #__assets: rules names10 Actions:–Site Login: core.login.site–Admin Login: core.login.admin–Offline Access: core.login.offline–Super Admin / Configure: core.admin–Access Administration Interface: core.manager–Create: core.create–Delete: core.delete–Edit: core.edit–Edit State: core.edit.state–Edit Own: core.edit.own

Page 29: Enrich your extensions with Joomla! ACL support

Database: #__assets: rules valuesPermissions values “Null”, ‘0’ and ‘1’ –Null: Not Set or Inherited –0: Denied–1: Allowed

Page 30: Enrich your extensions with Joomla! ACL support

Database: #__assets: rules format

{"core.login.site":{"6":1,"2":1}

Page 31: Enrich your extensions with Joomla! ACL support

Database: #__assets: name format

com_content.category.19

Page 32: Enrich your extensions with Joomla! ACL support

Database: #__assets

Page 33: Enrich your extensions with Joomla! ACL support

Joomla Basic ACL support

Page 34: Enrich your extensions with Joomla! ACL support

2 actions required

ConfigureTo configure the access settings via the 'Options' toolbar button

Access Administration InterfaceTo define which group is able to access/manage the component

Page 35: Enrich your extensions with Joomla! ACL support

18 lines of code4 steps

couple minutes

Page 36: Enrich your extensions with Joomla! ACL support

1. Add/modify config.xmlFile: administrator/components/com_foobar/config.xml

<?xml version="1.0" encoding="utf-8"?><config> <fieldset name="permissions" label="JCONFIG_PERMISSIONS_LABEL" description="JCONFIG_PERMISSIONS_DESC"> <field name="rules" type="rules" label="JCONFIG_PERMISSIONS_LABEL" filter="rules" component="com_foobar" section="component"> <action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" /> <action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" /> </field> </fieldset></config>

Page 37: Enrich your extensions with Joomla! ACL support

2. Add access checkFile: administrator/components/com_foobar/foobar.php

defined('_JEXEC') or die('Restricted access');

// Access check.if (!JFactory::getUser()->authorise('core.manage', 'com_foobar')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));}

Page 38: Enrich your extensions with Joomla! ACL support

3. Add the 'Options' toolbar buttonFile: administrator/components/com_foobar/views/foobars/view.html.php

// Options button.if (JFactory::getUser()->authorise('core.admin', 'com_foobar')) { JToolBarHelper::preferences('com_foobar');}

Page 39: Enrich your extensions with Joomla! ACL support

4. Add one language stringFile: administrator/language/en-GB/en-GB.com_foobar.ini

COM_FOOBAR_CONFIGURATION="FooBar Options"

Page 40: Enrich your extensions with Joomla! ACL support

That’s all!

Page 41: Enrich your extensions with Joomla! ACL support
Page 42: Enrich your extensions with Joomla! ACL support

Actually, basic ACL support is not optional, it should be a requirement for a “native”

Joomla 2.5 extension.

Page 43: Enrich your extensions with Joomla! ACL support

Adding custom actions

Page 44: Enrich your extensions with Joomla! ACL support

Adding custom actionsExample: administrator/components/com_foobar/access.xml

<?xml version="1.0" encoding="utf-8" ?><access component="com_helloworld">! <section name="component">! ! <action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />! ! <action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />! ! <action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />! ! <action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />! ! <action name="foobar.delete.own" title="FOOBAR_DELETE_OWN" description="FOOBAR_DELETE_OWN_DESC" />! </section>! <section name="message">! ! <action name="core.delete" title="JACTION_DELETE" description="COM_HELLOWORLD_ACCESS_DELETE_DESC" />! ! <action name="core.edit" title="JACTION_EDIT" description="COM_HELLOWORLD_ACCESS_EDIT_DESC" /> <action name="foobar.delete.own" title="FOOBAR_DELETE_OWN" description="FOOBAR_DELETE_OWN_DESC" />! </section></access>

Page 45: Enrich your extensions with Joomla! ACL support

Adding custom actionsExample: administrator/components/com_foobar/config.xml

<?xml version="1.0" encoding="utf-8"?><config>! <fieldset! ! name="greetings"! ! label="COM_FOOBAR_CONFIG_GREETING_SETTINGS_LABEL"! ! description="COM_FOOBAR_CONFIG_GREETING_SETTINGS_DESC"! >! ! <field! ! ! name="show_category"! ! ! type="radio"! ! ! label="COM_FOOBAR_HELLOWORLD_FIELD_SHOW_CATEGORY_LABEL"! ! ! description="COM_FOOBAR_HELLOWORLD_FIELD_SHOW_CATEGORY_DESC"! ! ! default="0"! ! >! ! ! <option value="0">JHIDE</option>! ! ! <option value="1">JSHOW</option>! ! </field>! </fieldset>! <fieldset! ! name="permissions"! ! label="JCONFIG_PERMISSIONS_LABEL"! ! description="JCONFIG_PERMISSIONS_DESC"! >! ! <field! ! ! name="rules"! ! ! type="rules"! ! ! label="JCONFIG_PERMISSIONS_LABEL"! ! ! class="inputbox"! ! ! validate="rules"! ! ! filter="rules"! ! ! component="com_foobar"! ! ! section="component"! ! />! </fieldset></config>

Page 46: Enrich your extensions with Joomla! ACL support

Extension X (not so good) example

Page 47: Enrich your extensions with Joomla! ACL support

Extension X (not so good) example

Page 48: Enrich your extensions with Joomla! ACL support

Extension X (not so good) example

Page 49: Enrich your extensions with Joomla! ACL support

Extension X (not so good) example

Page 50: Enrich your extensions with Joomla! ACL support

Action check

Page 51: Enrich your extensions with Joomla! ACL support

Simple action checkFile: administrator/components/com_foobar/views/foobars/view.html.php

// Options button.if (JFactory::getUser()->authorise('core.admin', 'com_foobar')) { JToolBarHelper::preferences('com_foobar');}

Page 52: Enrich your extensions with Joomla! ACL support

Multiple action checkFile: administrator/components/com_foobar/views/foobars/view.html.php

/**! * Setting the toolbar! */! protected function addToolBar() ! {! ! $canDo = FoobarHelper::getActions();! ! JToolBarHelper::title(JText::_('COM_FOOBAR_MANAGER_HELLOWORLDS'), 'foobar');! ! if ($canDo->get('core.create')) ! ! {! ! ! JToolBarHelper::addNew('foobar.add', 'JTOOLBAR_NEW');! ! }! ! if ($canDo->get('core.edit')) ! ! {! ! ! JToolBarHelper::editList('foobar.edit', 'JTOOLBAR_EDIT');! ! }! ! if (($canDo->get('core.delete')) || ($canDo->get('foobar.delete.own'))) ! ! {! ! ! JToolBarHelper::deleteList('', 'foobar.delete', 'JTOOLBAR_DELETE');! ! }! ! if ($canDo->get('core.admin')) ! ! {! ! ! JToolBarHelper::divider();! ! ! JToolBarHelper::preferences('com_foobar');! ! }! }

Page 53: Enrich your extensions with Joomla! ACL support

Multiple action checkFile: administrator/components/com_foobar/helpers/foobar.php

/**! * Get the actions! */! public static function getActions($messageId = 0)! {!! ! jimport('joomla.access.access');! ! $user ! = JFactory::getUser();! ! $result! = new JObject; ! ! if (empty($messageId)) {! ! ! $assetName = 'com_foobar';! ! }! ! else {! ! ! $assetName = 'com_foobar.message.'.(int) $messageId;! ! } ! ! $actions = JAccess::getActions('com_foobar', 'component'); ! ! foreach ($actions as $action) {! ! ! $result->set($action->name, $user->authorise($action->name, $assetName));! ! } ! ! return $result;! }

Page 54: Enrich your extensions with Joomla! ACL support

Multiple action checkFile: administrator/components/com_content/helpers/content.php

Page 55: Enrich your extensions with Joomla! ACL support

Displaying permission interface

Page 56: Enrich your extensions with Joomla! ACL support

Display permission interfaceFile: administrator/components/com_foobar/views/foobar/tmpl/edit.php

<?php if ($this->canDo->get('core.admin')): ?> <div class="width-100 fltlft"> <?php echo JHtml::_('sliders.start', 'permissions-sliders-'.$this->item->id, array('useCookie'=>1)); ?> <?php echo JHtml::_('sliders.panel', JText::_('COM_HELLOWORLD_FIELDSET_RULES'), 'access-rules'); ?> <fieldset class="panelform"> <?php echo $this->form->getLabel('rules'); ?> <?php echo $this->form->getInput('rules'); ?> </fieldset> <?php echo JHtml::_('sliders.end'); ?> </div> <?php endif; ?>

Page 57: Enrich your extensions with Joomla! ACL support

Display permission interfaceFile: administrator/components/com_foobar/views/foobar/tmpl/edit.php

Page 58: Enrich your extensions with Joomla! ACL support

Usage examples in MVC

Page 59: Enrich your extensions with Joomla! ACL support

Usage examples - ModelFile: administrator/components/com_content/models/article.php

Page 60: Enrich your extensions with Joomla! ACL support

Usage examples - ModelFile: administrator/components/com_content/models/articles.php

Page 61: Enrich your extensions with Joomla! ACL support

Usage examples - ViewFile: administrator/components/com_content/views/articles/tmpl/default.php

Page 62: Enrich your extensions with Joomla! ACL support

Usage examples - ViewFile: administrator/components/com_content/views/articles/tmpl/default.php

Page 63: Enrich your extensions with Joomla! ACL support

Usage examples - ControllerFile: administrator/components/com_content/controllers/articles.php

Page 64: Enrich your extensions with Joomla! ACL support

Be Creative!

Page 65: Enrich your extensions with Joomla! ACL support

Resources

• http://www.aclmanager.net/news/general/28-is-your-extension-really-joomla-17-ready

• http://www.aclmanager.net/news/general/31-how-to-add-basic-acl-support-to-your-extension

• http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_14

• http://docs.joomla.org/How_to_implement_actions_in_your_code• http://community.joomla.org/blogs/community/1252-16-acl.html • http://docs.joomla.org/ACL_Tutorial_for_Joomla_1.6 • http://docs.joomla.org/Access_Control_System_In_Joomla_1.6 • http://magazine.joomla.org/issues/Issue-May-2012/item/761-Joomla-ACL-

Configuring-back-end