Search code examples
liferayliferay-6

Liferay 6.2: Allow public access to one JSON API method


I'm trying to provide public access to the URL http://localhost:8080/api/jsonws/journalarticle/get-article-by-url-title/group-id/10182/url-title/events

When I try accessing this URL without being logged in to Liferay, I get the following error:

{"exception":"Authenticated access required"}

I've tried setting the following in portal-ext.properties:

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

I've also tried setting the values to get* with no luck. I need to access this API through an AngularJs application that is hosted on a different domain, so I also need to set up CORS access if possible.


Solution

  • Even I have tried all the above non have worked, What you can do is in your custom portlet create your own API for JSON web services in that call the API

    JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, urlTitle);
    

    In your *ServiceImp.java add the tag below, see the example

    @AccessControlled(guestAccessEnabled=true)

    Example:

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