File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
tests/TestCase/Controller/Component Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -103,4 +103,6 @@ applied during the ``Controller.initialize`` event instead::
103103 ]);
104104
105105You can also disable identity checks entirely with the ``requireIdentity ``
106- option.
106+ option or by calling ``disableIdentityCheck `` from the controller's ``beforeFilter() `` method itself::
107+
108+ $this->Authentication->disableIdentityCheck();
Original file line number Diff line number Diff line change @@ -190,6 +190,17 @@ protected function doIdentityCheck(): void
190190 }
191191 }
192192
193+ /**
194+ * Disables the identity check for this controller and as all its actions.
195+ * They then don't require an authentication identity to be present.
196+ *
197+ * @return void
198+ */
199+ public function disableIdentityCheck (): void
200+ {
201+ $ this ->setConfig ('requireIdentity ' , false );
202+ }
203+
193204 /**
194205 * Set the list of actions that don't require an authentication identity to be present.
195206 *
Original file line number Diff line number Diff line change @@ -490,7 +490,7 @@ public function testUnauthenticatedActionsNoActionsFails()
490490 }
491491
492492 /**
493- * test disabling requireidentity via settings
493+ * test disabling requireIdentity via settings
494494 *
495495 * @return void
496496 */
@@ -511,6 +511,27 @@ public function testUnauthenticatedActionsDisabledOptions()
511511 $ this ->assertTrue (true , 'No exception should be raised as require identity is off. ' );
512512 }
513513
514+ /**
515+ * test disabling requireIdentity via convenience method
516+ *
517+ * @return void
518+ */
519+ public function testUnauthenticatedActionsDisabledOptionsCall ()
520+ {
521+ $ request = $ this ->request
522+ ->withParam ('action ' , 'view ' )
523+ ->withAttribute ('authentication ' , $ this ->service );
524+
525+ $ controller = new Controller ($ request );
526+ $ controller ->loadComponent ('Authentication.Authentication ' );
527+ $ controller ->Authentication ->disableIdentityCheck ();
528+
529+ // Mismatched actions would normally cause an error.
530+ $ controller ->Authentication ->allowUnauthenticated (['index ' , 'add ' ]);
531+ $ controller ->startupProcess ();
532+ $ this ->assertTrue (true , 'No exception should be raised as require identity is off. ' );
533+ }
534+
514535 /**
515536 * Test that the identity check can be run from callback for Controller.initialize
516537 *
You can’t perform that action at this time.
0 commit comments