Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dustin Dertinger
Liferay 7 Service Access Policies
July 11, 2017 8:54 AM
Answer

Dustin Dertinger

Rank: New Member

Posts: 1

Join Date: July 11, 2017

Recent Posts

I am writing an Application Display Template in Liferay 7 to create an infinite loading feature on an Asset Publisher Portlet, and I want a particular service's get calls to be exposed to guests. I am using the Liferay Javascript object to get a pAuth token using Liferay.authToken to pass with the request, and I have included 'com.liferay.portlet.blogs.service.impl.BlogsEntryServiceImpl' as a service signature in my default Service Access Policy based on the documentation at https://dev.liferay.com/discover/deployment/-/knowledge_base/7-0/service-access-policies. I have also attempted included that package with #get* at the end to be specific to what I want. I'm trying to call '/blogsentry/get-group-entries', and I got the package name to include in my Service Access Policy from the /api/jsonws page. I've tried to invoke this call through JavaScript and URL, and am only able to get a response when I am signed in. If I am not signed in, I get:

{"exception":"Authenticated access required","throwable":"java.lang.SecurityException: Authenticated access required","error":{"message":"Authenticated access required","type":"java.lang.SecurityException"}}

I can see the pAuth getting correctly appended to my request:

cmd:{"/blogsentry/get-group-entries":{"p_auth":"MljBI2cj","groupId":10282,"status":0,"start":6,"end":12}}
p_auth:MljBI2cj

Based on the service access policy docs I thought that adding an allowed service signature under control panel/configuration/service access policy would allow guest access, since I am including a pAuth token with my request - but I can't get this to work. After not getting these to work, I created my own service builder remote services and saw them successfully come through on the /api/jsonws page, but similarly, I have only been able to access these services while signed in (I also included this package in my service access policy as I did with the blogsEntry request).

Is there something that I am missing or doing wrong? In Liferay 7, how can I exposed json web services to guest calls so I can use web services in my UI?
Tomas Polesovsky
RE: Liferay 7 Service Access Policies
July 28, 2017 2:40 PM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 653

Join Date: February 13, 2009

Recent Posts

Hi Dustin,

please don't use impl class name but the service name, i.e.
1com.liferay.blogs.service.BlogsEntryService


Also please note the "default" word in "default Service Access Policy" is a keyword. That means you must tick/check the "Default" field of SAP to be enabled.

Hope it helps.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!