1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Http\Middleware; |
4
|
|
|
|
5
|
|
|
use Slides\Saml2\Repositories\TenantRepository; |
6
|
|
|
use Illuminate\Support\Facades\Log; |
7
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
|
|
|
8
|
|
|
use Slides\Saml2\OneLoginBuilder; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ResolveTenant |
12
|
|
|
* |
13
|
|
|
* @package Slides\Saml2\Http\Middleware |
14
|
|
|
*/ |
15
|
|
|
class ResolveTenant |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var TenantRepository |
19
|
|
|
*/ |
20
|
|
|
protected $tenants; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var OneLoginBuilder |
24
|
|
|
*/ |
25
|
|
|
protected $builder; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* ResolveTenant constructor. |
29
|
|
|
* |
30
|
|
|
* @param TenantRepository $tenants |
31
|
|
|
* @param OneLoginBuilder $builder |
32
|
|
|
*/ |
33
|
|
|
public function __construct(TenantRepository $tenants, OneLoginBuilder $builder) |
34
|
|
|
{ |
35
|
|
|
$this->tenants = $tenants; |
36
|
|
|
$this->builder = $builder; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Handle an incoming request. |
41
|
|
|
* |
42
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
43
|
|
|
* @param \Closure $next |
44
|
|
|
* |
45
|
|
|
* @throws NotFoundHttpException |
46
|
|
|
* |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
|
|
public function handle($request, \Closure $next) |
50
|
|
|
{ |
51
|
|
|
if(!$tenant = $this->resolveTenant($request)) { |
52
|
|
|
throw new NotFoundHttpException(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (config('saml2.debug')) { |
|
|
|
|
56
|
|
|
Log::debug('[Saml2] Tenant resolved', [ |
57
|
|
|
'uuid' => $tenant->uuid, |
58
|
|
|
'id' => $tenant->id, |
59
|
|
|
'key' => $tenant->key |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
session()->flash('saml2.tenant.uuid', $tenant->uuid); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$this->builder |
66
|
|
|
->withTenant($tenant) |
67
|
|
|
->bootstrap(); |
68
|
|
|
|
69
|
|
|
return $next($request); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Resolve a tenant by a request. |
74
|
|
|
* |
75
|
|
|
* @param \Illuminate\Http\Request $request |
76
|
|
|
* |
77
|
|
|
* @return \Slides\Saml2\Models\Tenant|null |
78
|
|
|
*/ |
79
|
|
|
protected function resolveTenant($request) |
80
|
|
|
{ |
81
|
|
|
if(!$uuid = $request->route('uuid')) { |
82
|
|
|
if (config('saml2.debug')) { |
|
|
|
|
83
|
|
|
Log::debug('[Saml2] Tenant UUID is not present in the URL so cannot be resolved', [ |
84
|
|
|
'url' => $request->fullUrl() |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if(!$tenant = $this->tenants->findByUUID($uuid)) { |
92
|
|
|
if (config('saml2.debug')) { |
93
|
|
|
Log::debug('[Saml2] Tenant doesn\'t exist', [ |
94
|
|
|
'uuid' => $uuid |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if($tenant->trashed()) { |
102
|
|
|
if (config('saml2.debug')) { |
103
|
|
|
Log::debug('[Saml2] Tenant #' . $tenant->id. ' resolved but marked as deleted', [ |
104
|
|
|
'id' => $tenant->id, |
105
|
|
|
'uuid' => $uuid, |
106
|
|
|
'deleted_at' => $tenant->deleted_at->toDateTimeString() |
|
|
|
|
107
|
|
|
]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return null; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $tenant; |
114
|
|
|
} |
115
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths