File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace App \Models ;
44
5+ use Illuminate \Support \Facades \Log ;
6+ use Illuminate \Support \Str ;
57use Slides \Saml2 \Models \Tenant ;
68
79class Saml2Tenant extends Tenant
810{
911 public static function firstFromDomain (string $ domain )
1012 {
11- return self ::query ()
12- ->where ('domain ' , '= ' , $ domain )
13- ->orWhere ('alt_domain1 ' , '= ' , $ domain )
14- ->first ();
13+ return self ::all ()
14+ ->filter (function (Saml2Tenant $ saml2Tenant ) use ($ domain ) {
15+ $ allowedDomains = [
16+ $ saml2Tenant ->domain ,
17+ $ saml2Tenant ->alt_domain1 ,
18+ ];
19+
20+ foreach ($ allowedDomains as $ allowedDomain ) {
21+ // If SAML Tenant domain starts with ~, it is a regex
22+ if (Str::startsWith ($ allowedDomain , '~ ' )) {
23+ if (1 === preg_match ($ allowedDomain , $ domain )) {
24+ Log::debug ("[SAML2 Authentication] $ domain matches on domain regex $ allowedDomain " );
25+ return true ;
26+ }
27+ } else {
28+ if ($ domain === $ allowedDomain ) {
29+ Log::debug ("[SAML2 Authentication] $ domain is equal to domain $ allowedDomain " );
30+ return true ;
31+ }
32+ }
33+ }
34+
35+ return false ;
36+ })->first ();
1537 }
1638
1739 public function getTenantId ()
You can’t perform that action at this time.
0 commit comments