Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The logic of checking 'PUBLIC' and 'EXCEPT' is right? #30

Open
aisuhua opened this issue Oct 21, 2015 · 2 comments
Open

The logic of checking 'PUBLIC' and 'EXCEPT' is right? #30

aisuhua opened this issue Oct 21, 2015 · 2 comments

Comments

@aisuhua
Copy link

aisuhua commented Oct 21, 2015

I check the code of "Phalcon\UserPlugin\Plugin\Security.php". And I find the logic code of checking authority is not right. Below are code fragments:

/**
 * Check for public resources.
 *
 * @param array  $resources
 * @param string $actionName
 * @param string $controllerName
 *
 * @return bool
 */
private function checkPublicResources($resources, $actionName, $controllerName)
{
    $resources = isset($resources['*']) ? $resources['*'] : $resources;
    foreach ($resources as $controller => $actions) {
        if ($controller == $controllerName) {
            if (isset($controller['*'])) {
                return true;
            } else {
                if (in_array($actionName, $actions) || $actions[0] == '*') {
                    return true;
                }
            }
        }
    }
    return false;
}

Above logic code can not reach the goal which the doc say:

In the exampe bellow, the ONLY PUBLIC resurces are the actions LOGIN and REGISTER from the USER controller:

'pup' => array(
    'redirect' => array(
        'success' => 'user/profile',
        'failure' => 'user/login'
    ),
    'resources' => array(
        'type' => 'public',
        'resources' => array(
            'user' => array('login', 'register')
        )
    )
)

Think ! So sorry my bad english.

@calinrada
Copy link
Owner

It is working because the "$resources" param assigned to checkPublicResources() method, it is $var['pup']['resources']['resources']

@aisuhua
Copy link
Author

aisuhua commented Oct 21, 2015

Yes, I know. But the checkPublicResources() return true is meaning "private resource". For example, if i visit the url http://domain/user/login, and the config is:

'pup' => array(
    'redirect' => array(
        'success' => 'user/profile',
        'failure' => 'user/forbidden'
    ),
    'resources' => array(
        'type' => 'public',
        'resources' => array(
            'user' => array('login', 'register')
        )
    )
)

Now, as the doc says, the action login is public. But it redirect to user/forbidden. Is it right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants