JAccess

Class that handles all access authorisation routines.

since

11.1

package

Joomla.Platform

Methods

check

Method to check if a user is authorised to perform an action, optionally on an asset.

check(integer $userId, string $action, integer|string $assetKey = null, boolean $preload = true) : boolean|null
static
since

11.1

Arguments

$userId

integerId of the user for which to check authorisation.

$action

stringThe name of the action to authorise.

$assetKey

integer|stringThe asset key (asset id or asset name). null fallback to root asset.

$preload

booleanIndicates whether preloading should be used.

Response

boolean|nullTrue if allowed, false for an explicit deny, null for an implicit deny.

checkGroup

Method to check if a group is authorised to perform an action, optionally on an asset.

checkGroup(integer $groupId, string $action, integer|string $assetKey = null, boolean $preload = true) : boolean
static
since

11.1

Arguments

$groupId

integerThe path to the group for which to check authorisation.

$action

stringThe name of the action to authorise.

$assetKey

integer|stringThe asset key (asset id or asset name). null fallback to root asset.

$preload

booleanIndicates whether preloading should be used.

Response

booleanTrue if authorised.

cleanAssetKey

Method to clean the asset key to make sure we always have something.

cleanAssetKey(integer|string $assetKey = null) : integer|string
static
since

3.7.0

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name). null fallback to root asset.

Response

integer|stringAsset id or asset name.

clearStatics

Method for clearing static caches.

clearStatics() : void
static
since

11.3

getActions

Method to return a list of actions for which permissions can be set given a component and section.

getActions(string $component, string $section = 'component') : array
static deprecated
since

11.1

deprecated

12.3 (Platform) & 4.0 (CMS) Use JAccess::getActionsFromFile or JAccess::getActionsFromData instead.

Arguments

$component

stringThe component from which to retrieve the actions.

$section

stringThe name of the section within the component from which to retrieve the actions.

Response

arrayList of actions available for the given component and section.

getActionsFromData

Method to return a list of actions from a string or from an xml for which permissions can be set.

getActionsFromData(string|\SimpleXMLElement $data, string $xpath = "/access/section[@name='component']/") : boolean|array
static
since

12.1

Arguments

$data

string|\SimpleXMLElementThe XML string or an XML element.

$xpath

stringAn optional xpath to search for the fields.

Response

boolean|arrayFalse if case of error or the list of actions available.

getActionsFromFile

Method to return a list of actions from a file for which permissions can be set.

getActionsFromFile(string $file, string $xpath = "/access/section[@name='component']/") : boolean|array
static
since

12.1

Arguments

$file

stringThe path to the XML file.

$xpath

stringAn optional xpath to search for the fields.

Response

boolean|arrayFalse if case of error or the list of actions available.

getAssetAncestors

Method to recursively retrieve the list of parent Asset IDs for a particular Asset.

getAssetAncestors(string $assetType, integer $assetId) : array
static
since

1.6

Arguments

$assetType

stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').

$assetId

integerThe numeric asset id.

Response

arrayList of ancestor ids (includes original $assetId).

getAssetId

Method to get the asset id from the asset key.

getAssetId(integer|string $assetKey) : integer
static
since

3.7.0

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name).

Response

integerThe asset id.

getAssetName

Method to get the asset name from the asset key.

getAssetName(integer|string $assetKey) : string
static
since

3.7.0

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name).

Response

stringThe asset name (ex: com_content.article.8).

getAssetRules

Method to return the JAccessRules object for an asset. The returned object can optionally hold only the rules explicitly set for the asset or the summation of all inherited rules from parent assets and explicit rules.

getAssetRules(integer|string $assetKey, boolean $recursive = false, boolean $recursiveParentAsset = true, boolean $preload = true) : \JAccessRules
static
since

11.1

note

The non preloading code will be removed in 4.0. All asset rules should use asset preloading.

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name). null fallback to root asset.

$recursive

booleanTrue to return the rules object with inherited rules.

$recursiveParentAsset

booleanTrue to calculate the rule also based on inherited component/extension rules.

$preload

booleanIndicates whether preloading should be used.

Response

\JAccessRulesJAccessRules object for the asset.

getAssetType

Method to get the asset type from the asset name.

getAssetType(integer|string $assetKey) : string
static

For top level components this returns "components": 'com_content' returns 'components'

For other types: 'com_content.article.1' returns 'com_content.article' 'com_content.category.1' returns 'com_content.category'

since

1.6

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name).

Response

stringThe asset type (ex: com_content.article).

getAuthorisedViewLevels

Method to return a list of view levels for which the user is authorised.

getAuthorisedViewLevels(integer $userId) : array
static
since

11.1

Arguments

$userId

integerId of the user for which to get the list of authorised view levels.

Response

arrayList of view levels for which the user is authorised.

getExtensionNameFromAsset

Method to get the extension name from the asset name.

getExtensionNameFromAsset(integer|string $assetKey) : string
static
since

1.6

Arguments

$assetKey

integer|stringThe asset key (asset id or asset name).

Response

stringThe extension name (ex: com_content).

getGroupPath

Gets the parent groups that a leaf group belongs to in its branch back to the root of the tree (including the leaf group id).

getGroupPath(mixed $groupId) : mixed
static
since

11.1

Arguments

$groupId

mixedAn integer or array of integers representing the identities to check.

Response

mixedTrue if allowed, false for an explicit deny, null for an implicit deny.

getGroupsByUser

Method to return a list of user groups mapped to a user. The returned list can optionally hold only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited by the user.

getGroupsByUser(integer $userId, boolean $recursive = true) : array
static
since

11.1

Arguments

$userId

integerId of the user for which to get the list of groups.

$recursive

booleanTrue to include inherited user groups.

Response

arrayList of user group ids to which the user is mapped.

getGroupTitle

Method to return the title of a user group

getGroupTitle(integer $groupId) : string
static
since

3.5

Arguments

$groupId

integerId of the group for which to get the title of.

Response

stringTthe title of the group

getUsersByGroup

Method to return a list of user Ids contained in a Group

getUsersByGroup(integer $groupId, boolean $recursive = false) : array
static
since

11.1

todo

This method should move somewhere else

Arguments

$groupId

integerThe group Id

$recursive

booleanRecursively include all child groups (optional)

Response

array

preload

Method to preload the JAccessRules object for the given asset type.

preload(integer|string|array $assetTypes = 'components', boolean $reload = false) : boolean
static
since

1.6

note

This method will return void in 4.0.

Arguments

$assetTypes

integer|string|arrayThe type or name of the asset (e.g. 'com_content.article', 'com_menus.menu.2'). Also accepts the asset id. An array of asset type or a special 'components' string to load all component assets.

$reload

booleanSet to true to reload from database.

Response

booleanTrue on success.

preloadComponents

Method to preload the JAccessRules objects for all components.

preloadComponents() : array
static

Note: This will only get the base permissions for the component. e.g. it will get 'com_content', but not 'com_content.article.1' or any more specific asset type rules.

since

1.6

Response

arrayArray of component names that were preloaded.

preloadPermissions

Method to retrieve the Asset Rule strings for this particular Asset Type and stores them for later usage in getAssetRules().

preloadPermissions(string $assetType, boolean $reload = false) : boolean
static

Stores 2 arrays: one where the list has the Asset ID as the key and a second one where the Asset Name is the key.

since

1.6

note

This function will return void in 4.0.

Arguments

$assetType

stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').

$reload

booleanReload the preloaded assets.

Response

booleanTrue

preloadPermissionsParentIdMapping

Method to retrieve the list of Asset IDs and their Parent Asset IDs and store them for later usage in getAssetRules().

preloadPermissionsParentIdMapping(string $assetType) : array
static deprecated
since

1.6

deprecated

3.7.0 No replacement. Will be removed in 4.0.

Arguments

$assetType

stringThe asset type, or the asset name, or the extension of the asset (e.g. 'com_content.article', 'com_menus.menu.2', 'com_contact').

Response

arrayList of asset ids (includes parent asset id information).

Properties

viewLevels

Array of view levels

static

Type(s)

array

assetRules

Array of rules for the asset

static

Type(s)

array

assetRulesIdentities

Array of identities for asset rules

static

Type(s)

array

assetPermissionsById

Array of permissions for an asset type (Array Key = Asset ID) Also includes the rules string for the asset

static deprecated

Type(s)

array

assetPermissionsByName

Array of permissions for an asset type (Array Key = Asset Name)

static deprecated

Type(s)

array

assetPermissionsParentIdMapping

Array of the permission parent ID mappings

static

Type(s)

array

preloadedAssetTypes

Array of asset types that have been preloaded

static

Type(s)

array

identities

Array of loaded user identities

static

Type(s)

array

userGroups

Array of user groups.

static

Type(s)

array

userGroupPaths

Array of user group paths.

static

Type(s)

array

groupsByUser

Array of cached groups by user.

static

Type(s)

array

preloadedAssets

Array of preloaded asset names and ids (key is the asset id).

static

Type(s)

array

rootAssetId

The root asset id.

static

Type(s)

integer