login - Symfony 2.5 and FOSRestBundle: How to log in user -


Text after "div class =" itemprop = "text">

I want to log in for a user using FOSRestBundle as the program (I am not using FOSUserBundle) . It seems to work, but when I successfully entered and attempt to reach a safe end point, Symfony throws a AccessDeniedException

This is my security.yml.

 Security Providers: Main unit: Class: Departure Monitor \ Restbndl \ unit \ user property: Email Bhumika_adikrit: ROLE_EDITOR: [ROLE_USER] ROLE_VU_ADMIN: [ROLE_EDITOR, ROLE_USER] ROLE_ADMIN: [ROLE_VU_ADMIN] encoder: which one looks \ RestBundle \ unit \ user: algorithm: bcrypt cost: 13 firewalls: Dev: Pattern: ^ / / (_ (profiler | WDT) | css | images | js) Security: false rest pattern: ^ / API Provider: Main Anonymous: True form_login: Login_path: login check_path: login_check Law Out: ~ access_control: - {path: ^ / api / users / login, roles: IS_AUTHENTICATED_ANONYMOUSLY} - {path: ^ / API / users / passwords, roles: IS_AUTHENTICATED_ANONYMOUSLY} - {path: ^ / API, roles: ROLE_USER} < / Code> 

In my UsersController I have the following action:

  / ** * @Post ("/ users / login") * / public function loginAction (request $ Request) {$ them = $ this-> GetDoctrine () - & gt; GetManager (); User $ = $ em- & gt; GetRepository ('DepartureMonitorRestBundle: User') - & gt; FindOneBy (array ('email' = & gt; $ request & gt; request & gt; find ('username'))); If ($ user user example) {$ factory = $ this- & gt; Obtain ('security.encoder_factory'); $ Encoder = $ factory- & gt; Get encoder ($ user); $ Pw = $ encoder- & gt; Encoded password (get $ request- & gt; Request- & gt; ('password'), $ user-> getSalt ()); If ($ pw === $ user- & gt; receiptsword ()) {$ token = new username nickname ($ user, $ pw, "main", $ user-> getRoles ()); $ This- & gt; Get ('security.context') - & gt; SetToken ($ Tokens); $ Event = new \ Symfony \ Component \ Security \ hpp \ Event \ Interactive Login Event ($ request, $ token); $ This- & gt; Obtain ('event_dispatcher') - & gt; Remittance ('security.interactive_login', $ event); If ($ ($ $ - this-> GetUser) (see example $) -> (return to $ (- 'code' = & gt; HttpStatusCode :: NOT_FOUND, 'message' = & gt; $ this- & gt; ( 'Translate') - & gt; trans ( 'error.messages.bad_credentials')), Actiteepitats code :: NOT_FOUND;} $ view = $ it- & gt; View ($ user, Actiteepitats code :: $ View-> setSerializationContext (SerializationContext :: create () - & gt; setGroups (array ('login')); $ this-> Handle view ($ view);} Return; } Return $ this- & gt; View (array ('code' = & gt; HTTPITS code: NOT_FOUND, 'message' = & gt; $ this- & gt; Get (' Translator ') -> Trance (' error.messages Bad_credentials')), HTTP status code: NOT_FOUND;}  

I do not know what's the problem here. Any help much appreciated


Comments