8000 Custom Expression Language function not working in @Security annotation · Issue #21305 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Custom Expression Language function not working in @Security annotation #21305

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

Closed
mrsuh opened this issue Jan 16, 2017 · 2 comments
Closed

Custom Expression Language function not working in @Security annotation #21305

mrsuh opened this issue Jan 16, 2017 · 2 comments

Comments

@mrsuh
Copy link
Contributor
mrsuh commented Jan 16, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.1.9

AppBundle\ExpressionLanguage\ExpressionLanguageProvider;

<?php

namespace AppBundle\ExpressionLanguage;

use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
{
    public function getFunctions()
    {
        return array(
            new ExpressionFunction('test', function ($input) {
                return $input;
            }, function (array $values, $input) {
                return $input;
            }),
        );
    }
}

services.yml

    app.security_expression_language_provider:
        class: AppBundle\ExpressionLanguage\ExpressionLanguageProvider
        tags:
            - { name: security.expression_language_provider }

AppBundle\Controller\MyController;

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Response;

class MyController extends Controller
{
    /**
    * @Security("test()")
    */
    public function listAction(Request $request)
    {
       return new Response();
    }
}

Error: The function "test" does not exist around position 1.

@javiereguiluz javiereguiluz changed the title [Bug] Extra Language Expression not working in Security Annotation Custom Expression Language function not working in @Security annotation Jan 16, 2017
@dmaicher
8000 Copy link
Contributor

The problem is actually within the SensioFrameWorkExtraBundle which does not register custom expression language providers.

I proposed a fix here: https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/452/files#diff-c27855d16cebd806adb50a74554fa567R18

For now you could just add the compiler pass within your App to register your new functions.

@jakzal
Copy link
Contributor
jakzal commented Feb 8, 2017

Closing here, as the actual work needs to be done in the SensioFrameworkExtraBundle.

@jakzal jakzal closed this as completed Feb 8, 2017
fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this issue May 11, 2017
…cher)

This PR was merged into the 3.0 branch.

Discussion
----------

Register tagged security expression language providers

Custom security expression language providers are currently not registered which leads to issue symfony/symfony#21305.

Commits
-------

f8c19d7 Register tagged security expression language providers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0