File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 3
3
namespace LdapRecord \Laravel \Middleware ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Support \Arr ;
6
7
use Illuminate \Contracts \Auth \Factory as Auth ;
7
8
use Illuminate \Database \Eloquent \Model as Eloquent ;
8
9
use LdapRecord \Laravel \Auth \DatabaseUserProvider ;
14
15
15
16
class WindowsAuthenticate
16
17
{
18
+ /**
19
+ * The guards to use for SSO authentication.
20
+ *
21
+ * @var null|array
22
+ */
23
+ public static $ guards ;
24
+
17
25
/**
18
26
* The server key to use for fetching user SSO information.
19
27
*
@@ -66,6 +74,16 @@ public function __construct(Auth $auth)
66
74
$ this ->auth = $ auth ;
67
75
}
68
76
77
+ /**
78
+ * Set the guards to use for authentication.
79
+ *
80
+ * @param string|array $guards
81
+ */
82
+ public static function guards ($ guards )
83
+ {
84
+ static ::$ guards = Arr::wrap ($ guards );
85
+ }
86
+
69
87
/**
70
88
* Define the server key to use for fetching user SSO information.
71
89
*
@@ -131,7 +149,7 @@ public static function rememberAuthenticatedUsers()
131
149
*/
132
150
public function handle ($ request , Closure $ next , ...$ guards )
133
151
{
134
- $ this ->authenticate ($ request , $ guards );
152
+ $ this ->authenticate ($ request , static :: $ guards ?? $ guards );
135
153
136
154
return $ next ($ request );
137
155
}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ protected function setUp(): void
23
23
parent ::setUp ();
24
24
25
25
// Reset all middleware options.
26
+ WindowsAuthenticate::$ guards = null ;
26
27
WindowsAuthenticate::$ serverKey = 'AUTH_USER ' ;
27
28
WindowsAuthenticate::$ username = 'samaccountname ' ;
28
29
WindowsAuthenticate::$ domainVerification = true ;
@@ -364,6 +365,20 @@ public function test_users_are_logged_out_if_enabled_and_user_is_not_authenticat
364
365
$ this ->assertFalse (auth ()->check ());
365
366
});
366
367
}
368
+
369
+ public function test_guards_can_be_set_manually ()
370
+ {
371
+ WindowsAuthenticate::guards ('invalid ' );
372
+
373
+ $ middleware = new WindowsAuthenticate (app ('auth ' ));
374
+ $ request = tap (new Request , function ($ request ) {
375
+ $ request ->server ->set ('AUTH_USER ' , 'Local\SteveBauman ' );
376
+ });
377
+
378
+ $ this ->expectException (\InvalidArgumentException::class);
379
+
380
+ $ middleware ->handle ($ request , function () {});
381
+ }
367
382
}
368
383
369
384
class WindowsAuthRuleStub extends Rule
You can’t perform that action at this time.
0 commit comments