From 34eadb7f294cb4709a028cc3c473042fb595acbb Mon Sep 17 00:00:00 2001 From: Oliver Rahner Date: Wed, 8 Aug 2018 15:15:02 +0200 Subject: [PATCH 1/3] Enable `$currentUser` placeholder in restrictions implements #3493 --- library/Icinga/User.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/Icinga/User.php b/library/Icinga/User.php index c96bace1c..5374d3d9e 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -252,6 +252,10 @@ class User */ public function setRestrictions(array $restrictions) { + foreach ($restrictions as $name => $restriction) { + $restrictions[$name] = str_replace('$currentUser$', $this->getLocalUsername(), $restriction); + } + $this->restrictions = $restrictions; return $this; } From 967a0bf74e2334754d57bbcb457aa9ce59a07590 Mon Sep 17 00:00:00 2001 From: Oliver Rahner Date: Wed, 8 Aug 2018 15:24:26 +0200 Subject: [PATCH 2/3] documented $currentUser$ placeholder for restrictions --- doc/06-Security.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/06-Security.md b/doc/06-Security.md index a207d5209..64bf37685 100644 --- a/doc/06-Security.md +++ b/doc/06-Security.md @@ -214,6 +214,16 @@ results of this query instead: | +--- service_handled = 0 +#### Username placeholder + +The string `$currentUser` is replaced by the local username (without the domain part) of the logged on user while evaluating restrictions. +This can come in handy if you have some kind of attribute on host or service level defining which user is responsible for a certain host or service. + +#### Example : + +``` +monitoring/filter/objects = (__responsible=$currentUser$|__deputy=$currentUser$) +``` #### Stacking Filters From 6ad74ef1cccfda8bb462e3ececd2a625085f1740 Mon Sep 17 00:00:00 2001 From: Oliver Rahner Date: Mon, 3 Jun 2019 23:56:21 +0200 Subject: [PATCH 3/3] renamed variable $currentUser$ to $user:local_name$ updated docs, too --- doc/06-Security.md | 6 +++--- library/Icinga/User.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/06-Security.md b/doc/06-Security.md index 64bf37685..e0848f405 100644 --- a/doc/06-Security.md +++ b/doc/06-Security.md @@ -216,13 +216,13 @@ results of this query instead: #### Username placeholder -The string `$currentUser` is replaced by the local username (without the domain part) of the logged on user while evaluating restrictions. +The string `$user:local_name$` is replaced by the local username (without the domain part) of the logged on user while evaluating restrictions. This can come in handy if you have some kind of attribute on host or service level defining which user is responsible for a certain host or service. -#### Example : +**Example** ``` -monitoring/filter/objects = (__responsible=$currentUser$|__deputy=$currentUser$) +monitoring/filter/objects = (_responsible=$user:local_name$|_deputy=$user:local_name$) ``` #### Stacking Filters diff --git a/library/Icinga/User.php b/library/Icinga/User.php index 5374d3d9e..0d237831d 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -253,7 +253,7 @@ class User public function setRestrictions(array $restrictions) { foreach ($restrictions as $name => $restriction) { - $restrictions[$name] = str_replace('$currentUser$', $this->getLocalUsername(), $restriction); + $restrictions[$name] = str_replace('$user:local_name$', $this->getLocalUsername(), $restriction); } $this->restrictions = $restrictions;