2016-03-18 22 views
2

gitmek için reddeder Ben bir ön app Angular ve Symfony2 bir REST API arka ucunda bir proje inşa (2.7, yakında 3.3). Arka taraf tarafı, FOSRestBundle, FOSUSerBundle, LexikAuthBundle ve REST API gereksinimlerine yönelik bir takım diğer harika paketler kullanıyorum. Geçtiğimiz günlerde sosyal sağlayıcılar Google ve Facebook üzerinden giriş yaptık (ön giriş düğmeleri, daha sonra fos_user arka tarafı oluştur ve elle tanınan kullanıcı için elle ayarlanmış, LexikBundle tarafından sağlanan bir JWT). Bu aşağıdaki app\config\security.yml iyi çalışır:Access_Control anonim token'ed kullanıcı

security: 
    encoders: 
     Symfony\Component\Security\Core\User\User: plaintext 
     FOS\UserBundle\Model\UserInterface: sha512 

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

providers: 
    fos_userbundle: 
     id: fos_user.user_provider.username 

firewalls: 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 
    login: 
     pattern: ^/api/login 
     stateless: true 
     anonymous: true 
     form_login: 
      check_path:    /api/login_check 
      login_path:    /api/login 
      require_previous_session: false 
      username_parameter:  username 
      password_parameter:  password 
      success_handler:   lexik_jwt_authentication.handler.authentication_success 
      failure_handler:   lexik_jwt_authentication.handler.authentication_failure 
    api: 
     pattern: ^/api 
     stateless: true 
     anonymous: true 
     lexik_jwt: 
      authorization_header: 
       enabled: true 
       prefix: Bearer 
      query_parameter: 
       enabled: true 
       name: bearer 

always_authenticate_before_granting: true 
    access_control: 
     - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/api/registration., roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/api, roles: [IS_AUTHENTICATED_FULLY, ROLE_API] } 

Bu/API/kayıt :(ulaşmak için (veri vücutta, POST olan)/API/login/sosyal rotalar için ince, ama imkansız çalışır:

anonim belirteç ayarlandığı için
INFO - Matched route "myapp_security_register". 
     Context: {"route_parameters":  {"_controller":"myapp\\CoreBundle\\Controller\\SecurityController::registerAction","_route":"myapp_security_register"},"request_uri":"http://127.0.0.1:8000/api/registration"} 
    INFO - Populated the TokenStorage with an anonymous Token. 
    ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: "You do not have the necessary permissions" at C:\projects\myappAPI\vendor\friendsofsymfony\rest-bundle\FOS\RestBundle\EventListener\AccessDeniedListener.php line 70 
    Context: {"exception":"Object(Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException)"} 

ben bunu anlamıyorum! access_control i ne eksik/api/kayıt erişimini benim denetleyicisi? let doesnt Neden? Ben de sonrası FOSRestBundle yapılandırma o yardımcı olabilir eğer.

Teşekkür , Bor

cevap

1

sizin access_control yönergede bir yazım hatası yok:

- { path: ^/api/registration., roles: ['..'] } 

...

- { path: ^/api/registration, roles: ['..'] } 
+0

Tamam teşekkürler olmalı! Bunu yazdıktan hemen sonra gördüğüm ve kaldırdığım bu yazım hatası vardı. Ama işe yaramadı ... PC'yi yeniden başlattım ve tümleşik php sunucusunu yeniden başlattım ve şimdi beklendiği gibi çalışıyor gibi görünüyor. Security.yml, dev ortamlarda önbelleğe alınır ve açık: önbellek sorunu çözmüş olurdu? – bohr

+0

evet yazım hatası düzeltmenin birleşimi ** ve ** önbelleği temizledikten sonra çözmüş olmalı :) – nifr