Passed
Push — master ( dc3b44...f77c3f )
by Roeland
09:51 queued 10s
created
apps/user_ldap/lib/UserPluginManager.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -27,184 +27,184 @@
 block discarded – undo
27 27
 
28 28
 class UserPluginManager {
29 29
 
30
-	public $test = false;
31
-
32
-	private $respondToActions = 0;
33
-
34
-	private $which = array(
35
-		Backend::CREATE_USER => null,
36
-		Backend::SET_PASSWORD => null,
37
-		Backend::GET_HOME => null,
38
-		Backend::GET_DISPLAYNAME => null,
39
-		Backend::SET_DISPLAYNAME => null,
40
-		Backend::PROVIDE_AVATAR => null,
41
-		Backend::COUNT_USERS => null,
42
-		'deleteUser' => null
43
-	);
44
-
45
-	/**
46
-	 * @return int All implemented actions, except for 'deleteUser'
47
-	 */
48
-	public function getImplementedActions() {
49
-		return $this->respondToActions;
50
-	}
51
-
52
-	/**
53
-	 * Registers a user plugin that may implement some actions, overriding User_LDAP's user actions.
54
-	 *
55
-	 * @param ILDAPUserPlugin $plugin
56
-	 */
57
-	public function register(ILDAPUserPlugin $plugin) {
58
-		$respondToActions = $plugin->respondToActions();
59
-		$this->respondToActions |= $respondToActions;
60
-
61
-		foreach($this->which as $action => $v) {
62
-			if (is_int($action) && (bool)($respondToActions & $action)) {
63
-				$this->which[$action] = $plugin;
64
-				\OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']);
65
-			}
66
-		}
67
-		if (method_exists($plugin,'deleteUser')) {
68
-			$this->which['deleteUser'] = $plugin;
69
-			\OC::$server->getLogger()->debug("Registered action deleteUser to plugin ".get_class($plugin), ['app' => 'user_ldap']);
70
-		}
71
-	}
72
-
73
-	/**
74
-	 * Signal if there is a registered plugin that implements some given actions
75
-	 * @param int $actions Actions defined in \OC\User\Backend, like Backend::CREATE_USER
76
-	 * @return bool
77
-	 */
78
-	public function implementsActions($actions) {
79
-		return ($actions & $this->respondToActions) == $actions;
80
-	}
81
-
82
-	/**
83
-	 * Create a new user in LDAP Backend
84
-	 *
85
-	 * @param string $username The username of the user to create
86
-	 * @param string $password The password of the new user
87
-	 * @return bool
88
-	 * @throws \Exception
89
-	 */
90
-	public function createUser($username, $password) {
91
-		$plugin = $this->which[Backend::CREATE_USER];
92
-
93
-		if ($plugin) {
94
-			return $plugin->createUser($username,$password);
95
-		}
96
-		throw new \Exception('No plugin implements createUser in this LDAP Backend.');
97
-	}
98
-
99
-	/**
100
-	 * Change the password of a user*
101
-	 * @param string $uid The username
102
-	 * @param string $password The new password
103
-	 * @return bool
104
-	 * @throws \Exception
105
-	 */
106
-	public function setPassword($uid, $password) {
107
-		$plugin = $this->which[Backend::SET_PASSWORD];
108
-
109
-		if ($plugin) {
110
-			return $plugin->setPassword($uid,$password);
111
-		}
112
-		throw new \Exception('No plugin implements setPassword in this LDAP Backend.');
113
-	}
114
-
115
-	/**
116
-	 * checks whether the user is allowed to change his avatar in Nextcloud
117
-	 * @param string $uid the Nextcloud user name
118
-	 * @return boolean either the user can or cannot
119
-	 * @throws \Exception
120
-	 */
121
-	public function canChangeAvatar($uid) {
122
-		$plugin = $this->which[Backend::PROVIDE_AVATAR];
123
-
124
-		if ($plugin) {
125
-			return $plugin->canChangeAvatar($uid);
126
-		}
127
-		throw new \Exception('No plugin implements canChangeAvatar in this LDAP Backend.');
128
-	}
129
-
130
-	/**
131
-	 * Get the user's home directory
132
-	 * @param string $uid the username
133
-	 * @return boolean
134
-	 * @throws \Exception
135
-	 */
136
-	public function getHome($uid) {
137
-		$plugin = $this->which[Backend::GET_HOME];
138
-
139
-		if ($plugin) {
140
-			return $plugin->getHome($uid);
141
-		}
142
-		throw new \Exception('No plugin implements getHome in this LDAP Backend.');
143
-	}
144
-
145
-	/**
146
-	 * Get display name of the user
147
-	 * @param string $uid user ID of the user
148
-	 * @return string display name
149
-	 * @throws \Exception
150
-	 */
151
-	public function getDisplayName($uid) {
152
-		$plugin = $this->which[Backend::GET_DISPLAYNAME];
153
-
154
-		if ($plugin) {
155
-			return $plugin->getDisplayName($uid);
156
-		}
157
-		throw new \Exception('No plugin implements getDisplayName in this LDAP Backend.');
158
-	}
159
-
160
-	/**
161
-	 * Set display name of the user
162
-	 * @param string $uid user ID of the user
163
-	 * @param string $displayName new user's display name
164
-	 * @return string display name
165
-	 * @throws \Exception
166
-	 */
167
-	public function setDisplayName($uid, $displayName) {
168
-		$plugin = $this->which[Backend::SET_DISPLAYNAME];
169
-
170
-		if ($plugin) {
171
-			return $plugin->setDisplayName($uid, $displayName);
172
-		}
173
-		throw new \Exception('No plugin implements setDisplayName in this LDAP Backend.');
174
-	}
175
-
176
-	/**
177
-	 * Count the number of users
178
-	 * @return int|bool
179
-	 * @throws \Exception
180
-	 */
181
-	public function countUsers() {
182
-		$plugin = $this->which[Backend::COUNT_USERS];
183
-
184
-		if ($plugin) {
185
-			return $plugin->countUsers();
186
-		}
187
-		throw new \Exception('No plugin implements countUsers in this LDAP Backend.');
188
-	}
189
-
190
-	/**
191
-	 * @return bool
192
-	 */
193
-	public function canDeleteUser() {
194
-		return $this->which['deleteUser'] !== null;
195
-	}
196
-
197
-	/**
198
-	 * @param $uid
199
-	 * @return bool
200
-	 * @throws \Exception
201
-	 */
202
-	public function deleteUser($uid) {
203
-		$plugin = $this->which['deleteUser'];
204
-		if ($plugin) {
205
-			return $plugin->deleteUser($uid);
206
-		}
207
-		throw new \Exception('No plugin implements deleteUser in this LDAP Backend.');
208
-	}
30
+    public $test = false;
31
+
32
+    private $respondToActions = 0;
33
+
34
+    private $which = array(
35
+        Backend::CREATE_USER => null,
36
+        Backend::SET_PASSWORD => null,
37
+        Backend::GET_HOME => null,
38
+        Backend::GET_DISPLAYNAME => null,
39
+        Backend::SET_DISPLAYNAME => null,
40
+        Backend::PROVIDE_AVATAR => null,
41
+        Backend::COUNT_USERS => null,
42
+        'deleteUser' => null
43
+    );
44
+
45
+    /**
46
+     * @return int All implemented actions, except for 'deleteUser'
47
+     */
48
+    public function getImplementedActions() {
49
+        return $this->respondToActions;
50
+    }
51
+
52
+    /**
53
+     * Registers a user plugin that may implement some actions, overriding User_LDAP's user actions.
54
+     *
55
+     * @param ILDAPUserPlugin $plugin
56
+     */
57
+    public function register(ILDAPUserPlugin $plugin) {
58
+        $respondToActions = $plugin->respondToActions();
59
+        $this->respondToActions |= $respondToActions;
60
+
61
+        foreach($this->which as $action => $v) {
62
+            if (is_int($action) && (bool)($respondToActions & $action)) {
63
+                $this->which[$action] = $plugin;
64
+                \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']);
65
+            }
66
+        }
67
+        if (method_exists($plugin,'deleteUser')) {
68
+            $this->which['deleteUser'] = $plugin;
69
+            \OC::$server->getLogger()->debug("Registered action deleteUser to plugin ".get_class($plugin), ['app' => 'user_ldap']);
70
+        }
71
+    }
72
+
73
+    /**
74
+     * Signal if there is a registered plugin that implements some given actions
75
+     * @param int $actions Actions defined in \OC\User\Backend, like Backend::CREATE_USER
76
+     * @return bool
77
+     */
78
+    public function implementsActions($actions) {
79
+        return ($actions & $this->respondToActions) == $actions;
80
+    }
81
+
82
+    /**
83
+     * Create a new user in LDAP Backend
84
+     *
85
+     * @param string $username The username of the user to create
86
+     * @param string $password The password of the new user
87
+     * @return bool
88
+     * @throws \Exception
89
+     */
90
+    public function createUser($username, $password) {
91
+        $plugin = $this->which[Backend::CREATE_USER];
92
+
93
+        if ($plugin) {
94
+            return $plugin->createUser($username,$password);
95
+        }
96
+        throw new \Exception('No plugin implements createUser in this LDAP Backend.');
97
+    }
98
+
99
+    /**
100
+     * Change the password of a user*
101
+     * @param string $uid The username
102
+     * @param string $password The new password
103
+     * @return bool
104
+     * @throws \Exception
105
+     */
106
+    public function setPassword($uid, $password) {
107
+        $plugin = $this->which[Backend::SET_PASSWORD];
108
+
109
+        if ($plugin) {
110
+            return $plugin->setPassword($uid,$password);
111
+        }
112
+        throw new \Exception('No plugin implements setPassword in this LDAP Backend.');
113
+    }
114
+
115
+    /**
116
+     * checks whether the user is allowed to change his avatar in Nextcloud
117
+     * @param string $uid the Nextcloud user name
118
+     * @return boolean either the user can or cannot
119
+     * @throws \Exception
120
+     */
121
+    public function canChangeAvatar($uid) {
122
+        $plugin = $this->which[Backend::PROVIDE_AVATAR];
123
+
124
+        if ($plugin) {
125
+            return $plugin->canChangeAvatar($uid);
126
+        }
127
+        throw new \Exception('No plugin implements canChangeAvatar in this LDAP Backend.');
128
+    }
129
+
130
+    /**
131
+     * Get the user's home directory
132
+     * @param string $uid the username
133
+     * @return boolean
134
+     * @throws \Exception
135
+     */
136
+    public function getHome($uid) {
137
+        $plugin = $this->which[Backend::GET_HOME];
138
+
139
+        if ($plugin) {
140
+            return $plugin->getHome($uid);
141
+        }
142
+        throw new \Exception('No plugin implements getHome in this LDAP Backend.');
143
+    }
144
+
145
+    /**
146
+     * Get display name of the user
147
+     * @param string $uid user ID of the user
148
+     * @return string display name
149
+     * @throws \Exception
150
+     */
151
+    public function getDisplayName($uid) {
152
+        $plugin = $this->which[Backend::GET_DISPLAYNAME];
153
+
154
+        if ($plugin) {
155
+            return $plugin->getDisplayName($uid);
156
+        }
157
+        throw new \Exception('No plugin implements getDisplayName in this LDAP Backend.');
158
+    }
159
+
160
+    /**
161
+     * Set display name of the user
162
+     * @param string $uid user ID of the user
163
+     * @param string $displayName new user's display name
164
+     * @return string display name
165
+     * @throws \Exception
166
+     */
167
+    public function setDisplayName($uid, $displayName) {
168
+        $plugin = $this->which[Backend::SET_DISPLAYNAME];
169
+
170
+        if ($plugin) {
171
+            return $plugin->setDisplayName($uid, $displayName);
172
+        }
173
+        throw new \Exception('No plugin implements setDisplayName in this LDAP Backend.');
174
+    }
175
+
176
+    /**
177
+     * Count the number of users
178
+     * @return int|bool
179
+     * @throws \Exception
180
+     */
181
+    public function countUsers() {
182
+        $plugin = $this->which[Backend::COUNT_USERS];
183
+
184
+        if ($plugin) {
185
+            return $plugin->countUsers();
186
+        }
187
+        throw new \Exception('No plugin implements countUsers in this LDAP Backend.');
188
+    }
189
+
190
+    /**
191
+     * @return bool
192
+     */
193
+    public function canDeleteUser() {
194
+        return $this->which['deleteUser'] !== null;
195
+    }
196
+
197
+    /**
198
+     * @param $uid
199
+     * @return bool
200
+     * @throws \Exception
201
+     */
202
+    public function deleteUser($uid) {
203
+        $plugin = $this->which['deleteUser'];
204
+        if ($plugin) {
205
+            return $plugin->deleteUser($uid);
206
+        }
207
+        throw new \Exception('No plugin implements deleteUser in this LDAP Backend.');
208
+    }
209 209
 }
210 210
 
Please login to merge, or discard this patch.