Liferay 6.2:允许 public 访问一个 JSON API 方法

Liferay 6.2: Allow public access to one JSON API method

我正在尝试提供 public 访问 URL http://localhost:8080/api/jsonws/journalarticle/get-article-by-url-title/group-id/10182/url-title/events

当我尝试在未登录 Liferay 的情况下访问此 URL 时,出现以下错误:

{"exception":"Authenticated access required"}

我已经尝试在 portal-ext.properties 中设置以下内容:

json.service.public.methods=*
jsonws.web.service.public.methods=*

我也试过将值设置为 get* 但没有成功。我需要通过托管在不同域上的 AngularJs 应用程序访问此 API,因此如果可能,我还需要设置 CORS 访问。

尝试在门户中添加属性-ext.properties

json.web.service.enabled=true
json.service.auth.token.enabled=false
auth.token.check.enabled=false
json.service.auth.token.hosts.allowed=

第四个空着。

这将禁用 JSON 调用 Liferay 所需的身份验证。

即使我已经尝试了以上所有方法都没有用,您可以做的是在您的自定义 portlet 中为调用 API 的 JSON Web 服务创建您自己的 API

JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, urlTitle);

在你的*ServiceImp.java中添加下面的标签,看例子

@AccessControlled(guestAccessEnabled=true)

示例:

@AccessControlled(guestAccessEnabled=true)
public JurnalArtical yourMethodName(){...}