Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

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.

Here is part of my code, feel free to ask :) Thanks in advance!

My Android http call:

@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();
    }

My firewall

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

My Controller

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);
    }
 }

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.

share|improve this question
    
what do your webserver logs say about the http 500 error ? anything inside app/logs/dev.log or app/logs/prod.log ? –  nifr Jul 10 '13 at 10:43
    
sorry, I wrote it wrong I get a 404 error but everything is settle in routing.yml /api/usuario/{id} –  soni Jul 10 '13 at 11:09
    
are you sure you get a 404 ? and not a 403 Forbidden or 401 Unauthorized ? 404 is page not found ... are you sure the pages are accessible and the routes are properly set up? –  nifr Jul 10 '13 at 11:12
    
OMG! This is insane!!! I've cleaned cache and I'm having again the 500 error I had before! –  soni Jul 10 '13 at 11:49
    
now is it a 404 or a 500 or both? check the logs :D –  nifr Jul 10 '13 at 11:50

1 Answer 1

up vote 0 down vote accepted

It happened to be a typo issue in my routing.yml so if its useful for somebody I must say this works properly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.