Foros de discusión

Background Thread Use PermissionChecker on liferay services api

Cristhian Camilo Lopez, modificado hace 12 años.

Background Thread Use PermissionChecker on liferay services api

New Member Mensajes: 15 Fecha de incorporación: 11/04/08 Mensajes recientes
Hello Guys,

I'm developing a portlet to check the consistence between the DL metadata on the database and the data stored on the data store hook.
I need to use de DLFileEntryServiceUtil to delete the invalid entries. Due the long time it could take, I launch the process on other thread on server, but I'm getting a exception because the PermissionChecker isn't set, after some debug I find that it's because it's on other thread.

Which is the best practice to launch background threads and use liferay api ???. Thanks in advance.


2012-01-05 16:55:42,693 INFO  [net.cristhiank.liferay.checker.LibraryChecker] (LiferayChecker/documents) Checking 1385 entries
2012-01-05 16:56:53,761 ERROR [net.cristhiank.liferay.checker.LibraryChecker] (LiferayChecker/documents) class javax.jcr.version.VersionException
2012-01-05 16:56:53,761 WARN  [net.cristhiank.liferay.checker.LibraryChecker] (LiferayChecker/documents) Entry Version 1.1 not found on com.liferay.documentlibrary.util.JCRHook store: enrociclina.jpg
2012-01-05 16:56:53,764 ERROR [net.cristhiank.liferay.checker.portlet.LiferayCheckerPortlet] (LiferayChecker/documents) 
com.liferay.portal.security.auth.PrincipalException: PermissionChecker not initialized
	at com.liferay.portal.service.base.PrincipalBean.getPermissionChecker(PrincipalBean.java:81)
	at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryServiceImpl.deleteFileEntry(DLFileEntryServiceImpl.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
	at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy482.deleteFileEntry(Unknown Source)
	at com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil.deleteFileEntry(DLFileEntryServiceUtil.java:73)
	at net.cristhiank.liferay.checker.LibraryChecker.checkDocumentLibrary(LibraryChecker.java:73)
	at net.cristhiank.liferay.checker.portlet.LiferayCheckerPortlet$2.run(LiferayCheckerPortlet.java:46)
	at java.lang.Thread.run(Thread.java:662)
thumbnail
Amos Fong, modificado hace 12 años.

RE: Background Thread Use PermissionChecker on liferay services api (Respuesta)

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Hi Cristhian,

You probably don't even need a permission check at this point because you probably don't have a specific user performing the action; it seems like backend background stuff. So you can use the DLFileEntryLocalServiceUtil instead which does not do any permission checking.
Cristhian Camilo Lopez, modificado hace 12 años.

RE: Background Thread Use PermissionChecker on liferay services api

New Member Mensajes: 15 Fecha de incorporación: 11/04/08 Mensajes recientes
Hi Amos,

Thank you so much for the answer, you're right, and it's now working like a charm.
Just to know, how could I start background process if in the future I would like use some ThreadLocal objects from Liferay ?

Regards,

Cristhian
thumbnail
Amos Fong, modificado hace 12 años.

RE: Background Thread Use PermissionChecker on liferay services api (Respuesta)

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
I found this code in LayoutsRemotePublisherMessageListener.java which is background process that needs permission checking.

This looks like the code needed to initialize the permissionChecker:

		PrincipalThreadLocal.setName(userId);

		User user = UserLocalServiceUtil.getUserById(userId);

		PermissionChecker permissionChecker =
			PermissionCheckerFactoryUtil.create(user, false);

		PermissionThreadLocal.setPermissionChecker(permissionChecker);
Ricardo Piccoli, modificado hace 11 años.

RE: Background Thread Use PermissionChecker on liferay services api

New Member Mensajes: 6 Fecha de incorporación: 14/02/13 Mensajes recientes
Amos Fong, you just saved my life! emoticon
thumbnail
Jay Patel, modificado hace 10 años.

RE: Background Thread Use PermissionChecker on liferay services api

Regular Member Mensajes: 118 Fecha de incorporación: 24/02/10 Mensajes recientes
Thanks Amos, you saved a lot of sweat emoticon
Mark Smith, modificado hace 10 años.

RE: Background Thread Use PermissionChecker on liferay services api

Junior Member Mensajes: 54 Fecha de incorporación: 18/01/14 Mensajes recientes
Thank you very much Amos!!! emoticon
Venkat P, modificado hace 7 años.

RE: Background Thread Use PermissionChecker on liferay services api

New Member Mensajes: 12 Fecha de incorporación: 4/09/15 Mensajes recientes
How to do permission checker in webservice soap.