【问题标题】:Symfony2 firewall issue AndroidSymfony2防火墙问题Android
【发布时间】:2013-07-08 01:41:53
【问题描述】:

让我解释一下我的情况,我在 Symfony2.1 中为一个运行良好的 Android 应用程序开发了一个完整的后端,现在我正在尝试创建 Android 应用程序部分,为此我创建了一个带有 http_basic 身份验证的防火墙,以确保我的用户经过了正确的身份验证和授权,我实际上可以使用我的应用程序并被登录,但是如果我尝试检索防火墙后面的任何页面,则会出现 404 错误。

我不想使用任何外部捆绑包,我只想发送我的用户/传递每个请求,因为我的应用只进行了三个 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 应用程序会出现问题,我不知道如何解决。

【问题讨论】:

  • 您的网络服务器日志对 http 500 错误有何看法? app/logs/dev.logapp/logs/prod.log 里面有什么?
  • 对不起,我写错了我收到 404 错误,但一切都在 routing.yml /api/usuario/{id}
  • 你确定你得到了 404 吗?而不是 403 Forbidden 或 401 Unauthorized ? 404 is page not found ...您确定页面可以访问并且路由设置正确吗?
  • 天哪!疯了吧!!!我已经清理了缓存,但我又遇到了以前的 500 错误!
  • 现在是 404 还是 500 或两者兼而有之?检查日志:D

标签: android symfony firewall symfony-2.1 androidhttpclient


【解决方案1】:

这恰好是我的 routing.yml 中的一个错字问题,所以如果它对某人有用,我必须说它可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-30
    • 2017-08-23
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    相关资源
    最近更新 更多