Fórum
Авторизация RS, JSON через http
Skif Swarogich, modificado 9 Anos atrás.
Авторизация RS, JSON через http
New Member Postagens: 8 Data de Entrada: 10/11/13 Postagens Recentes
Добрый день.
Пытаюсь авторизироваться на remote service при помщи HttpClient
Вываливается с ошибкой
Подскажите, что-то в 6.2 поменялось в плане авторизации по сравнению с 6.1?
PS: Liferay v6.2 CE Server
Пытаюсь авторизироваться на remote service при помщи HttpClient
httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(tfLogin.getText().toString(), pfPass.getText().toString()));
System.out.println(tfLogin.getText().toString() + " : " +pfPass.getText().toString());
String secureURLpg = "http://localhost:8080/api/jsonws/corrector-portlet.artusers/get-user-exist/user/skif/pass/qwe";
try {
URI uri;
InputStream data = null;
HttpGet httpGet = new HttpGet(secureURLpg);
HttpResponse response;
response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
//Далее код
}
else {
System.out.println(response.getStatusLine());
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Вываливается с ошибкой
skif : qwe
http://localhost:8080/api/jsonws/corrector-portlet.artusers/get-user-exist/user/skif/pass/qwe
PREP-GRPERROR! {"exception":"Authenticated access required"}
Подскажите, что-то в 6.2 поменялось в плане авторизации по сравнению с 6.1?
PS: Liferay v6.2 CE Server
Skif Swarogich, modificado 9 Anos atrás.
RE: Авторизация RS, JSON через http
New Member Postagens: 8 Data de Entrada: 10/11/13 Postagens Recentes
решил. Теперь работает только так:
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("skif@liferay.com", "90455"));
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
String secureURLpg = "http://localhost:8080/api/jsonws/BPLAcorrector-portlet.artusers/get-user-exist/user/skif/pass/qwe";
HttpGet httpGet = new HttpGet(secureURLpg);
HttpResponse resp;
try {
resp = httpclient.execute(targetHost, httpGet, ctx);
resp.getEntity().writeTo(System.out);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println();
httpclient.getConnectionManager().shutdown();