我想通过注释(SF 2.3.7)
保护我的应用(JMS\SecurityExtraBundle\JMSSecurityExtraBundle)
。但它不起作用。我可以在离线时访问addAction
。
我的app / config / security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
remember_me:
key: %secret%
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
我的作曲家
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"jms/security-extra-bundle": "dev-master",
"stof/doctrine-extensions-bundle": "dev-master",
"friendsofsymfony/user-bundle": "~2.0@dev"
}
我的AppKernel
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Intranet\UserBundle\IntranetUserBundle(),
new Intranet\IntranetBundle\IntranetIntranetBundle(),
);
我的控制器
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Intranet\IntranetBundle\Entity\Client;
class ClientController extends Controller
{
/**
* @Secure(roles="IS_AUTHENTICATED_FULLY")
*/
public function addAction()
{
// stuff
}
使用JMS \ Security:
use JMS\SecurityExtraBundle\Annotation\Secure;
那没关系?我错过了什么步骤?
答案 0 :(得分:7)
我发现你没有JMSDiExtraBundle
。
Dan, here ,解释了他的错误/解决方案,这似乎与你的非常相似。
答案 1 :(得分:1)
这只是一个疯狂的猜测,但由于注释被缓存,您是否尝试过清除缓存?这在开发环境中也可能是必要的。
app/console cache:clear --env=prod
我唯一能想到的是一些注释问题。您是否尝试在动作上使用@Route注释?