掲示板

Having problem in JSON Web Service.. Authentication

thumbnail
9年前 に Arnab Saha によって更新されました。

Having problem in JSON Web Service.. Authentication

New Member 投稿: 10 参加年月日: 15/03/16 最新の投稿
I am using the .java file for Liferay WebService Client call plugin portlet services

Code:
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
HttpClient httpclient = new DefaultHttpClient();
((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials("test@liferay.com", "test"));
AuthCache authCache = new BasicAuthCache();

BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
BasicHttpContext ctx = new BasicHttpContext();
ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);

HttpPost post = new HttpPost("/RemoteWebService-portlet/api/jsonws/employee/get-employee");

List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("emplyeeId", "1"));


UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);

System.out.println("post:"+post);
System.out.println("ctx:"+ctx);
System.out.println("target Host:"+targetHost);
System.out.println("params:"+params);

HttpResponse resp = httpclient.execute(targetHost, post, ctx);
System.out.println("output is "+resp.toString());
System.out.println("response:"+resp.getEntity());
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();
}
}

... Thats working fine in liferay 6.1

But its not working in liferay 6.2 ...
Getting the output: {"exception":"Authenticated access required"}

-Please help.. Is there any default authentication in liferay 6.2..?
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Check the headers on the submitted post to ensure it has the authentication header.
thumbnail
9年前 に Arnab Saha によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

New Member 投稿: 10 参加年月日: 15/03/16 最新の投稿
I had tried adding httpheader:
post.addHeader("Accept", "application/json");
post.addHeader("Content-Type"," application/json");
post.addHeader("Authorization", "Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0");


Still its not working.. emoticon
9年前 に Khushbu Ajmera によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

New Member 投稿: 5 参加年月日: 14/09/19 最新の投稿
I have same problem.
It is working fine with Liferay 6.1
but giving Authentication Error in Liferay 6.2
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
You can try turning on the logging on the server side for the authentication. May be some useful nugget there to help diagnose why authentication is not being received and/or processed.
9年前 に Khushbu Ajmera によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

New Member 投稿: 5 参加年月日: 14/09/19 最新の投稿
Need to modify httpPost value
it is quite different for Liferay 6.2
I have modify url in given formate and it is working fine.
HttpPost post = new HttpPost("/api/jsonws/LiferayJSONWebservices-portlet.employee/get-employee");

you can refer given URL
http://www.liferaysavvy.com/2014/05/consuming-liferay-json-web-services.html
9年前 に Maria Smith によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

New Member 投稿: 2 参加年月日: 15/03/28 最新の投稿
have the same problememoticon
thumbnail
9年前 に Tomas Polesovsky によって更新されました。

RE: Having problem in JSON Web Service.. Authentication

Liferay Master 投稿: 676 参加年月日: 09/02/13 最新の投稿
Hi,

1, Please use /api/jsonws/... URLs, plugins should auto-register to /api/jsonws/...

If you use /yourPluginName/api/jsonws/... you need to configure your plugin and configure authentication filter.

2, For 6.2 you need to use preemtive authentication, the API no longer sends HTTP Authorization challenge.

For HTTP Client please see http://hc.apache.org/httpclient-3.x/authentication.html#Preemptive_Authentication

This is due to security reasons:
A, it's much harder to exploit any possible JSONWS vulnerabilities using browser, because all access must be authenticated and browsers don't support preemptive authentication
B, The JSONWS api can support any number of authentication mechanisms that can be pipelined

Thanks.