Debian Codegraph @

doc/antora/modules/tutorials/pages/unlang_policies.adoc

raw
1 = Unlang Policies
2
3 *Goal:* Create and use policies for abstracting business logic
4
5 *Time:* 10-20 minutes
6
7 *File:*
8
9 - `etc/raddb/policy.d/*`
10
11 *`man` page:* unlang
12
13 include::partial$unlang_start.adoc[]
14
15 Look through the existing files in `etc/raddb/policy.d/*` and the rest
16 of the documentation to get a feel for the unlang syntax and the tasks
17 that policies can be used for.
18
19 The basic structure of a policy is the policy name then a set of curly
20 braces containing the body of the policy
21
22 ------------------------------------------------
23 a_policy {
24 if (User-Name =~ /@([\w.+])/) {
25 reply.Reply-Message := "Hello remote %{User-Name}"
26 }
27 }
28 ------------------------------------------------
29
30 Policies defined within `etc/raddb/policy.d/*` can be called from
31 anywhere in the server where modules can be called.
32
33 ------------------------------------------------
34 authorize {
35 ...
36 a_policy
37 ...
38 }
39 ------------------------------------------------
40
41 Create a policy `proxy_to_realm` that forwards the incoming request
42 to to a remote realm if the `User-Name` attribute ends in `@<remote realm>`.
43
44 The contents of this policy should be identical to the the 'unlang'
45 code written for the xref:unlang_splitting_strings.adoc[Splitting Strings]
46 tutorial.
47
48 Call this policy at the start of the `authorize {}` section of the
49 `etc/raddb/sites-available/default` virtual server.
50
51 All the information you need to create this policy is contained within
52 documentation pages and the examples in this exercise.
53
54 == Questions
55
56 1. What are the advantages of using the policy language over interpreted
57 language modules?
58 2. What are the main differences between a policy and a function in other
59 languages?
60
61 // Copyright (C) 2021 Network RADIUS SAS. Licenced under CC-by-NC 4.0.
62 // This documentation was developed by Network RADIUS SAS.