Skip to content

Commit 9a7880c

Browse files
author
Miguel Angel
committed
feat: add saml metadata controller to validate xml
1 parent c279e9e commit 9a7880c

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace ProcessMaker\Exception;
4+
5+
use Exception;
6+
7+
class MetadataFileNotFoundException extends Exception
8+
{
9+
//
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace ProcessMaker\Http\Controllers\Saml;
4+
5+
use CodeGreenCreative\SamlIdp\Http\Controllers\MetadataController as SamlIdpMetadataController;
6+
use ProcessMaker\Exception\MetadataFileNotFoundException;
7+
8+
class MetadataController extends SamlIdpMetadataController
9+
{
10+
public function __construct()
11+
{
12+
$file = $this->getMetadataFilePath();
13+
14+
if ($this->fileExists($file)) {
15+
$this->modifyFileContent($file);
16+
} else {
17+
throw new MetadataFileNotFoundException('Unable to find metadata file');
18+
}
19+
}
20+
21+
private function getMetadataFilePath()
22+
{
23+
$basePath = base_path();
24+
$directory = $basePath . '/vendor/codegreencreative/laravel-samlidp/resources/views';
25+
return $directory . '/metadata.blade.php';
26+
}
27+
28+
private function fileExists($file)
29+
{
30+
$directory = dirname($file);
31+
return is_dir($directory) && file_exists($file);
32+
}
33+
34+
private function modifyFileContent($file)
35+
{
36+
$lines = file($file);
37+
38+
// check if the first line is the xml tag
39+
if (strpos($lines[0], '<?xml') === 0) {
40+
// remove break lines and add the php tag
41+
$lines[0] = str_replace(PHP_EOL, '', $lines[0]);
42+
$lines[0] = "@php echo '" . $lines[0] . "' @endphp" . PHP_EOL;
43+
44+
// save the contents
45+
file_put_contents($file, $lines);
46+
}
47+
}
48+
}

‎routes/web.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ProcessMaker\Http\Controllers\ProcessesCatalogueController;
3131
use ProcessMaker\Http\Controllers\ProfileController;
3232
use ProcessMaker\Http\Controllers\RequestController;
33+
use ProcessMaker\Http\Controllers\Saml\MetadataController;
3334
use ProcessMaker\Http\Controllers\TaskController;
3435
use ProcessMaker\Http\Controllers\TemplateController;
3536
use ProcessMaker\Http\Controllers\TestStatusController;
@@ -178,3 +179,6 @@
178179
})->name('password-success');
179180

180181
Route::get('/unavailable', [UnavailableController::class, 'show'])->name('error.unavailable');
182+
183+
// SAML Metadata Route
184+
Route::resource('/saml/metadata', MetadataController::class)->only('index');

0 commit comments

Comments
 (0)