2014-09-22 69 views
2

我正在使用Symfony 2.5我已經設置了一個基本的simple_form,並且我已經確保了/管理路徑,如果我嘗試以/ admin /面板爲例,我總是得到重定向到/ login,我沒有要重定向我想要一個401響應禁用重定向symfony安全

,這裏是我的conf

firewalls: 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 

    main: 
     pattern: ^/ 
     anonymous: true 
     stateless: true 
     provider: my_user_provider 
     simple_form: 
      authenticator: form.authenticator 
      login_path: login 
      check_path: login_check 

access_control: 
    - { path: ^/admin, roles: ROLE_USER } 
    - { path: ^/ , roles: IS_AUTHENTICATED_ANONYMOUSLY } 
+0

添加到login_path返回401代碼路徑 – 2014-09-22 16:15:37

+0

使用請求類和它的setStatusCode(integer $ code,mixed $ text = null) 方法 – 2014-09-22 16:16:30

+0

'防火牆:access_denied_url:'中有一個選項可以提供url或路由名。 – malcolm 2016-08-24 19:30:38

回答

4

我解決了添加entry_point: my_entry_point到我的安全

// declared like service 'my_entry_point' 
class MyEntryPoint implements AuthenticationEntryPointInterface 
{ 

    public function start(Request $request, AuthenticationException $authException = null) 
    { 
     $response = new Response("", Response::HTTP_UNAUTHORIZED); 

     return $response; 
    } 
}