Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 firewall issue Android
    primarykey
    data
    text
    <p>Let me explain my situation, I developed a complete backend for an Android application in Symfony2.1 that works perfectly, now I'm trying to create the Android app part, for that I created a firewall with http_basic authentication that ensures that my users are correctly authenticated and authorized, I actually can use my app and be logged, but if I try to retrieve any page behind the firewall a get a 404 error.</p> <p>I don't want to use any external bundle, I just want to send my user/pass on every request since my app makes just three httpclient calls but I don't know hoy to get access granted on every request.</p> <p>Here is part of my code, feel free to ask :) Thanks in advance!</p> <p>My Android http call:</p> <pre><code>@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(); } </code></pre> <p>My firewall</p> <pre><code>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 </code></pre> <p>My Controller</p> <pre><code>public function apiLoginAction() { $peticion = $this-&gt;getRequest(); $sesion = $peticion-&gt;getSession(); $usuario = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser(); $error = $peticion-&gt;attributes-&gt;get(SecurityContext::AUTHENTICATION_ERROR, $sesion-&gt;get(SecurityContext::AUTHENTICATION_ERROR)); $securityContext = $this-&gt;container-&gt;get('security.context'); if( $securityContext-&gt;isGranted('IS_AUTHENTICATED_FULLY')){ $texto["user"] = $usuario-&gt;getUser(); return new JsonResponse($texto); } } </code></pre> <p>Note: If I repeat the same steps in a different function of my controller I get a problem in my android app and I don't know how to solve this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload