10.6.9. Custom User Attribute Handler Module

The custom user attribute handler module allows the administrator to set or delete custom user attributes automatically. A specific event can thus set or delete a custom user attribute without any further intervention of the administrator or helpdesk. To learn more about custom user attributes please check out Additional user attributes.

Note

This event handler can also set attributes that can’t be set or deleted manually by the administrator or the helpdesk users.

10.6.9.1. Possible Actions

10.6.9.1.1. set_custom_user_attributes

This action sets a custom user attribute on a certain event.

The action takes the options attrkey, attrvalue and user.

attrkey and attrvalue can take fixed values. The custom user attribute with the name from attrkey will then be set to the value of attrvalue.

The attrvalue may contain tags that are replaced when the event is handled. The tag {now} is replaced by the current timestamp and supports offsets like {now}+2h or {now}-30m (s, m, h, d). {current_time} is a deprecated alias for {now}. In addition, the tags provided by all notification handlers are available, for example {client_ip}, {ua_browser}, {ua_string}, {serial}, {username}, {userrealm} and {tokentype}.

The tags that describe a user ({username}, {userrealm}, {user}, {givenname} and {surname}) refer to the user the attribute is written for, which is chosen with the user option below. {serial} is the token of the event; it is empty if the event carries no token.

This allows you, for instance, to store the timestamp of a successful authentication in a custom user attribute (attrvalue = {now}) and to reference it later in a time-based policy condition (date_within_last).

With the user option, the custom user attribute can either be set for the acting, logged in user or for the user on whom the administrator is acting.

For example if a user failed to log in too many times, the event handler can automatically set the custom attribute "this user has login problems".

10.6.9.1.2. delete_custom_user_attributes

This action deletes a custom user attribute on a certain event.

This event handler action takes the options attrkey and user as described above.

For example, on token enrollment you could set a custom user attribute to "new user". On the first successful login this custom user attribute could be automatically deleted using this event handler action.

10.6.9.2. Code

This is the event handler module for custom user attributes. You can set or delete your custom attributes

class privacyidea.lib.eventhandler.customuserattributeshandler.ACTION_TYPE[source]

Allowed actions

DELETE_CUSTOM_USER_ATTRIBUTES = 'delete_custom_user_attributes'
SET_CUSTOM_USER_ATTRIBUTES = 'set_custom_user_attributes'
class privacyidea.lib.eventhandler.customuserattributeshandler.CustomUserAttributesHandler[source]

The CustomUserAttributesHandler is an EventHandler which can set/change/delete custom User-Attributes.

property actions

This method returns a dictionary of allowed actions and possible options in this handler module.

Returns:

dict with actions

property allowed_positions

This returns the allowed positions of the event handler definition.

Returns:

list of allowed positions

description = 'This eventhandler can set and delete custom_user_attributes'
do(action, options=None)[source]

This method executes the defined action in the given event.

Parameters:
  • action (str) – The action to perform

  • options (dict) – Contains the flask parameters g, attrkey and attrvalue

Returns:

identifier = 'CustomUserAttributes'
class privacyidea.lib.eventhandler.customuserattributeshandler.USER_TYPE[source]

Allowed user types

LOGGED_IN_USER = 'logged_in_user'
TOKENOWNER = 'tokenowner'