Skip to content
Snippets Groups Projects
Verified Commit 7634b4ca authored by Damien's avatar Damien
Browse files

FEAT #10887 TIME 1:30 Multi Ldap + suffix + connection

parent 2b6d2053
No related branches found
No related tags found
No related merge requests found
......@@ -65,5 +65,5 @@ INSERT INTO password_rules (label, "value") VALUES ('renewal', 90);
-----
TRUNCATE TABLE configurations;
INSERT INTO configurations (identifier, value) VALUES ('emailServer', '{"type" : "smtp", "host" : "smtp.gmail.com", "port" : 465, "user" : "", "password" : "", "auth" : true, "secure" : "ssl", "from" : "notifications@maarch.org", "charset" : "utf-8"}');
INSERT INTO configurations (identifier, value) VALUES ('ldapServer', '[{"uri" : "10.2.95.60", "prefix" : "MAARCH", "ssl" : false}]');
INSERT INTO configurations (identifier, value) VALUES ('connection', '{"standard" : true, "ldap" : false}');
INSERT INTO configurations (identifier, value) VALUES ('ldapServer', '[{"uri" : "10.2.95.60", "prefix" : "MAARCH", "suffix" : "", "ssl" : false}]');
INSERT INTO configurations (identifier, value) VALUES ('connection', '"standard"');
......@@ -83,13 +83,8 @@ class ConfigurationModel
return 'standard';
}
$connections = json_decode($configuration[0]['value'], true);
foreach ($connections as $key => $connection) {
if ($connection) {
return $key;
}
}
$connection = json_decode($configuration[0]['value']);
return 'standard';
return $connection;
}
}
......@@ -63,23 +63,28 @@ class AuthenticationController
$ldapConfigurations = json_decode($ldapConfigurations['value'], true);
foreach ($ldapConfigurations as $ldapConfiguration) {
$uri = ($ldapConfiguration['ssl'] === true ? "LDAPS://{$ldapConfiguration['uri']}" : $ldapConfiguration['uri']);
$ldap = ldap_connect($uri);
if ($ldap !== false) {
break;
$ldap = @ldap_connect($uri);
if ($ldap === false) {
$error = 'Ldap connect failed';
continue;
}
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_NETWORK_TIMEOUT, 10);
$login = (!empty($ldapConfiguration['prefix']) ? $ldapConfiguration['prefix'] . '\\' . $body['login'] : $body['login']);
$login = (!empty($ldapConfiguration['suffix']) ? $login . $ldapConfiguration['suffix'] : $login);
$authenticated = @ldap_bind($ldap, $login, $body['password']);
if (!$authenticated) {
$error = ldap_error($ldap);
}
}
if (empty($ldap)) {
return $response->withStatus(400)->withJson(['errors' => 'Ldap connection failed']);
if (empty($authenticated) && !empty($error) && $error != 'Invalid credentials') {
return $response->withStatus(400)->withJson(['errors' => $error]);
}
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$login = (!empty($ldapConfiguration['prefix']) ? $ldapConfiguration['prefix'] . '\\' . $body['login'] : $body['login']);
$authenticated = @ldap_bind($ldap, $login, $body['password']);
} else {
$authenticated = AuthenticationModel::authentication(['login' => $body['login'], 'password' => $body['password']]);
}
if (!$authenticated) {
if (empty($authenticated)) {
return $response->withStatus(401)->withJson(['errors' => 'Authentication Failed']);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment