# When logging into the system and trying to redirect to index action gives me error "The request to / did not apply any authorization checks."

**URL:** <https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128>\
**Category:** Need Help\
**Created:** [March 16, 2021, 2:34pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128 "2021-03-16T14:34:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 16, 2021, 2:34pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/1 "2021-03-16T14:34:46Z")

</div>

I am looking at Authorization’s documentation and in step 2 talks about Policies, but for some reason I don’t have src/Policy folder, where should I save a Policy class so that Authorization works?

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 16, 2021, 6:25pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/2 "2021-03-16T18:25:05Z")

</div>

I created the policies with bin/cake bake policy but it still gives me the same error.  
How can I fill each method of the policy class, I am returning this:

```auto
return !empty($user->getIdentifier());

```

Is that ok to make it work the policies?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 16, 2021, 8:42pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/3 "2021-03-16T20:42:08Z")

</div>

Just having a policy is not enough. You need to tell it to actually use the policy in your controller. [This](https://book.cakephp.org/authorization/2/en/component.html#automatic-authorization-checks) and [this](https://book.cakephp.org/authorization/2/en/component.html#checking-authorization) are two ways to do so.

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 17, 2021, 12:58am UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/4 "2021-03-17T00:58:57Z")

</div>

I did all the steps in the second option but now throws me a ForbiddenException, this is the image:

 ![forbidden](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/3/31a05b319ea0c45c3cb9408b8d1d509bfb28ca37.png)

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 17, 2021, 1:59am UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/5 "2021-03-17T01:59:42Z")

</div>

Seems likely that your policy is returning `false`.

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 17, 2021, 4:20pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/6 "2021-03-17T16:20:57Z")

</div>

Then how can I implement the methods of policies so that it doesn’t throw me the ForbiddenException?

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 17, 2021, 4:42pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/7 "2021-03-17T16:42:30Z")

</div>

It doesn’t even let me to login, when login action is allowed with no authentication and skip authorization.  
Why is that happening?

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 17, 2021, 6:24pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/8 "2021-03-17T18:24:03Z")

</div>

I figured it out, I have a class named RequestPolicy that has this code:

```auto
<?php
namespace App\Policy;

use Authorization\Policy\RequestPolicyInterface;
use Cake\Http\ServerRequest;

class RequestPolicy implements RequestPolicyInterface
{
    /**
     * Method to check if the request can be accessed
     *
     * @param \Authorization\IdentityInterface|null $identity Identity
     * @param \Cake\Http\ServerRequest $request Server Request
     * @return bool
     */
    public function canAccess($identity, ServerRequest $request)
    {
        if ($request->getParam('controller') === 'Users'
            && $request->getParam('action') === 'login'
        ) {
            return true;
        }

        return false;
    }
}
?>

```

Locally in my computer with wampserver it works, but in the web hosting still gives me the ForbiddenException, can you help me with that please? Why in remote isn’t working?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 17, 2021, 10:46pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/9 "2021-03-17T22:46:01Z")

</div>

When things work on Windows but not on Linux, it’s quite often case issues in filenames. Is this file named “requestpolicy.php” instead of “RequestPolicy.php”, for example? Or is the folder called “policy” instead of “Policy”?

---

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 17, 2021, 10:52pm UTC](https://discourse.cakephp.org/t/when-logging-into-the-system-and-trying-to-redirect-to-index-action-gives-me-error-the-request-to-did-not-apply-any-authorization-checks/9128/10 "2021-03-17T22:52:26Z")

</div>

No the names are correct, but don’t matter, it’s working fine now, I created a github repository and clone it in my hosting, but for some reason this didn’t overwrite the files in the public\_html folder, when I copied the files from my computer it functioned fine, now is functioning everything ok, thank you for the help.
