Authorization

Concepts 2023-11-30 11:00

Authorization

Authorization of the access to your application's resources.

Authorization is the most important topic for every application used by several (or even many) users with different tasks, roles and (security) contexts.

Within the system authorization is done with a special access granting rule system where nearly any object and resource in the system could get an appropriate rule attached.

Where to apply

Access granting rules can be defined at several different places.

Application Definition

Within an Application Definition a section “access” could be added. This will get taken into account for every single action and data operation.

Key Value Store Collection

If there is a collection “_access” in the Key Value Store and setting “access_db” in section “sharing” of the Application Definition is “true”, then the appropriate records will get taken into account additionally for every data operation.

Key Value Store Data Records

If the data record for an operation has a section “access”, then this will get taken into account for this data record.

How to write

The access granting rules are written as an array of rule( object)s where each rule defines a condition which grants access to the appropriate resource, action and/or operation.

If there is no rule granting access, then the appropriate resource, action and/or operation is not permitted to the current authenticated user.

{
	"access": [
		{
			"scope": [
				"*"
			],
			"allow": [
				{
					"level": 7
				}
			]
		},
		{
			"scope": [
				"customers.get",
				"customers.index"
			],
			"allow": [
				{
					"level": 1,
					"group": "sales"
				}
			]
		}
	]
}

Rule

Each rule contains an array of scope( string)s and an array of condition( object)s to allow access.

Scope

A scope is given in a special syntax selecting the module, collection and/or method for the resource, action and/or operation the permission is asked for.

module:collection.methodsales:leads.get1Selects getting a record of collection leads in module sales.
module:collectionsales:leads4Selects any operation for collection leads in module sales.
:collection.method:leads.get3Selects getting a record of collection leads.
:collection:leads6Selects any operation for collection leads.
module.methodsales.index2Selects action index in module sales.
modulesales5Selects any action in module sales.
**9Selects everything.
Syntax, Examples and Priorities

Every condition( object) of a rule with a matching scope( string) within its priority is evaluated.

That means, if there are matching rules of priority 1, all of them (and only these) are taken into account.

If not, then the same for priority 2. If there are no matching rules of priority 1 and priority 2, then all rules of priority 3 will be used and so on.

If there no matching rules, permission cannot be granted.

addmoduleStandard method “add”
connectmoduleStandard method “connect”
detailsmoduleStandard method “details”
editmoduleStandard method “edit”
indexmoduleStandard method “index”
processmoduleStandard method “process”
removemoduleStandard method “remove”
updatemoduleStandard method “update”
“own action”moduleCustom method out of Application Definition
getcollectionStandard method “get”
deletecollectionStandard method “delete”
insertcollectionStandard method “insert”
updatecollectionStandard method “update”
Available methods

Please pay attention to the context ("module" or “collection”) of the above mentioned methods.

{
	"access": [
		{
			"scope": [
				"*"
			],
			"allow": [
				{
					"level": 7
				}
			]
		},
		{
			"scope": [
				"customers"
			],
			"allow": [
				{
					"level": 1,
					"group": "sales"
				}
			]
		},
		{
			"scope": [
				"customers:leads.update"
			],
			"allow": [
				{
					"level": 3,
					"group": "sales"
				}
			]
		}
	]
}

In the example above everything (using scope “*") is restricted to access level 7 (for security this is a good way to default).

All authenticated users of group “sales” are allowed to use module “customers”.

But only authenticated users of group “sales” with access level 3 are allowed to updated leads data.

Condition

The conditions are given as an array of condition( object)s. Each condition( object) describes the set of values which all have to match.

levelinteger(0..9)

The access level of the authenticated user must be higher or equal.

"$auth_level" could be used if applied on a data record to use that value from the record.

userstring

The user ID (not username) of the authenticated user.

"$user_id" could be used if applied on a data record to use that value from the record.

groupstringThe authenticated user must be member in the given group.
rolestringThe authenticated user must have assigned the given role. (Only for authentication backends with that feature enabled.)
sitestringThe appropriate condition is only validated if the current site tag is equal to the given one.
contextstring[]The authenticated user must have assigned one of the given contexts.
Available condition( object) fields

If several of the above mentioned fields are given in one condition( object), then all must match to have the condition grant access.