2013-03-08 20 views

回答

10

我與相當多的時間掙扎,太。以下是如何解決這個問題:

app/config文件夾,例如在SecurityBundle添加到app/AppKernel.php

public function registerBundles() 
{ 
    $bundles = array(
     // ... 

     // support for the admin 
     new Symfony\Bundle\SecurityBundle\SecurityBundle(), 
    ); 
    // ... 
} 

創建security.yml本演示內容:

security: 
    encoders: 
     Symfony\Component\Security\Core\User\User: plaintext 

    role_hierarchy: 
     ROLE_ADMIN:  ROLE_USER 
     ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 

    providers: 
     in_memory: 
      memory: 
       users: 
        user: { password: userpass, roles: [ 'ROLE_USER' ] } 
        admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } 
    firewalls: 
     dev: 
      pattern: ^/(_(profiler|wdt)|css|images|js)/ 
      security: false 
     main: 
      pattern: ^/ 
      anonymous: ~ 
      http_basic: 

       realm: "Secured Demo Area" 
    access_control: 
     #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } 
     #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 } 

,並加載它,它的app/config/config.yml

imports: 
    - { resource: security.yml } 

爲我工作。

+0

什麼巫術是這個!像魅力一樣工作 – Dheeraj 2016-01-21 09:51:58