aboutsummaryrefslogtreecommitdiff
path: root/pkgs/icingaweb2/sproxy.patch
blob: d1b074dbb7eac91570ded95b9c6cf259f1decd36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
commit 04eb7cffa84387070f48f5649a1d5a5a7843fc9c
Author: Igor Pashev <pashev.igor@gmail.com>
Date:   Fri Jan 1 11:05:48 2016 +0300

    Added Sproxy backend

    See https://github.com/zalora/sproxy

diff --git a/library/Icinga/Authentication/User/SproxyBackend.php b/library/Icinga/Authentication/User/SproxyBackend.php
new file mode 100644
index 0000000..4b15b0e
--- /dev/null
+++ b/library/Icinga/Authentication/User/SproxyBackend.php
@@ -0,0 +1,40 @@
+<?php
+/* 2016 Zalora South East Asia Pte. Ltd | GPLv2+ */
+
+namespace Icinga\Authentication\User;
+
+use Icinga\Data\ConfigObject;
+use Icinga\User;
+
+/**
+ * Login with Sproxy authentication mechanism:
+ * https://github.com/zalora/sproxy
+ */
+class SproxyBackend extends ExternalBackend
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function authenticate(User $user, $password = null)
+    {
+        if (! empty($_SERVER['HTTP_FROM'])) {
+            $email = $_SERVER['HTTP_FROM'];
+            $user->setUsername($email);
+            $user->setEmail($email);
+            $user->setExternalUserInformation($email, 'HTTP_FROM');
+
+            if (! empty($_SERVER['HTTP_X_GIVEN_NAME'])) {
+              $user->setFirstname($_SERVER['HTTP_X_GIVEN_NAME']);
+            }
+            if (! empty($_SERVER['HTTP_X_GROUPS'])) {
+              $user->setGroups(explode(',', $_SERVER['HTTP_X_GROUPS']));
+            }
+            if (! empty($_SERVER['HTTP_X_FAMILY_NAME'])) {
+              $user->setLastname($_SERVER['HTTP_X_FAMILY_NAME']);
+            }
+
+            return true;
+        }
+        return false;
+    }
+}
diff --git a/library/Icinga/Authentication/User/UserBackend.php b/library/Icinga/Authentication/User/UserBackend.php
index 3b8e210..d264365 100644
--- a/library/Icinga/Authentication/User/UserBackend.php
+++ b/library/Icinga/Authentication/User/UserBackend.php
@@ -22,6 +22,7 @@ class UserBackend implements ConfigAwareFactory
      * @var array
      */
     protected static $defaultBackends = array(
+        'sproxy',
         'external',
         'db',
         'ldap',
@@ -176,6 +177,11 @@ class UserBackend implements ConfigAwareFactory
             $backend->setName($name);
             return $backend;
         }
+        if ($backendType === 'sproxy') {
+            $backend = new SproxyBackend($backendConfig);
+            $backend->setName($name);
+            return $backend;
+        }
         if (in_array($backendType, static::$defaultBackends)) {
             // The default backend check is the first one because of performance reasons:
             // Do not attempt to load a custom user backend unless it's actually required