Fórum
Background Thread Use PermissionChecker on liferay services api
Cristhian Camilo Lopez, modificado 12 Anos atrás.
Background Thread Use PermissionChecker on liferay services api
New Member Postagens: 15 Data de Entrada: 11/04/08 Postagens Recentes
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.
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)
Amos Fong, modificado 12 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api (Resposta)
Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
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.
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 12 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api
New Member Postagens: 15 Data de Entrada: 11/04/08 Postagens Recentes
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
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
Amos Fong, modificado 12 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api (Resposta)
Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
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:
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 11 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api
New Member Postagens: 6 Data de Entrada: 14/02/13 Postagens Recentes
Amos Fong, you just saved my life!
Jay Patel, modificado 10 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api
Regular Member Postagens: 118 Data de Entrada: 24/02/10 Postagens Recentes
Thanks Amos, you saved a lot of sweat
Mark Smith, modificado 10 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api
Junior Member Postagens: 54 Data de Entrada: 18/01/14 Postagens Recentes
Thank you very much Amos!!!
Venkat P, modificado 7 Anos atrás.
RE: Background Thread Use PermissionChecker on liferay services api
New Member Postagens: 12 Data de Entrada: 04/09/15 Postagens Recentes
How to do permission checker in webservice soap.