Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: [DXP] How to allow guest access to custom service builder method?
I am trying to call a custom service builder remote method via HTTP as a non-authenticated user, but I always get the following error:
"Access denied to com.client-name.speedtest.service.SpeedTestResultService#addSpeedTestResult"
I have tried adding the "@AccessControlled(guestAccessEnabled = true)" header to both the remote impl class and remote impl method, and neither has done anything.
What steps do I need to take to allow for unauthenticated access against my custom service builder entity?
Remote Impl Class:
Local Impl Class:
Calling the service from javascript:
"Access denied to com.client-name.speedtest.service.SpeedTestResultService#addSpeedTestResult"
I have tried adding the "@AccessControlled(guestAccessEnabled = true)" header to both the remote impl class and remote impl method, and neither has done anything.
What steps do I need to take to allow for unauthenticated access against my custom service builder entity?
Remote Impl Class:
@AccessControlled(guestAccessEnabled = true)
public class SpeedTestResultServiceImpl extends SpeedTestResultServiceBaseImpl {
@AccessControlled(guestAccessEnabled = true)
public SpeedTestResult addSpeedTestResult(final double download, final double upload) {
return this.speedTestResultLocalService.addSpeedTestResult(download, upload);
}
}
Local Impl Class:
public class SpeedTestResultLocalServiceImpl extends SpeedTestResultLocalServiceBaseImpl {
public SpeedTestResult addSpeedTestResult(final double download, final double upload) {
final SpeedTestResult result = createSpeedTestResult(CounterLocalServiceUtil.increment(SpeedTestResult.class.getName()));
result.setDate(new Date());
result.setDownloadSpeed(download);
result.setUploadSpeed(upload);
result.persist();
return result;
}
}Calling the service from javascript:
Liferay.Service(
'/speedtest.speedtestresult/add-speed-test-result',
{
download: parseFloat(testResult.download),
upload: parseFloat(testResult.upload)
},
function(obj) {
console.log(obj);
}
);
Zak Thompson
I have tried adding the "@AccessControlled(guestAccessEnabled = true)" header to both the remote impl class and remote impl method, and neither has done anything.
Making sure, did you re-run service builder after adding the annotation? Because the method invocation happens on Spring proxies, it needs to exist on the interface for the annotation lookup in AccessControlAdvice to be able to find it.
Minhchau DangHi Minhchau,Zak Thompson
I have tried adding the "@AccessControlled(guestAccessEnabled = true)" header to both the remote impl class and remote impl method, and neither has done anything.
Making sure, did you re-run service builder after adding the annotation? Because the method invocation happens on Spring proxies, it needs to exist on the interface for the annotation lookup in AccessControlAdvice to be able to find it.
I did re-run the service builder after adding the annotations. I ran it again just to be safe, but it still did not work after rebuilding the services and re-deploying. Here is the definition of the service interface class:
@AccessControlled
@JSONWebService
@OSGiBeanProperties(property = {
"json.web.service.context.name=speedtest", "json.web.service.context.path=SpeedTestResult"}, service = SpeedTestResultService.class)
@ProviderType
@Transactional(isolation = Isolation.PORTAL, rollbackFor = {
PortalException.class, SystemException.class})
public interface SpeedTestResultService extends BaseService {
@AccessControlled(guestAccessEnabled = true)
public SpeedTestResult addSpeedTestResult(double download, double upload);
/**
* Returns the OSGi service identifier.
*
* @return the OSGi service identifier
*/
public String getOSGiServiceIdentifier();
}
Hi , Did you try creating new Service Access Policy on control panel -> Configuration? We can define list of methods to be public from service class.