Skip to content
Snippets Groups Projects
Commit 874b04f6 authored by Damien's avatar Damien
Browse files

FEAT #6751 Basic auth for Rest + basic auth for curl calls

parent f7f21c25
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ROOT> <ROOT>
<user>super</user>
<password>maaarch</password>
<call> <call>
<id>sendFile</id> <id>sendFile</id>
<url></url> <url></url>
......
...@@ -22,6 +22,7 @@ class CurlModel ...@@ -22,6 +22,7 @@ class CurlModel
ValidatorModel::notEmpty($aArgs, ['curlCallId']); ValidatorModel::notEmpty($aArgs, ['curlCallId']);
ValidatorModel::stringType($aArgs, ['curlCallId']); ValidatorModel::stringType($aArgs, ['curlCallId']);
ValidatorModel::arrayType($aArgs, ['bodyData']); ValidatorModel::arrayType($aArgs, ['bodyData']);
ValidatorModel::boolType($aArgs, ['noAuth']);
$curlConfig = CurlModel::getConfigByCallId(['curlCallId' => $aArgs['curlCallId']]); $curlConfig = CurlModel::getConfigByCallId(['curlCallId' => $aArgs['curlCallId']]);
if (empty($curlConfig)) { if (empty($curlConfig)) {
...@@ -36,6 +37,9 @@ class CurlModel ...@@ -36,6 +37,9 @@ class CurlModel
], ],
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
]; ];
if (empty($aArgs['noAuth'])) {
$opts[CURLOPT_HTTPHEADER][] = 'Authorization: Basic ' . base64_encode($curlConfig['user']. ':' .$curlConfig['password']);
}
if ($curlConfig['method'] == 'POST' || $curlConfig['method'] == 'PUT') { if ($curlConfig['method'] == 'POST' || $curlConfig['method'] == 'PUT') {
if (!empty($curlConfig['data'])) { if (!empty($curlConfig['data'])) {
...@@ -76,6 +80,9 @@ class CurlModel ...@@ -76,6 +80,9 @@ class CurlModel
$curlConfig = []; $curlConfig = [];
if (file_exists($path)) { if (file_exists($path)) {
$loadedXml = simplexml_load_file($path); $loadedXml = simplexml_load_file($path);
$curlConfig['user'] = (string)$loadedXml->user;
$curlConfig['password'] = (string)$loadedXml->password;
foreach ($loadedXml->call as $call) { foreach ($loadedXml->call as $call) {
if ((string)$call->id == $aArgs['curlCallId']) { if ((string)$call->id == $aArgs['curlCallId']) {
$curlConfig['url'] = (string)$call->url; $curlConfig['url'] = (string)$call->url;
......
...@@ -70,13 +70,26 @@ if (empty($_SESSION['user'])) { ...@@ -70,13 +70,26 @@ if (empty($_SESSION['user'])) {
//login management //login management
if (empty($_SESSION['user'])) { if (empty($_SESSION['user'])) {
require_once('apps/maarch_entreprise/class/class_login.php'); if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
$loginObj = new login(); $_SESSION['error'] = '';
$loginMethods = $loginObj->build_login_method(); $security = new security();
require_once('core/services/Session.php'); $pass = $security->getPasswordHash($_SERVER['PHP_AUTH_PW']);
$oSessionService = new \Core_Session_Service(); $res = $security->login($_SERVER['PHP_AUTH_USER'], $pass);
$_SESSION['user'] = $res['user'];
if (!empty($res['error'])) {
$_SESSION['error'] = $res['error'];
}
} else {
require_once('apps/maarch_entreprise/class/class_login.php');
$loginObj = new login();
$loginMethods = $loginObj->build_login_method();
require_once('core/services/Session.php');
$oSessionService = new \Core_Session_Service();
$loginObj->execute_login_script($loginMethods, true);
}
$loginObj->execute_login_script($loginMethods, true);
} }
if ($_SESSION['error']) { if ($_SESSION['error']) {
...@@ -246,3 +259,15 @@ $app->get('/res/listDocs/{clause}/{select}', \Core\Controllers\ResController::cl ...@@ -246,3 +259,15 @@ $app->get('/res/listDocs/{clause}/{select}', \Core\Controllers\ResController::cl
$app->run(); $app->run();
if ($_SESSION['user']['UserId'] == 'restUser') {
$name = $_SESSION['sessionName'];
setcookie ($name, "", 1);
setcookie ($name, false);
unset($_COOKIE[$name]);
session_unset();
session_destroy();
unset($_SESSION['sessionName']);
}
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