From d170cf0c9d3407d7725c356907f5054e0d1f5161 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 20 Oct 2014 13:42:15 +0200 Subject: [PATCH] lib: Replace Membership with IniUserGroupBackend --- .../Backend/IniUserGroupBackend.php | 65 +++++++++++++++++++ library/Icinga/Authentication/Membership.php | 39 ----------- 2 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 library/Icinga/Authentication/Backend/IniUserGroupBackend.php delete mode 100644 library/Icinga/Authentication/Membership.php diff --git a/library/Icinga/Authentication/Backend/IniUserGroupBackend.php b/library/Icinga/Authentication/Backend/IniUserGroupBackend.php new file mode 100644 index 000000000..45d36e833 --- /dev/null +++ b/library/Icinga/Authentication/Backend/IniUserGroupBackend.php @@ -0,0 +1,65 @@ +config = $config; + } + + /** + * (non-PHPDoc) + * @see UserGroupBackend::getMemberships() For the method documentation. + */ + public function getMemberships(User $user) + { + $username = strtolower($user->getUsername()); + $groups = array(); + foreach ($this->config as $name => $section) { + if (empty($section->users)) { + throw new ConfigurationError( + 'Membership section \'%s\' in \'%s\' is missing the \'users\' section', + $name, + $this->config->getConfigFile() + ); + } + if (empty($section->groups)) { + throw new ConfigurationError( + 'Membership section \'%s\' in \'%s\' is missing the \'groups\' section', + $name, + $this->config->getConfigFile() + ); + } + $users = array_map('strtolower', String::trimSplit($section->users)); + if (in_array($username, $users)) { + $groups = array_merge($groups, array_diff(String::trimSplit($section->groups), $groups)); + } + } + return $groups; + } +} diff --git a/library/Icinga/Authentication/Membership.php b/library/Icinga/Authentication/Membership.php deleted file mode 100644 index 2f6e83710..000000000 --- a/library/Icinga/Authentication/Membership.php +++ /dev/null @@ -1,39 +0,0 @@ -users); - if (in_array($username, $users)) { - $groups = array_merge($groups, String::trimSplit($section->groups)); - } - } - return $groups; - } -}