내 상황을 설명하겠습니다. 완벽하게 작동하는 Symfony2.1에서 안드로이드 응용 프로그램을위한 완벽한 백엔드를 개발했습니다. 이제는 http_basic으로 방화벽을 생성하기 위해 Android 앱 부분을 만들려고합니다. 내 사용자가 올바르게 인증되고 권한이 부여되도록하는 인증, 실제로 내 앱을 사용할 수 있고 기록 될 수 있지만 방화벽 뒤 페이지를 검색하려고하면 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);
}
}
참고 : 내 컨트롤러 I의 다른 기능에 동일한 단계를 반복합니다 내 안드로이드 애플 리케이션에 문제가 생기면 어떻게 해결할 지 모르겠다.
웹 서버 로그에서 http 500 오류에 대해 어떻게 말합니까? 'app/logs/dev.log' 또는'app/logs/prod.log' 안에있는 어떤 것입니까? – nifr
미안하지만, 내가 잘못 썼다는 404 오류가 있지만 routing.yml/api/usuario/{id} – soni
에 모든 것이 정착하는 것은 확실합니까? 403 금지되었거나 401 승인되지 않았습니까? 404 페이지를 찾을 수 없습니다 ... 페이지에 액세스 할 수 있고 경로가 올바르게 설정되어 있습니까? – nifr