wp-auth-ldap
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
9 changed files
with
588 additions
and
0 deletions
wp-content/plugins/wp-auth-ldap/.gitignore
0 → 100644
wp-content/plugins/wp-auth-ldap/README.md
0 → 100644
| 1 | # authLDAP | ||
| 2 | |||
| 3 | [](https://gitter.im/heiglandreas/authLdap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
| 4 | |||
| 5 | Use your existing LDAP as authentication-backend for your wordpress! | ||
| 6 | |||
| 7 | [](https://travis-ci.org/heiglandreas/authLdap) | ||
| 8 | [](https://wordpress.org/plugins/authldap/stats/) | ||
| 9 | [](https://wordpress.org/plugins/authldap/) | ||
| 10 | [](https://wordpress.org/plugins/authldap/) | ||
| 11 | [](https://codeclimate.com/github/heiglandreas/authLdap) | ||
| 12 | [](https://codeclimate.com/github/heiglandreas/authLdap) | ||
| 13 | |||
| 14 | So what are the differences to other Wordpress-LDAP-Authentication-Plugins? | ||
| 15 | |||
| 16 | * **Flexible**: You are totaly free in which LDAP-backend to use. Due to the extensive configuration you can | ||
| 17 | freely decide how to do the authentication of your users. It simply depends on your | ||
| 18 | filters | ||
| 19 | * **Independent**: As soon as a user logs in, it is added/updated to the Wordpress' user-database | ||
| 20 | to allow wordpress to always use the correct data. You only have to administer your users once. | ||
| 21 | * **Failsafe**: Due to the users being created in Wordpress' User-database they can | ||
| 22 | also log in when the LDAP-backend currently is gone. | ||
| 23 | * **Role-Aware**: You can map Wordpress' roles to values of an existing LDAP-attribute. | ||
| 24 | |||
| 25 | ## How does the plugin work? | ||
| 26 | |||
| 27 | Well, as a matter of fact it is rather simple. The plugin verifies, that the user | ||
| 28 | seeking authentification can bind to the LDAP using the provided password. | ||
| 29 | |||
| 30 | If that is so, the user is either created or updated in the wordpress-user-database. | ||
| 31 | This update includes the provided password (so the wordpress can authenticate users | ||
| 32 | even without the LDAP), the users name according to the authLDAP-preferences and | ||
| 33 | the status of the user depending on the groups-settings of the authLDAP-preferences | ||
| 34 | |||
| 35 | Writing this plugin would not have been as easy as it has been, without the | ||
| 36 | wonderfull plugin of Alistair Young from http://www.weblogs.uhi.ac.uk/sm00ay/?p=45 | ||
| 37 | |||
| 38 | ## Configuration | ||
| 39 | |||
| 40 | ### Usage Settings | ||
| 41 | |||
| 42 | * **Enable Authentication via LDAP** Whether you want to enable authLdap for login or not | ||
| 43 | * **debug authLdap** When you have problems with authentication via LDAP you can enable a debugging mode here. | ||
| 44 | * **Save entered Password** Decide whether passwords will be cached in your wordpress-installation. **Attention:** Without the cache your users will not be able to log into your site when your LDAP is down! | ||
| 45 | |||
| 46 | ### Server Settings | ||
| 47 | |||
| 48 | * **LDAP Uri** This is the URI where your ldap-backend can be reached. More information are actually on the Configuration page | ||
| 49 | * **Filter** This is the real McCoy! The filter you define here specifies how a user will be found. Before applying the filter a %s will be replaced with the given username. This means, when a user logs in using ‘foobar’ as username the following happens: | ||
| 50 | |||
| 51 | * **uid=%s** check for any LDAP-Entry that has an attribute ‘uid’ with value ‘foobar’ | ||
| 52 | * **(&(objectclass=posixAccount)((!(uid=%s)(mail=%s)))** check for any LDAP-Entry that has an attribute ‘objectclass’ with value ‘posixAccout’ and either a UID- or a mail-attribute with value ‘foobar’ | ||
| 53 | |||
| 54 | This filter is rather powerfull if used wisely. | ||
| 55 | |||
| 56 | ### Creating Users | ||
| 57 | |||
| 58 | * **Name-Attribute** Which Attribute from the LDAP contains the Full or the First name of the user trying to log in. This defaults to name | ||
| 59 | * **Second Name Attribute** If the above Name-Attribute only contains the First Name of the user you can here specify an Attribute that contains the second name. This field is empty by default | ||
| 60 | * **User-ID Attribute** This field will be used as login-name for wordpress. Please give the Attribute, that is used to identify the user. This should be the same as you used in the above Filter-Option. This field defaults to uid | ||
| 61 | * **Mail Attribute** Which Attribute holds the eMail-Address of the user? If more than one eMail-Address are stored in the LDAP, only the first given is used. This field defaults to mail | ||
| 62 | * **Web-Attribute** If your users have a personal page (URI) stored in the LDAP, it can be provided here. This field is empty by default | ||
| 63 | |||
| 64 | ### User-Groups for Roles | ||
| 65 | |||
| 66 | * **Group-Attribute** This is the attribute that defines the Group-ID that can be matched against the Groups defined further down This field defaults to gidNumber. | ||
| 67 | * **Group-Filter** Here you can add the filter for selecting groups for the currentlly logged in user The Filter should contain the string %s which will be replaced by the login-name of the currently logged in | ||
| 68 | |||
| 69 | |||
| 70 | ## FAQ | ||
| 71 | |||
| 72 | <dl> | ||
| 73 | <dt>Can I change a users password with this plugin?</dt> | ||
| 74 | <dd>Short Answer: <strong>No</strong>!<br>Long Answer: As the users credentials are not | ||
| 75 | only used for a wordpress-site when you authenticate against an LDAP but for | ||
| 76 | many other services also chances are great that there is a centralized place | ||
| 77 | where password-changes shall be made. We'll later allow inclusion of a link | ||
| 78 | to such a place but currently it's not available. And as password-hashing and | ||
| 79 | where to store it requires deeper insight into the LDAP-Server then most users | ||
| 80 | have and admins are willing to give, password changes are out of scope of this | ||
| 81 | plugin. If you know exactyl what you do, you might want to have a look at | ||
| 82 | <a href="https://github.com/heiglandreas/authLdap/issues/54#issuecomment-125851029"> | ||
| 83 | issue 54</a> | ||
| 84 | wherer a way of adding it is described! | ||
| 85 | </dd> | ||
| 86 | <dt>Can I add a user to the LDAP when she creates a user-account on wordpress?</dt> | ||
| 87 | <dd>Short Answer: <strong>No</strong>!<br>Long Answer: Even though that is technically possible | ||
| 88 | it's not in the scope of this plugin. As creating a user in an LDAP often involves | ||
| 89 | an administrative process that has already been implemented in your departments | ||
| 90 | administration it doesn't make sense to rebuild that - in most cases highly | ||
| 91 | individual - process in this plugin. If you know exactly what you do, have a look at | ||
| 92 | <a href="https://github.com/heiglandreas/authLdap/issues/65">issue 65</a> | ||
| 93 | where <a href="https://github.com/wtfiwtz">wtfiwtz</a> shows how to implement that feature. | ||
| 94 | </dd> | ||
| 95 | </dl> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
wp-content/plugins/wp-auth-ldap/VERSION
0 → 100644
| 1 | 1.4.20 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | { | ||
| 2 | "name" : "lampo/wp-auth-ldap", | ||
| 3 | "type" : "wordpress-plugin", | ||
| 4 | "description": "Fork of http://github.com/heiglandreas/authLdap, moves settings to defined constants.", | ||
| 5 | "keywords": ["ldap","authenticate", "auth", "wordpress"], | ||
| 6 | "homepage": "http://github.com/lampo/wp-auth-ldap", | ||
| 7 | "license": "MIT", | ||
| 8 | "authors": [{ | ||
| 9 | "name": "Andreas Heigl", | ||
| 10 | "email": "andreas@heigl.org", | ||
| 11 | "homepage": "http://andreas.heigl.org", | ||
| 12 | "role": "Developer" | ||
| 13 | },{ | ||
| 14 | "name": "Micah Flatt", | ||
| 15 | "email": "mflatt@flattware.net", | ||
| 16 | "role": "Developer" | ||
| 17 | }], | ||
| 18 | "require" : { | ||
| 19 | "php": ">=5.4", | ||
| 20 | "composer/installers": "~1.0" | ||
| 21 | }, | ||
| 22 | "autoload" : { | ||
| 23 | "psr-4" : { | ||
| 24 | "Org_Heigl\\AuthLdap\\" : "./" | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } |
wp-content/plugins/wp-auth-ldap/ldap.php
0 → 100644
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * $Id: ldap.php 381646 2011-05-06 09:37:31Z heiglandreas $ | ||
| 4 | * | ||
| 5 | * authLdap - Authenticate Wordpress against an LDAP-Backend. | ||
| 6 | * Copyright (c) 2008 Andreas Heigl<andreas@heigl.org> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License | ||
| 10 | * as published by the Free Software Foundation; either version 2 | ||
| 11 | * of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 21 | * | ||
| 22 | * This file handles the basic LDAP-Tasks | ||
| 23 | * | ||
| 24 | * @author Andreas Heigl<andreas@heigl.org> | ||
| 25 | * @package authLdap | ||
| 26 | * @category authLdap | ||
| 27 | * @since 2008 | ||
| 28 | */ | ||
| 29 | namespace Org_Heigl\AuthLdap; | ||
| 30 | |||
| 31 | use Exception; | ||
| 32 | |||
| 33 | class LDAP | ||
| 34 | { | ||
| 35 | private $_server = ''; | ||
| 36 | |||
| 37 | private $_scheme = 'ldap'; | ||
| 38 | |||
| 39 | private $_port = 389; | ||
| 40 | |||
| 41 | private $_baseDn = ''; | ||
| 42 | |||
| 43 | private $_debug = false; | ||
| 44 | /** | ||
| 45 | * This property contains the connection handle to the ldap-server | ||
| 46 | * | ||
| 47 | * @var Ressource | ||
| 48 | */ | ||
| 49 | private $_ch = null; | ||
| 50 | |||
| 51 | private $_username = ''; | ||
| 52 | |||
| 53 | private $_password = ''; | ||
| 54 | |||
| 55 | private $_starttls = false; | ||
| 56 | |||
| 57 | public function __construct($URI, $debug = false, $starttls = false) | ||
| 58 | { | ||
| 59 | $this->_debug=$debug; | ||
| 60 | $array = parse_url($URI); | ||
| 61 | if (! is_array($array)) { | ||
| 62 | throw new Exception($URI . ' seems not to be a valid URI'); | ||
| 63 | } | ||
| 64 | $url = array_map(function ($item) { return urldecode($item); }, $array); | ||
| 65 | if (false === $url) { | ||
| 66 | throw new Exception($URI . ' is an invalid URL'); | ||
| 67 | } | ||
| 68 | if (! isset ( $url['scheme'] )) { | ||
| 69 | throw new Exception($URI . ' does not provide a scheme'); | ||
| 70 | } | ||
| 71 | if (0 !== strpos($url['scheme'], 'ldap')) { | ||
| 72 | throw new Exception($URI . ' is an invalid LDAP-URI'); | ||
| 73 | } | ||
| 74 | if (! isset ( $url['host'] )) { | ||
| 75 | throw new Exception($URI . ' does not provide a server'); | ||
| 76 | } | ||
| 77 | if (! isset ( $url['path'] )) { | ||
| 78 | throw new Exception($URI . ' does not provide a search-base'); | ||
| 79 | } | ||
| 80 | if (1 == strlen($url['path'])) { | ||
| 81 | throw new Exception($URI . ' does not provide a valid search-base'); | ||
| 82 | } | ||
| 83 | $this -> _server = $url['host']; | ||
| 84 | $this -> _scheme = $url['scheme']; | ||
| 85 | $this -> _baseDn = substr($url['path'], 1); | ||
| 86 | if (isset ( $url['user'] )) { | ||
| 87 | $this -> _username = $url['user']; | ||
| 88 | } | ||
| 89 | if ('' == trim($this -> _username)) { | ||
| 90 | $this -> _username = 'anonymous'; | ||
| 91 | } | ||
| 92 | if (isset ( $url['pass'] )) { | ||
| 93 | $this -> _password = $url['pass']; | ||
| 94 | } | ||
| 95 | if (isset ( $url['port'] )) { | ||
| 96 | $this -> _port = $url['port']; | ||
| 97 | } | ||
| 98 | $this->_starttls = $starttls; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Connect to the given LDAP-Server | ||
| 103 | * | ||
| 104 | * @return LDAP | ||
| 105 | * @throws AuthLdap_Exception | ||
| 106 | */ | ||
| 107 | public function connect() | ||
| 108 | { | ||
| 109 | $this -> disconnect(); | ||
| 110 | if ('ldaps' == $this->_scheme && 389 == $this->_port) { | ||
| 111 | $this->_port = 636; | ||
| 112 | } | ||
| 113 | |||
| 114 | $this->_ch = @ldap_connect($this->_scheme . '://' . $this->_server . ':' . $this -> _port); | ||
| 115 | if (! $this->_ch) { | ||
| 116 | throw new AuthLDAP_Exception('Could not connect to the server'); | ||
| 117 | } | ||
| 118 | ldap_set_option($this->_ch, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
| 119 | ldap_set_option($this->_ch, LDAP_OPT_REFERRALS, 0); | ||
| 120 | //if configured try to upgrade encryption to tls for ldap connections | ||
| 121 | if ($this->_starttls) { | ||
| 122 | ldap_start_tls($this->_ch); | ||
| 123 | } | ||
| 124 | return $this; | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Disconnect from a resource if one is available | ||
| 129 | * | ||
| 130 | * @return LDAP | ||
| 131 | */ | ||
| 132 | public function disconnect() | ||
| 133 | { | ||
| 134 | if (is_resource($this->_ch)) { | ||
| 135 | @ldap_unbind($this->_ch); | ||
| 136 | } | ||
| 137 | $this->_ch = null; | ||
| 138 | return $this; | ||
| 139 | } | ||
| 140 | |||
| 141 | /** | ||
| 142 | * Bind to an LDAP-Server with the given credentials | ||
| 143 | * | ||
| 144 | * @return LDAP | ||
| 145 | * @throw AuthLdap_Exception | ||
| 146 | */ | ||
| 147 | public function bind() | ||
| 148 | { | ||
| 149 | if (! $this->_ch) { | ||
| 150 | $this->connect(); | ||
| 151 | } | ||
| 152 | if (! is_resource($this->_ch)) { | ||
| 153 | throw new AuthLDAP_Exception('No Resource-handle given'); | ||
| 154 | } | ||
| 155 | $bind = false; | ||
| 156 | if (( ( $this->_username ) | ||
| 157 | && ( $this->_username != 'anonymous') ) | ||
| 158 | && ( $this->_password != '' ) ) { | ||
| 159 | $bind = @ldap_bind($this->_ch, $this->_username, $this->_password); | ||
| 160 | } else { | ||
| 161 | $bind = @ldap_bind($this->_ch); | ||
| 162 | } | ||
| 163 | if (! $bind) { | ||
| 164 | throw new AuthLDAP_Exception('bind was not successfull: ' . ldap_error($this->_ch)); | ||
| 165 | } | ||
| 166 | return $this; | ||
| 167 | } | ||
| 168 | |||
| 169 | public function getErrorNumber() | ||
| 170 | { | ||
| 171 | return @ldap_errno($this->_ch); | ||
| 172 | } | ||
| 173 | |||
| 174 | public function getErrorText() | ||
| 175 | { | ||
| 176 | return @ldap_error($this->_ch); | ||
| 177 | } | ||
| 178 | |||
| 179 | /** | ||
| 180 | * This method does the actual ldap-serch. | ||
| 181 | * | ||
| 182 | * This is using the filter <var>$filter</var> for retrieving the attributes | ||
| 183 | * <var>$attributes</var> | ||
| 184 | * | ||
| 185 | * | ||
| 186 | * @param string $filter | ||
| 187 | * @param array $attributes | ||
| 188 | * @return array | ||
| 189 | */ | ||
| 190 | public function search($filter, $attributes = array('uid')) | ||
| 191 | { | ||
| 192 | if (! is_Resource($this->_ch)) { | ||
| 193 | throw new AuthLDAP_Exception('No resource handle avbailable'); | ||
| 194 | } | ||
| 195 | $result = @ldap_search($this->_ch, $this->_baseDn, $filter, $attributes); | ||
| 196 | if ($result === false) { | ||
| 197 | throw new AuthLDAP_Exception('no result found'); | ||
| 198 | } | ||
| 199 | $this->_info = @ldap_get_entries($this->_ch, $result); | ||
| 200 | if ($this->_info === false) { | ||
| 201 | throw new AuthLDAP_Exception('invalid results found'); | ||
| 202 | } | ||
| 203 | return $this -> _info; | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * This method sets debugging to ON | ||
| 208 | */ | ||
| 209 | public function debugOn() | ||
| 210 | { | ||
| 211 | $this->_debug = true; | ||
| 212 | return $this; | ||
| 213 | } | ||
| 214 | |||
| 215 | /** | ||
| 216 | * This method sets debugging to OFF | ||
| 217 | */ | ||
| 218 | public function debugOff() | ||
| 219 | { | ||
| 220 | $this->_debug = false; | ||
| 221 | return $this; | ||
| 222 | } | ||
| 223 | |||
| 224 | /** | ||
| 225 | * This method authenticates the user <var>$username</var> using the | ||
| 226 | * password <var>$password</var> | ||
| 227 | * | ||
| 228 | * @param string $username | ||
| 229 | * @param string $password | ||
| 230 | * @param string $filter OPTIONAL This parameter defines the Filter to be used | ||
| 231 | * when searchin for the username. This MUST contain the string '%s' which | ||
| 232 | * will be replaced by the vaue given in <var>$username</var> | ||
| 233 | * @return boolean true or false depending on successfull authentication or not | ||
| 234 | */ | ||
| 235 | public function authenticate($username, $password, $filter = '(uid=%s)') | ||
| 236 | { | ||
| 237 | //return true; | ||
| 238 | $this->connect(); | ||
| 239 | $this->bind(); | ||
| 240 | $res = $this->search(sprintf($filter, $username)); | ||
| 241 | if (! $res || ! is_array($res) || ( $res ['count'] != 1 )) { | ||
| 242 | return false; | ||
| 243 | } | ||
| 244 | $dn = $res[0]['dn']; | ||
| 245 | if ($username && $password) { | ||
| 246 | if (@ldap_bind($this->_ch, $dn, $password)) { | ||
| 247 | return true; | ||
| 248 | } | ||
| 249 | } | ||
| 250 | return false; | ||
| 251 | } | ||
| 252 | /** | ||
| 253 | * $this method loggs errors if debugging is set to ON | ||
| 254 | */ | ||
| 255 | public function logError() | ||
| 256 | { | ||
| 257 | if ($this->_debug) { | ||
| 258 | $_v = debug_backtrace(); | ||
| 259 | throw new AuthLDAP_Exception('[LDAP_ERROR]' . ldap_errno($this->_ch) . ':' . ldap_error($this->_ch), $_v[0]['line']); | ||
| 260 | } | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | class AuthLDAP_Exception extends Exception | ||
| 265 | { | ||
| 266 | public function __construct($message, $line = null) | ||
| 267 | { | ||
| 268 | parent :: __construct($message); | ||
| 269 | if ($line) { | ||
| 270 | $this -> line = $line; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | } |
wp-content/plugins/wp-auth-ldap/readme.txt
0 → 100644
| 1 | === authLdap === | ||
| 2 | Contributors: heiglandreas | ||
| 3 | Tags: ldap, auth | ||
| 4 | Requires at least: 2.5.0 | ||
| 5 | Tested up to: 4.6.1 | ||
| 6 | Stable tag: trunk | ||
| 7 | |||
| 8 | Use your existing LDAP flexible as authentication backend for WordPress | ||
| 9 | |||
| 10 | == Description == | ||
| 11 | |||
| 12 | Use your existing LDAP as authentication-backend for your wordpress! | ||
| 13 | |||
| 14 | So what are the differences to other Wordpress-LDAP-Authentication-Plugins? | ||
| 15 | |||
| 16 | * Flexible: You are totaly free in which LDAP-backend to use. Due to the extensive configuration you can | ||
| 17 | freely decide how to do the authentication of your users. It simply depends on your | ||
| 18 | filters | ||
| 19 | * Independent: As soon as a user logs in, it is added/updated to the Wordpress' user-database | ||
| 20 | to allow wordpress to always use the correct data. You only have to administer your users once. | ||
| 21 | * Failsafe: Due to the users being created in Wordpress' User-database they can | ||
| 22 | also log in when the LDAP-backend currently is gone. | ||
| 23 | * Role-Aware: You can map Wordpress' roles to values of an existing LDAP-attribute. | ||
| 24 | |||
| 25 | For more Information on the configuration have a look at https://github.com/heiglandreas/authLdap | ||
| 26 | |||
| 27 | == Installation == | ||
| 28 | |||
| 29 | 1. Upload the extracted folder `authLdap` to the `/wp-content/plugins/` directory | ||
| 30 | 2. Activate the plugin through the 'Plugins' menu in WordPress | ||
| 31 | 3. Configure the Plugin via the 'authLdap'-Configuration-Page. | ||
| 32 | |||
| 33 | == Frequently Asked Questions == | ||
| 34 | |||
| 35 | = Where can I find more Informations about the plugin? = | ||
| 36 | |||
| 37 | Go to https://github.com/heiglandreas/authLdap | ||
| 38 | |||
| 39 | = Where can I report issues with the plugin? = | ||
| 40 | |||
| 41 | Please use the issuetracker at https://github.com/heiglandreas/authLdap/issues | ||
| 42 | |||
| 43 | == Changelog == | ||
| 44 | = 1.4.20 = | ||
| 45 | * Allows multiple LDAP-servers to be queried (given that they use the same attributes) | ||
| 46 | * Fixes issue with URL-Encoded informations (see https://github.com/heiglandreas/authLdap/issues/108) | ||
| 47 | |||
| 48 | = 1.4.19 = | ||
| 49 | * Adds support for TLS | ||
| 50 | |||
| 51 | = 1.4.14 = | ||
| 52 | * Update to showing password-fields check (thanks to @chaplina) | ||
| 53 | |||
| 54 | = 1.4.13 = | ||
| 55 | * Removed generation of default email-address (thanks to @henryk) | ||
| 56 | * Fixes password-hashing when caching passwords (thanks to @litinoveweedle) | ||
| 57 | * Removes the possibility to reset a password for LDAP-based users (thanks to @chaplina) | ||
| 58 | * Removes the password-change-Email from 4.3 on (thanks to @litinoveweedle) | ||
| 59 | * Fixes double authentication-attempt (that resulted in failed authentication) (thanks to @litinoveweedle) | ||
| 60 | |||
| 61 | = 1.4.10 = | ||
| 62 | * Cleanup by removing deprecated code | ||
| 63 | * Fixes issues with undefined variables | ||
| 64 | * Enables internal option-versioning | ||
| 65 | * Setting users nickname initially to the realname instead of the uid | ||
| 66 | * Fixes display of password-change possibility in users profile-page | ||
| 67 | = 1.4.9 = | ||
| 68 | * Fixed an issue with changing display name on every login | ||
| 69 | * Use proper way of looking up user-roles in setups w/o DB-prefix | ||
| 70 | = 1.4.8 = | ||
| 71 | * Updated version string | ||
| 72 | = 1.4.7 = | ||
| 73 | * Use default user to retrieve group menberships and not logging in user. | ||
| 74 | * return the UID from the LDAP instead of the value given by the user | ||
| 75 | * remove unnecessary checkbox | ||
| 76 | * Adds a testsuite | ||
| 77 | * Fixes PSR2 violations | ||
| 78 | |||
| 79 | […] | ||
| 80 | |||
| 81 | = 1.2.1 = | ||
| 82 | * Fixed an issue with group-ids | ||
| 83 | * Moved the code to GitHub (https://github.com/heiglandreas/authLdap) | ||
| 84 | = 1.1.0 = | ||
| 85 | * Changed the login-process. Now users that are not allowed to login due to | ||
| 86 | missing group-memberships are not created within your blog as was the standard | ||
| 87 | until Version 1.0.3 - Thanks to alex@tayts.com | ||
| 88 | * Changed the default mail-address that is created when no mail-address can be | ||
| 89 | retrieved from the LDAP from me@example.com to $username@example.com so that | ||
| 90 | a new user can be created even though the mail address already exists in your | ||
| 91 | blog - Also thanks to alex@tayts.com | ||
| 92 | * Added support for WordPress-Table-prefixes as the capabilities of a user | ||
| 93 | are interlany stored in a field that is named "$tablePrefix_capabilities" - | ||
| 94 | again thanks to alex@tayts.com and also to sim0n of silicium.mine.nu |
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Copyright (c) Andreas Heigl<andreas@heigl.org> | ||
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 5 | * of this software and associated documentation files (the "Software"), to deal | ||
| 6 | * in the Software without restriction, including without limitation the rights | ||
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 8 | * copies of the Software, and to permit persons to whom the Software is | ||
| 9 | * furnished to do so, subject to the following conditions: | ||
| 10 | * The above copyright notice and this permission notice shall be included in | ||
| 11 | * all copies or substantial portions of the Software. | ||
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 18 | * THE SOFTWARE. | ||
| 19 | * | ||
| 20 | * @author Andreas Heigl<andreas@heigl.org> | ||
| 21 | * @copyright Andreas Heigl | ||
| 22 | * @license http://www.opensource.org/licenses/mit-license.php MIT-License | ||
| 23 | * @since 07.07.2016 | ||
| 24 | * @link http://github.com/heiglandreas/authLDAP | ||
| 25 | */ | ||
| 26 | |||
| 27 | namespace Org_Heigl\AuthLdap; | ||
| 28 | |||
| 29 | class LdapList | ||
| 30 | { | ||
| 31 | /** | ||
| 32 | * @var \LDAP[] | ||
| 33 | */ | ||
| 34 | protected $items = []; | ||
| 35 | |||
| 36 | public function addLdap(LDAP $ldap) | ||
| 37 | { | ||
| 38 | $this->items[] = $ldap; | ||
| 39 | } | ||
| 40 | |||
| 41 | public function authenticate($username, $password, $filter = '(uid=%s)') | ||
| 42 | { | ||
| 43 | foreach ($this->items as $key => $item) { | ||
| 44 | if (! $item->authenticate($username, $password, $filter)) { | ||
| 45 | unset ($this->items[$key]); | ||
| 46 | continue; | ||
| 47 | } | ||
| 48 | return true; | ||
| 49 | } | ||
| 50 | |||
| 51 | return false; | ||
| 52 | } | ||
| 53 | |||
| 54 | public function bind() | ||
| 55 | { | ||
| 56 | $allFailed = true; | ||
| 57 | foreach ($this->items as $key => $item) { | ||
| 58 | try { | ||
| 59 | $item->bind(); | ||
| 60 | } catch (\Exception $e) { | ||
| 61 | unset($this->items[$key]); | ||
| 62 | continue; | ||
| 63 | } | ||
| 64 | $allFailed = false; | ||
| 65 | } | ||
| 66 | |||
| 67 | if ($allFailed) { | ||
| 68 | throw new AuthLDAP_Exception('No bind successfull'); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | public function search($filter, $attributes = array('uid')) | ||
| 73 | { | ||
| 74 | foreach ($this->items as $item) { | ||
| 75 | try { | ||
| 76 | $result = $item->search($filter, $attributes); | ||
| 77 | return $result; | ||
| 78 | } catch (Exception $e) { | ||
| 79 | throw $e; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | throw new \AuthLDAP_Exception('No Results found'); | ||
| 84 | } | ||
| 85 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment