Skip to content
Snippets Groups Projects
Commit e932be53 authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FEAT #17590 TIME 0:50 back: azure saml connection

parent 79b4dcc6
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ use SrcCore\models\AuthenticationModel; ...@@ -24,7 +24,7 @@ use SrcCore\models\AuthenticationModel;
class ConfigurationController class ConfigurationController
{ {
public const CONNECTION_MODES = ['default', 'ldap', 'kerberos', 'x509']; public const CONNECTION_MODES = ['default', 'ldap', 'kerberos', 'x509', 'azure_saml'];
public function get(Request $request, Response $response) public function get(Request $request, Response $response)
{ {
...@@ -49,10 +49,11 @@ class ConfigurationController ...@@ -49,10 +49,11 @@ class ConfigurationController
$configurations = $configurations[0]; $configurations = $configurations[0];
$configurations['value'] = json_decode($configurations['value']); $configurations['value'] = json_decode($configurations['value']);
$configurations['availableConnections'] = [ $configurations['availableConnections'] = [
['id' => 'default', 'allowed' => true], ['id' => 'default', 'allowed' => true],
['id' => 'kerberos', 'allowed' => true], ['id' => 'kerberos', 'allowed' => true],
['id' => 'x509', 'allowed' => true], ['id' => 'x509', 'allowed' => true],
['id' => 'ldap', 'allowed' => !empty($ldapConfigurations)] ['id' => 'ldap', 'allowed' => !empty($ldapConfigurations)],
['id' => 'azure_saml', 'allowed' => true],
]; ];
} }
......
...@@ -166,6 +166,13 @@ class AuthenticationController ...@@ -166,6 +166,13 @@ class AuthenticationController
return $response->withStatus(401)->withJson(['errors' => 'No identifier detected for kerberos']); return $response->withStatus(401)->withJson(['errors' => 'No identifier detected for kerberos']);
} }
$authenticated = true; $authenticated = true;
} else if ($connection == 'azure_saml') {
$authenticated = AuthenticationController::azureSamlConnection();
if (!empty($authenticated['errors'])) {
return $response->withStatus(401)->withJson(['errors' => $authenticated['errors']]);
}
$login = strtolower($authenticated['login']);
$authenticated = true;
} else { } else {
$authenticated = AuthenticationModel::authentication(['login' => $login, 'password' => $body['password']]); $authenticated = AuthenticationModel::authentication(['login' => $login, 'password' => $body['password']]);
} }
...@@ -222,6 +229,29 @@ class AuthenticationController ...@@ -222,6 +229,29 @@ class AuthenticationController
return $response->withStatus(204); return $response->withStatus(204);
} }
private static function azureSamlConnection()
{
$libDir = CoreConfigModel::getLibrariesDirectory();
if (!is_file($libDir . 'simplesamlphp/lib/_autoload.php')) {
return ['errors' => 'Library simplesamlphp not present'];
}
require_once($libDir . 'simplesamlphp/lib/_autoload.php');
$as = new \SimpleSAML\Auth\Simple('default-sp');
$as->requireAuth([
'ReturnTo' => UrlController::getCoreUrl(),
'skipRedirection' => true
]);
$attributes = $as->getAttributes();
$login = $attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'][0];
if (empty($login)) {
return ['errors' => 'Authentication Failed : login not present in attributes'];
}
return ['login' => $login];
}
public function getRefreshedToken(Request $request, Response $response) public function getRefreshedToken(Request $request, Response $response)
{ {
$queryParams = $request->getQueryParams(); $queryParams = $request->getQueryParams();
......
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