Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
implement LDAP addRealm
Browse files Browse the repository at this point in the history
  • Loading branch information
François Kooman committed Mar 30, 2020
1 parent 6aa1708 commit cca468c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 2.2.4 (...)
- introduce `userIdAttribute` for `FormLdapAuthentication` to "normalize" the
user ID used inside the VPN service (issue #151)
- implement `addRealm` option for `FormLdapAuthentication` that adds a provided
domain to the user specified "authUser" if no domain is specified yet

## 2.2.3 (2020-03-23)
- add German portal translation
Expand Down
6 changes: 6 additions & 0 deletions CONFIG_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ will be used as the user ID. For example:
If not provided, the exact user ID used for binding to the LDAP server will be
used as the user ID in the VPN service.

You can also specify the `addRealm` option that takes a `string` value that
will add a "realm" to the users specified "authUser". For example, if the user
provides `foo`, an `addRealm` with value `example.org` would convert the
"authUser" to `[email protected]`. If the user specifies `[email protected]` and the
`addRealm` value is `example.org` nothing will be changed.

## 2.2.3

We added the translation for German (Germany). You can add it to
Expand Down
1 change: 1 addition & 0 deletions src/FormLdapAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(Config $config, SessionInterface $session, TplInterf
$config->optionalItem('baseDn'),
$config->optionalItem('userFilterTemplate'),
$config->optionalItem('userIdAttribute'),
$config->optionalItem('addRealm'),
$config->optionalItem('permissionAttribute')
);

Expand Down
14 changes: 13 additions & 1 deletion src/LdapAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class LdapAuth implements CredentialValidatorInterface
/** @var string|null */
private $userIdAttribute;

/** @var string|null */
private $addRealm;

/** @var string|null */
private $permissionAttribute;

Expand All @@ -42,16 +45,18 @@ class LdapAuth implements CredentialValidatorInterface
* @param string|null $baseDn
* @param string|null $userFilterTemplate
* @param string|null $userIdAttribute
* @param string|null $addRealm
* @param string|null $permissionAttribute
*/
public function __construct(LoggerInterface $logger, LdapClient $ldapClient, $bindDnTemplate, $baseDn, $userFilterTemplate, $userIdAttribute, $permissionAttribute)
public function __construct(LoggerInterface $logger, LdapClient $ldapClient, $bindDnTemplate, $baseDn, $userFilterTemplate, $userIdAttribute, $addRealm, $permissionAttribute)
{
$this->logger = $logger;
$this->ldapClient = $ldapClient;
$this->bindDnTemplate = $bindDnTemplate;
$this->baseDn = $baseDn;
$this->userFilterTemplate = $userFilterTemplate;
$this->userIdAttribute = $userIdAttribute;
$this->addRealm = $addRealm;
$this->permissionAttribute = $permissionAttribute;
}

Expand All @@ -63,6 +68,13 @@ public function __construct(LoggerInterface $logger, LdapClient $ldapClient, $bi
*/
public function isValid($authUser, $authPass)
{
// add "realm" after user name if none is specified
if (null !== $addRealm = $this->addRealm) {
if (false === strpos($authUser, '@')) {
$authUser .= '@'.$addRealm;
}
}

$bindDn = str_replace('{{UID}}', LdapClient::escapeDn($authUser), $this->bindDnTemplate);
try {
$this->ldapClient->bind($bindDn, $authPass);
Expand Down

0 comments on commit cca468c

Please sign in to comment.