Debian Codegraph @

doc/sources/admin/exportedvars.rst

raw
1 Exported variables
2 ==================
3
4 Presentation
5 ------------
6
7 Exported variables are the variables available to
8 :doc:`write rules and headers<writingrulesand_headers>`. They are
9 extracted from the users database by the
10 :ref:`users module<start-authentication-users-and-password-databases>`.
11
12 To create a variable, you've just to map a user attributes in LL::NG
13 using ``Variables`` » ``Exported variables``. For each variable, the
14 first field is the name which will be used in rules, macros or headers
15 and the second field is the name of the user database field.
16
17 Examples for :doc:`LDAP<authldap>`:
18
19 ============= ==============
20 Variable name LDAP attribute
21 ============= ==============
22 uid uid
23 number employeeNumber
24 name sn
25 ============= ==============
26
27 You can define exported variables for each module in the module
28 configuration itself. Variables defined in the main
29 ``Exported variables`` will be used for each backend. Variables defined
30 in the exported variables node of the module will be used only for that
31 module.
32
33 |Exported variables in the Manager|
34
35
36 .. tip::
37
38 You can define environment variables in
39 ``Exported variables``, this allows one to populate user session with
40 some environment values. Environment variables will not be queried in
41 users database.
42
43 .. _macros_and_groups:
44
45 Extend variables using macros and groups
46 ----------------------------------------
47
48 Macros and groups are computed during authentication process by the
49 Portal:
50
51 - macros are used to extend (or rewrite)
52 :doc:`exported variables<exportedvars>`. A macro is stored as
53 attributes: it can contain boolean results or any string
54 - macros can also be used for importing environment variables *(these
55 variables are in CGI format)*. Example: ``$ENV{HTTP_COOKIE}``
56 - groups are stored as a string with values separated by '; '
57 (default multivalues separator) in the special attribute ``groups``: it
58 contains names of groups whose rules were returned true for the
59 current user. For example:
60
61 .. danger::
62
63 Macros can be used for rewriting or overloading exported variables
64 but it can lead to some side effects. Be aware of alphabetical order
65 and keep in mind that exported variables are set. Then macros and
66 groups are computed.
67
68 .. code-block:: perl
69
70 $groups = group3; admin
71
72 - You can also get groups in ``$hGroups`` which is a Hash Reference of
73 this form:
74
75 .. code-block:: perl
76
77 $hGroups = {
78 'group3' => {
79 'description' => [
80 'Service 3',
81 'Service 3 TEST'
82 ],
83 'cn' => [
84 'group3'
85 ],
86 'name' => 'group3'
87 },
88 'admin' => {
89 'name' => 'admin'
90 }
91 }
92
93
94 Example for macros:
95
96 .. code-block:: perl
97
98 # boolean macro
99 isAdmin -> $uid eq 'foo' or $uid eq 'bar'
100 # other macro
101 displayName -> $givenName." ".$surName
102
103 # Use a boolean macro in a rule
104 ^/admin -> $isAdmin
105 # Use a string macro in a HTTP header
106 Display-Name -> $displayName
107
108 Defining a group for admins
109
110 .. code-block:: perl
111
112 # group
113 admin -> $uid eq 'foo' or $uid eq 'bar'
114
115 Using groups in a rule
116
117 .. code-block:: perl
118
119 ^/admin -> $groups =~ /\badmin\b/
120
121 # Or with hGroups
122 ^/admin -> defined $hGroups->{'admin'}
123
124 # Since 2.0.8
125 ^/admin -> inGroup('admin')
126
127
128 .. note::
129
130 Groups are computed after macros, so a group rule may involve a
131 macro value.
132
133
134 .. warning::
135
136 Macros and groups are computed in alphanumeric order,
137 that is, in the order they are displayed in the manager. For example,
138 macro "macro1" will be computed before macro "macro2": so, expression of
139 macro2 may involve value of macro1. As same for groups: a group rule may
140 involve another, previously computed group.
141
142 In macros and access rules, you can deal with any session attribute stored in the user session.
143 Sometimes, those attributes are arrays, and you want to grab a value inside.
144 You can use them, but pay attention to treat variables in a non-ambiguous way.
145 For arrays, this means for example writing ``@{$variable}`` and not ``@$variable``.
146
147 As a more complete example, you can build a macro checking a specific LDAP objectClass in the ``$objectClass`` array reference:
148
149 .. code-block:: perl
150
151 # string macro checking a value in an array attribute
152 employeeCategory -> grep( /^customer$/, @{$objectClass} ) ? "customer" : "other"
153
154
155 .. |Exported variables in the Manager| image:: /documentation/manager-exported-variables.png
156 :class: align-center
157