Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Nov 16, 2020
2 parents ae33595 + 255c440 commit a347daa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.0.2
## 11/16/2020

1. [](#improved)
* Allow to login if LDAP user's DN contains double quotes [#18](https://github.com/trilbymedia/grav-plugin-login-ldap/pulls/18)
* Ignore authentication requests with empty username [#14](https://github.com/trilbymedia/grav-plugin-login-ldap/pulls/14)
* Better handling a null condition with `array_shift` [#8](https://github.com/trilbymedia/grav-plugin-login-ldap/pulls/8)

# v1.0.1
## 06/11/2018

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Login LDAP
version: 1.0.1
version: 1.0.2
description: Allows for Grav user authentication against an LDAP Server such as OpenLDAP or ActiveDirectory
icon: user-circle-o
author:
Expand All @@ -13,7 +13,7 @@ docs: https://github.com/trilbymedia/grav-plugin-login-ldap/blob/develop/README.
license: MIT

dependencies:
- { name: login, version: '>=2.6.3' }
- { name: login, version: '>=3.0.0' }

form:
validation: strict
Expand Down
24 changes: 18 additions & 6 deletions login-ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Grav\Plugin\Login\Events\UserLoginEvent;
use Grav\Plugin\Login\Login;
use Symfony\Component\Ldap\Ldap;
use Symfony\Component\Ldap\LdapInterface;
use Symfony\Component\Ldap\Exception\ConnectionException;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -69,6 +70,12 @@ public function onPluginsInitialized()
public function userLoginAuthenticate(UserLoginEvent $event)
{
$credentials = $event->getCredentials();

// empty username -> ignore
if($credentials['username'] == ''){
$event->setStatus($event::AUTHENTICATION_FAILURE);
return;
}

// Get Proper username
$user_dn = $this->config->get('plugins.login-ldap.user_dn');
Expand Down Expand Up @@ -171,7 +178,7 @@ public function userLoginAuthenticate(UserLoginEvent $event)
if ($group_dn) {
// retrieves all extra groups for user
$group_query = str_replace('[username]', $credentials['username'], $group_query);
$group_query = str_replace('[dn]', $userdata['dn'], $group_query);
$group_query = str_replace('[dn]', $ldap->escape($userdata['dn'], '', LdapInterface::ESCAPE_FILTER), $group_query);
$query = $ldap->query($group_dn, $group_query);
$groups = $query->execute()->toArray();

Expand All @@ -181,11 +188,16 @@ public function userLoginAuthenticate(UserLoginEvent $event)

foreach ($groups as $group) {
$attributes = $group->getAttributes();
$user_group = array_shift($attributes[$group_indentifier]);
$user_groups[] = $user_group;

if ($this->config->get('plugins.login-ldap.store_ldap_data', false)) {
$userdata['ldap']['groups'][] = $user_group;

// make sure we have an array to read
if ( !empty($attributes) && !empty($attributes[$group_indentifier]) && is_array($attributes[$group_indentifier]) )
{
$user_group = array_shift($attributes[$group_indentifier]);
$user_groups[] = $user_group;

if ($this->config->get('plugins.login-ldap.store_ldap_data', false)) {
$userdata['ldap']['groups'][] = $user_group;
}
}
}
}
Expand Down

0 comments on commit a347daa

Please sign in to comment.