2013-07-10 123 views
0

讓我解釋一下我的情況,我爲Symfony2.1中的Android應用程序開發了一個完整的後端,現在我正在嘗試創建Android應用程序部分,因爲我使用http_basic創建了防火牆身份驗證,確保我的用戶得到正確的身份驗證和授權,我實際上可以使用我的應用程序並進行日誌記錄,但如果我嘗試檢索防火牆後面的任何頁面,則會出現404錯誤。Symfony2防火牆問題Android

我不想使用任何外部包,我只想發送我的用戶/通過每個請求,因爲我的應用程序只有三個httpclient調用,但我不知道霍伊獲得訪問授予每個請求。

這裏是我的代碼的一部分,隨時問:) 在此先感謝!

我的Android HTTP調用:

@Override protected String doInBackground(Void... arg0) { 

     HttpClient httpClient = new DefaultHttpClient(); 

     // construir peticion get 
     HttpGet httpGet = new HttpGet("http://www.somewebsite.com/api/login/"); 

     httpGet.addHeader(BasicScheme.authenticate(
       new UsernamePasswordCredentials(loguser, passw), "UTF-8", 
       false)); 

     try { 
      response = httpClient.execute(httpGet); 

      reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 
      builder = new StringBuilder(); 
      for(String line = null; (line = reader.readLine()) != null;){ 
       builder.append(line).append("\n"); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
      alert("Error de protocolo", "Lo sentimos, ha ocurrido un error"); 
     } 

     return builder.toString(); 
    } 

我的防火牆

api: 
     pattern: ^/api/.* 
     provider: app_user 
     http_basic: 
      realm: "API" 

access_control: 
    - { path: ^/api-registro/, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/api/.*, role: ROLE_API } 
providers: 
    app_user: 
     entity: { class: Alood\BackBundle\Entity\Usuario, property: user } 
encoders: 
    Alood\BackBundle\Entity\Usuario: plaintext 

我的控制器

public function apiLoginAction() 
{ 
    $peticion = $this->getRequest(); 
    $sesion = $peticion->getSession(); 
    $usuario = $this->get('security.context')->getToken()->getUser(); 
    $error = $peticion->attributes->get(SecurityContext::AUTHENTICATION_ERROR, 
    $sesion->get(SecurityContext::AUTHENTICATION_ERROR)); 

    $securityContext = $this->container->get('security.context'); 
    if($securityContext->isGranted('IS_AUTHENTICATED_FULLY')){ 
     $texto["user"] = $usuario->getUser(); 

     return new JsonResponse($texto); 
    } 
} 

注:如果我重複我的控制我的不同的功能相同的步驟在我的android應用程序中遇到問題,我不知道如何解決這個問題。

+0

你的網絡服務器日誌對http 500錯誤有什麼看法? 'app/logs/dev.log'或'app/logs/prod.log'中的任何內容? – nifr

+0

對不起,我寫錯了我得到一個404錯誤,但一切都解決了routing.yml/api/usuario/{id} – soni

+0

你確定你得到404嗎?而不是403 Forbidden或401 Unauthorized? 404沒有找到頁面......你確定這些頁面是可訪問的,並且路由設置正確嗎? OMG! – nifr

回答

0

它恰巧是我的routing.yml中的拼寫錯誤問題,所以如果它對某人有用,我必須說這個工作正常。